Types

Type definitions for the Agent library.

All Pydantic models and type definitions are centralized here.

class agent.types.ContentPart(**data)[source]

Bases: BaseModel

A part of message content (text, image, etc.).

Parameters:
  • data (Any)

  • type (Literal['text', 'image', 'image_url'])

  • text (str | None)

  • image_url (str | None)

  • image_data (bytes | None)

  • media_type (str | None)

type: Literal['text', 'image', 'image_url']
text: str | None
image_url: str | None
image_data: bytes | None
media_type: str | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

classmethod text_part(text)[source]

Create a text content part.

Parameters:

text (str)

Return type:

ContentPart

classmethod image_url_part(url)[source]

Create an image URL content part.

Parameters:

url (str)

Return type:

ContentPart

classmethod image_data_part(data, media_type='image/png')[source]

Create an image data content part.

Parameters:
Return type:

ContentPart

class agent.types.Message(**data)[source]

Bases: BaseModel

A normalized message in a conversation.

Parameters:
role: Literal['system', 'user', 'assistant', 'tool']
content: str | list[ContentPart]
name: str | None
tool_call_id: str | None
tool_calls: list[dict[str, Any]] | None
classmethod system(content)[source]

Create a system message.

Parameters:

content (str)

Return type:

Message

classmethod user(content)[source]

Create a user message.

Parameters:

content (str | list[ContentPart])

Return type:

Message

classmethod assistant(content=None, tool_calls=None)[source]

Create an assistant message.

Parameters:
Return type:

Message

classmethod tool(content, tool_call_id, name=None)[source]

Create a tool result message.

Parameters:
Return type:

Message

property text: str

Get the text content of the message.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agent.types.AgentRequest(**data)[source]

Bases: BaseModel

A normalized request to be sent to a provider.

Parameters:
input: str | None
messages: list[Message]
system: str | None
tools: list[Any]
output_schema: dict[str, Any] | None
temperature: float | None
max_tokens: int | None
top_p: float | None
stop: list[str] | None
metadata: dict[str, Any]
session_id: str | None
property schema: dict[str, Any] | None

Alias for output_schema for backwards compatibility.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

to_messages()[source]

Convert request to a list of messages.

Return type:

list[Message]

class agent.types.Usage(**data)[source]

Bases: BaseModel

Token usage information.

Parameters:
  • data (Any)

  • prompt_tokens (int)

  • completion_tokens (int)

  • total_tokens (int)

prompt_tokens: int
completion_tokens: int
total_tokens: int
classmethod from_dict(data)[source]

Create Usage from a dictionary.

Parameters:

data (dict[str, Any])

Return type:

Usage

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agent.types.AgentResponse(**data)[source]

Bases: BaseModel

Normalized response from any provider.

Parameters:
text: str | None
content: list[Any]
output: Any
provider: str
model: str
usage: Usage | None
stop_reason: str | None
tool_calls: list[ToolCall]
raw: Any
latency_ms: float | None
cost_estimate: float | None
request_id: str | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property has_tool_calls: bool

Check if response contains tool calls.

to_dict()[source]

Convert response to a dictionary.

Return type:

dict[str, Any]

class agent.types.ToolSpec(**data)[source]

Bases: BaseModel

Specification for a tool that can be called by an LLM.

Parameters:
name: str
description: str
parameters: dict[str, Any]
function: Any | None
is_async: bool
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

to_openai_schema()[source]

Convert to OpenAI function calling format.

Return type:

dict[str, Any]

to_anthropic_schema()[source]

Convert to Anthropic tool format.

Return type:

dict[str, Any]

to_gemini_schema()[source]

Convert to Gemini function declaration format.

Return type:

dict[str, Any]

class agent.types.ToolCall(**data)[source]

Bases: BaseModel

A tool call requested by the LLM.

Parameters:
id: str
name: str
arguments: dict[str, Any]
to_dict()[source]

Convert to dictionary.

Return type:

dict[str, Any]

classmethod from_dict(data)[source]

Create from dictionary.

Parameters:

data (dict[str, Any])

Return type:

ToolCall

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agent.types.ToolResult(**data)[source]

Bases: BaseModel

Result of executing a tool.

Parameters:
tool_call_id: str
name: str
content: str
is_error: bool
to_dict()[source]

Convert to dictionary.

Return type:

dict[str, Any]

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agent.types.StreamEvent(**data)[source]

Bases: BaseModel

A normalized streaming event.

