Base converter
Classes:
Name | Description |
---|---|
BaseConverter |
Abstract base class for all LLM response converters. |
ConverterType |
Enumeration of supported converter types for LLM responses. |
Classes¶
BaseConverter
¶
Bases: ABC
Abstract base class for all LLM response converters.
Subclasses should implement methods to convert standard and streaming LLM responses into PyAgenity's internal message/event formats.
Attributes:
Name | Type | Description |
---|---|---|
state |
AgentState | None
|
Optional agent state for context during conversion. |
Methods:
Name | Description |
---|---|
__init__ |
Initialize the converter. |
convert_response |
Convert a standard agent response to a Message. |
convert_streaming_response |
Convert a streaming agent response to an async generator of EventModel or Message. |
Source code in pyagenity/adapters/llm/base_converter.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
Attributes¶
Functions¶
__init__
¶
__init__(state=None)
Initialize the converter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
AgentState | None
|
Optional agent state for context during conversion. |
None
|
Source code in pyagenity/adapters/llm/base_converter.py
32 33 34 35 36 37 38 39 |
|
convert_response
abstractmethod
async
¶
convert_response(response)
Convert a standard agent response to a Message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Any
|
The raw response from the LLM or agent. |
required |
Returns:
Name | Type | Description |
---|---|---|
Message |
Message
|
The converted message object. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If not implemented in subclass. |
Source code in pyagenity/adapters/llm/base_converter.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
convert_streaming_response
abstractmethod
async
¶
convert_streaming_response(config, node_name, response, meta=None)
Convert a streaming agent response to an async generator of EventModel or Message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
dict
|
Node configuration parameters. |
required |
|
str
|
Name of the node processing the response. |
required |
|
Any
|
The raw streaming response from the LLM or agent. |
required |
|
dict | None
|
Optional metadata for conversion. |
None
|
Yields:
Type | Description |
---|---|
AsyncGenerator[EventModel | Message, None]
|
EventModel | Message: Chunks of the converted streaming response. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If not implemented in subclass. |
Source code in pyagenity/adapters/llm/base_converter.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
ConverterType
¶
Bases: Enum
Enumeration of supported converter types for LLM responses.
Attributes:
Name | Type | Description |
---|---|---|
ANTHROPIC |
|
|
CUSTOM |
|
|
GOOGLE |
|
|
LITELLM |
|
|
OPENAI |
|
Source code in pyagenity/adapters/llm/base_converter.py
11 12 13 14 15 16 17 18 |
|