Parameters:
  • data (Any)

  • type (Literal['text_delta', 'tool_call_start', 'tool_call_delta', 'tool_result', 'message_start', 'message_end', 'usage', 'error'])

  • text (str | None)

  • tool_call (ToolCall | None)

  • tool_call_delta (dict[str, Any] | None)

  • tool_result (str | None)

  • usage (Usage | None)

  • error (str | None)

  • raw (Any)

type: Literal['text_delta', 'tool_call_start', 'tool_call_delta', 'tool_result', 'message_start', 'message_end', 'usage', 'error']
text: str | None
tool_call: ToolCall | None
tool_call_delta: dict[str, Any] | None
tool_result: str | None
usage: Usage | None
error: str | None
raw: Any
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

classmethod text_delta(text, raw=None)[source]

Create a text delta event.

Parameters:
Return type:

StreamEvent

classmethod tool_call_start(tool_call, raw=None)[source]

Create a tool call start event.

Parameters:
Return type:

StreamEvent

classmethod tool_call_delta_event(tool_call_id, delta, raw=None)[source]

Create a tool call delta event.

Parameters:
Return type:

StreamEvent

classmethod tool_result_event(tool_call_id, result, raw=None)[source]

Create a tool result event.

Parameters:
Return type:

StreamEvent

classmethod message_start_event(raw=None)[source]

Create a message start event.

Parameters:

raw (Any)

Return type:

StreamEvent

classmethod message_end(usage=None, raw=None)[source]

Create a message end event.

Parameters:
Return type:

StreamEvent

classmethod usage_event(usage, raw=None)[source]

Create a usage event.

Parameters:
Return type:

StreamEvent

classmethod error_event(error, raw=None)[source]

Create an error event.

Parameters:
Return type:

StreamEvent

class agent.types.AgentConfig(**data)[source]

Bases: BaseModel

Configuration for an Agent instance.

Parameters:
provider: str
model: str
api_key: str | None
base_url: str | None
timeout: float
max_retries: int
temperature: float | None
max_tokens: int | None
top_p: float | None
default_system: str | None
extra: dict[str, Any]
resolve_config()[source]

Resolve model alias and get API key/base URL from environment.

Return type:

AgentConfig

with_overrides(**kwargs)[source]

Create a new config with overrides.

Parameters:

kwargs (Any)

Return type:

AgentConfig

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agent.types.ProviderCapabilities(**data)[source]

Bases: BaseModel

Declares what features a provider supports.

Parameters:
  • data (Any)

  • streaming (bool)

  • tools (bool)

  • structured_output (bool)

  • json_mode (bool)

  • vision (bool)

  • system_messages (bool)

  • batch (bool)

  • native_schema_output (bool)

  • max_context_tokens (int | None)

  • max_output_tokens (int | None)

streaming: bool
tools: bool
structured_output: bool
json_mode: bool
vision: bool
system_messages: bool
batch: bool
native_schema_output: bool
max_context_tokens: int | None
max_output_tokens: int | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agent.types.RetryConfig(**data)[source]

Bases: BaseModel

Configuration for retry behavior.

Parameters:
max_retries: int
initial_delay: float
max_delay: float
exponential_base: float
jitter: bool
retryable_errors: tuple[type[Exception], ...]
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

should_retry(error, attempt)[source]

Check if we should retry for this error.

Parameters:
Return type:

bool

get_delay(attempt, error=None)[source]

Calculate delay before next retry.

Parameters:
Return type:

float

class agent.types.ToolLoopConfig(**data)[source]

Bases: BaseModel

Configuration for tool loop behavior.

Parameters:
  • data (Any)

  • max_iterations (int)

  • max_tool_calls_per_iteration (int)

  • timeout_per_tool (float)

  • parallel_tool_execution (bool)

  • stop_on_error (bool)

max_iterations: int
max_tool_calls_per_iteration: int
timeout_per_tool: float
parallel_tool_execution: bool
stop_on_error: bool
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agent.types.RoutingStrategy(*values)[source]

Bases: str, Enum

Available routing strategies.

FALLBACK = 'fallback'
ROUND_ROBIN = 'round_robin'
FASTEST = 'fastest'
CHEAPEST = 'cheapest'
CAPABILITY = 'capability'
CUSTOM = 'custom'
class agent.types.RouteResult(**data)[source]

Bases: BaseModel

Result of a routing decision.

Parameters:
agent: Any
reason: str | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Config

Configuration types for Agent.

agent.types.config.get_api_key(provider, api_key=None)[source]

Get API key for a provider.

Parameters:
Return type:

str | None

agent.types.config.get_base_url(provider, base_url=None)[source]

Get base URL for a provider.

Parameters:
Return type:

str | None

agent.types.config.resolve_model(model)[source]

Resolve model alias to full model name.

Parameters:

model (str)

Return type:

str

agent.types.config.estimate_cost(model, prompt_tokens, completion_tokens)[source]

Estimate cost for a request.

Parameters:
  • model (str)

  • prompt_tokens (int)

  • completion_tokens (int)

Return type:

float | None

class agent.types.config.ProviderCapabilities(**data)[source]

Bases: BaseModel

Declares what features a provider supports.

Parameters:
  • data (Any)

  • streaming (bool)

  • tools (bool)

  • structured_output (bool)

  • json_mode (bool)

  • vision (bool)

  • system_messages (bool)

  • batch (bool)

  • native_schema_output (bool)

  • max_context_tokens (int | None)

  • max_output_tokens (int | None)

streaming: bool
tools: bool
structured_output: bool
json_mode: bool
vision: bool
system_messages: bool
batch: bool
native_schema_output: bool
max_context_tokens: int | None
max_output_tokens: int | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agent.types.config.AgentConfig(**data)[source]

Bases: BaseModel

Configuration for an Agent instance.

Parameters:
provider: str
model: str
api_key: str | None
base_url: str | None
timeout: float
max_retries: int
temperature: float | None
max_tokens: int | None
top_p: float | None
default_system: str | None
extra: dict[str, Any]
resolve_config()[source]

Resolve model alias and get API key/base URL from environment.

Return type:

AgentConfig

with_overrides(**kwargs)[source]

Create a new config with overrides.

Parameters:

kwargs (Any)

Return type:

AgentConfig

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agent.types.config.RetryConfig(**data)[source]

Bases: BaseModel

Configuration for retry behavior.

Parameters:
max_retries: int
initial_delay: float
max_delay: float
exponential_base: float
jitter: bool
retryable_errors: tuple[type[Exception], ...]
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

should_retry(error, attempt)[source]

Check if we should retry for this error.

Parameters:
Return type:

bool

get_delay(attempt, error=None)[source]

Calculate delay before next retry.

Parameters:
Return type:

float

class agent.types.config.ToolLoopConfig(**data)[source]

Bases: BaseModel

Configuration for tool loop behavior.

Parameters:
  • data (Any)

  • max_iterations (int)

  • max_tool_calls_per_iteration (int)

  • timeout_per_tool (float)

  • parallel_tool_execution (bool)

  • stop_on_error (bool)

max_iterations: int
max_tool_calls_per_iteration: int
timeout_per_tool: float
parallel_tool_execution: bool
stop_on_error: bool
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Messages

Message types for Agent.

class agent.types.messages.ContentPart(**data)[source]

Bases: BaseModel

A part of message content (text, image, etc.).

Parameters:
  • data (Any)

  • type (Literal['text', 'image', 'image_url'])

  • text (str | None)

  • image_url (str | None)

  • image_data (bytes | None)

  • media_type (str | None)

type: Literal['text', 'image', 'image_url']
text: str | None
image_url: str | None
image_data: bytes | None
media_type: str | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

classmethod text_part(text)[source]

Create a text content part.

Parameters:

text (str)

Return type:

ContentPart

classmethod image_url_part(url)[source]

Create an image URL content part.

Parameters:

url (str)

Return type:

ContentPart

classmethod image_data_part(data, media_type='image/png')[source]

Create an image data content part.

Parameters:
Return type:

ContentPart

class agent.types.messages.Message(**data)[source]

Bases: BaseModel

A normalized message in a conversation.

Parameters:
role: Literal['system', 'user', 'assistant', 'tool']
content: str | list[ContentPart]
name: str | None
tool_call_id: str | None
tool_calls: list[dict[str, Any]] | None
classmethod system(content)[source]

Create a system message.

Parameters:

content (str)

Return type:

Message

classmethod user(content)[source]

Create a user message.

Parameters:

content (str | list[ContentPart])

Return type:

Message

classmethod assistant(content=None, tool_calls=None)[source]

Create an assistant message.

Parameters:
Return type:

Message

classmethod tool(content, tool_call_id, name=None)[source]

Create a tool result message.

Parameters:
Return type:

Message

property text: str

Get the text content of the message.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agent.types.messages.AgentRequest(**data)[source]

Bases: BaseModel

A normalized request to be sent to a provider.

Parameters:
input: str | None
messages: list[Message]
system: str | None
tools: list[Any]
output_schema: dict[str, Any] | None
temperature: float | None
max_tokens: int | None
top_p: float | None
stop: list[str] | None
metadata: dict[str, Any]
session_id: str | None
property schema: dict[str, Any] | None

Alias for output_schema for backwards compatibility.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

to_messages()[source]

Convert request to a list of messages.

Return type:

list[Message]

Response

Response types for Agent.

class agent.types.response.Usage(**data)[source]

Bases: BaseModel

Token usage information.

Parameters:
  • data (Any)

  • prompt_tokens (int)

  • completion_tokens (int)

  • total_tokens (int)

prompt_tokens: int
completion_tokens: int
total_tokens: int
classmethod from_dict(data)[source]

Create Usage from a dictionary.

Parameters:

data (dict[str, Any])

Return type:

Usage

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agent.types.response.AgentResponse(**data)[source]

Bases: BaseModel

Normalized response from any provider.

Parameters:
text: str | None
content: list[Any]
output: Any
provider: str
model: str
usage: Usage | None
stop_reason: str | None
tool_calls: list[ToolCall]
raw: Any
latency_ms: float | None
cost_estimate: float | None
request_id: str | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property has_tool_calls: bool

Check if response contains tool calls.

to_dict()[source]

Convert response to a dictionary.

Return type:

dict[str, Any]

Router

Router types for Agent.

class agent.types.router.RoutingStrategy(*values)[source]

Bases: str, Enum

Available routing strategies.

FALLBACK = 'fallback'
ROUND_ROBIN = 'round_robin'
FASTEST = 'fastest'
CHEAPEST = 'cheapest'
CAPABILITY = 'capability'
CUSTOM = 'custom'
class agent.types.router.RouteResult(**data)[source]

Bases: BaseModel

Result of a routing decision.

Parameters:
agent: Any
reason: str | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Stream

Streaming types for Agent.

class agent.types.stream.StreamEvent(**data)[source]

Bases: BaseModel

A normalized streaming event.

Parameters:
  • data (Any)

  • type (Literal['text_delta', 'tool_call_start', 'tool_call_delta', 'tool_result', 'message_start', 'message_end', 'usage', 'error'])

  • text (str | None)

  • tool_call (ToolCall | None)

  • tool_call_delta (dict[str, Any] | None)

  • tool_result (str | None)

  • usage (Usage | None)

  • error (str | None)

  • raw (Any)

type: Literal['text_delta', 'tool_call_start', 'tool_call_delta', 'tool_result', 'message_start', 'message_end', 'usage', 'error']
text: str | None
tool_call: ToolCall | None
tool_call_delta: dict[str, Any] | None
tool_result: str | None
usage: Usage | None
error: str | None
raw: Any
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

classmethod text_delta(text, raw=None)[source]

Create a text delta event.

Parameters:
Return type:

StreamEvent

classmethod tool_call_start(tool_call, raw=None)[source]

Create a tool call start event.

Parameters:
Return type:

StreamEvent

classmethod tool_call_delta_event(tool_call_id, delta, raw=None)[source]

Create a tool call delta event.

Parameters:
Return type:

StreamEvent

classmethod tool_result_event(tool_call_id, result, raw=None)[source]

Create a tool result event.

Parameters:
Return type:

StreamEvent

classmethod message_start_event(raw=None)[source]

Create a message start event.

Parameters:

raw (Any)

Return type:

StreamEvent

classmethod message_end(usage=None, raw=None)[source]

Create a message end event.

Parameters:
Return type:

StreamEvent

classmethod usage_event(usage, raw=None)[source]

Create a usage event.

Parameters:
Return type:

StreamEvent

classmethod error_event(error, raw=None)[source]

Create an error event.

Parameters:
Return type:

StreamEvent

Tools

Tool-related types for Agent.

class agent.types.tools.ToolSpec(**data)[source]

Bases: BaseModel

Specification for a tool that can be called by an LLM.

Parameters:
name: str
description: str
parameters: dict[str, Any]
function: Any | None
is_async: bool
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

to_openai_schema()[source]

Convert to OpenAI function calling format.

Return type:

dict[str, Any]

to_anthropic_schema()[source]

Convert to Anthropic tool format.

Return type:

dict[str, Any]

to_gemini_schema()[source]

Convert to Gemini function declaration format.

Return type:

dict[str, Any]

class agent.types.tools.ToolCall(**data)[source]

Bases: BaseModel

A tool call requested by the LLM.

Parameters:
id: str
name: str
arguments: dict[str, Any]
to_dict()[source]

Convert to dictionary.

Return type:

dict[str, Any]

classmethod from_dict(data)[source]

Create from dictionary.

Parameters:

data (dict[str, Any])

Return type:

ToolCall

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agent.types.tools.ToolResult(**data)[source]

Bases: BaseModel

Result of executing a tool.

Parameters:
tool_call_id: str
name: str
content: str
is_error: bool
to_dict()[source]

Convert to dictionary.

Return type:

dict[str, Any]

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].