Schema
Modules concerning the schema of GLLM Inference modules.
Activity
Bases: BaseModel
Base schema for any activity.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
The type of activity being performed. Defaults to an empty string. |
ActivityEvent
Bases: Event
Event schema for model-triggered activities (e.g. web search, MCP call, etc.).
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The ID of the activity event. Defaults to None. |
value |
dict[str, Any]
|
The value of the activity event. |
level |
EventLevel
|
The severity level of the activity event. Defaults to EventLevel.INFO. |
type |
Literal[ACTIVITY]
|
The type of the activity event. Defaults to EventType.ACTIVITY. |
timestamp |
datetime
|
The timestamp of the activity event. Defaults to the current timestamp. |
metadata |
dict[str, Any]
|
The metadata of the activity event. Defaults to an empty dictionary. |
from_activity(id_=None, activity=None)
classmethod
Create an activity event from an Activity object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_ |
str | None
|
The ID of the activity event. Defaults to None. |
None
|
activity |
Activity | None
|
The activity object to create the event from. Defaults to None, in which case the value will be an empty dictionary. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ActivityEvent |
ActivityEvent
|
The activity event. |
Attachment
Bases: BaseModel
Defines a file attachment schema.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
bytes
|
The content data of the file attachment. |
filename |
str
|
The filename of the file attachment. |
mime_type |
str
|
The mime type of the file attachment. |
extension |
str
|
The extension of the file attachment. |
url |
str | None
|
The URL of the file attachment. Defaults to None. |
metadata |
dict[str, Any]
|
The metadata of the file attachment. Defaults to an empty dictionary. |
__repr__()
Return string representation of the Attachment.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the Attachment. |
__str__()
Return string representation of the Attachment.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the Attachment. |
from_base64(base64_data, filename=None, metadata=None)
classmethod
Creates an Attachment from a base64 string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base64_data |
str
|
The base64 string of the file. |
required |
filename |
str | None
|
The filename of the file. Defaults to None, in which case the filename will be derived from the mime type. |
None
|
metadata |
dict[str, Any] | None
|
The metadata of the file attachment. Defaults to None, in which case an empty dictionary will be used. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Attachment |
Attachment
|
The instantiated Attachment. |
from_bytes(bytes, filename=None, metadata=None)
classmethod
Creates an Attachment from bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bytes |
bytes
|
The bytes of the file. |
required |
filename |
str | None
|
The filename of the file. Defaults to None, in which case the filename will be derived from the extension. |
None
|
metadata |
dict[str, Any] | None
|
The metadata of the file attachment. Defaults to None, in which case an empty dictionary will be used. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Attachment |
Attachment
|
The instantiated Attachment. |
from_data_url(data_url, filename=None, metadata=None)
classmethod
Creates an Attachment from a data URL (data:[mime/type];base64,[bytes]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_url |
str
|
The data URL of the file. |
required |
filename |
str | None
|
The filename of the file. Defaults to None, in which case the filename will be derived from the mime type. |
None
|
metadata |
dict[str, Any] | None
|
The metadata of the file attachment. Defaults to None, in which case an empty dictionary will be used. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Attachment |
Attachment
|
The instantiated Attachment. |
from_path(path, filename=None, metadata=None)
classmethod
Creates an Attachment from a path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
The path to the file. |
required |
filename |
str | None
|
The filename of the file. Defaults to None, in which case the filename will be derived from the path. |
None
|
metadata |
dict[str, Any] | None
|
The metadata of the file attachment. Defaults to None, in which case an empty dictionary will be used. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Attachment |
Attachment
|
The instantiated Attachment. |
from_url(url, filename=None, metadata=None)
classmethod
Creates an Attachment from a URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str
|
The URL of the file. |
required |
filename |
str | None
|
The filename of the file. Defaults to None, in which case the filename will be derived from the URL. |
None
|
metadata |
dict[str, Any] | None
|
The metadata of the file attachment. Defaults to None, in which case an empty dictionary will be used. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Attachment |
Attachment
|
The instantiated Attachment. |
write_to_file(path=None)
Writes the Attachment to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str | None
|
The path to the file. Defaults to None, in which case the filename will be used as the path. |
None
|
AttachmentType
Bases: StrEnum
Defines valid attachment types.
BatchStatus
Bases: StrEnum
Defines the status of a batch job.
CodeEvent
Bases: BlockBasedEvent
Event schema for model-generated code to be executed.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The ID of the code event. Defaults to None. |
value |
str
|
The value of the code event. Defaults to an empty string. |
level |
EventLevel
|
The severity level of the code event. Defaults to EventLevel.INFO. |
type |
CodeEventType
|
The type of the code event. Defaults to EventType.CODE. |
timestamp |
datetime
|
The timestamp of the code event. Defaults to the current timestamp. |
metadata |
dict[str, Any]
|
The metadata of the code event. Defaults to an empty dictionary. |
CodeExecResult
Bases: BaseModel
Defines a code execution result when a language model is configured to execute code.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The ID of the code execution. Defaults to an empty string. |
code |
str
|
The executed code. Defaults to an empty string. |
output |
list[str | Attachment]
|
The output of the executed code. Defaults to an empty list. |
EmitDataType
Bases: StrEnum
Defines valid data types for emitting events.
InputTokenDetails
Bases: BaseModel
Defines the input token details schema.
Attributes:
| Name | Type | Description |
|---|---|---|
cached_tokens |
int
|
The number of cached tokens. Defaults to 0. |
uncached_tokens |
int
|
The number of uncached tokens. Defaults to 0. |
__add__(other)
Add two InputTokenDetails objects together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other |
InputTokenDetails
|
The other InputTokenDetails object to add. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
InputTokenDetails |
InputTokenDetails
|
A new InputTokenDetails object with summed values. |
JinjaEnvType
Bases: StrEnum
Enumeration for Jinja environment types.
LMEventType
Bases: StrEnum
Defines event types to be emitted by the LM invoker.
LMEventTypeSuffix
Bases: StrEnum
Defines suffixes for LM event types.
LMOutput(*, outputs=None, token_usage=None, duration=None, finish_details=None, response='', structured_output=None, tool_calls=None, reasoning=None, attachments=None, citations=None, code_exec_results=None, mcp_calls=None)
Bases: BaseModel
Defines the output of a language model.
Attributes:
| Name | Type | Description |
|---|---|---|
outputs |
list[LMOutputItem]
|
The outputs of the language model in sequential order. Defaults to an empty list. |
token_usage |
TokenUsage | None
|
The token usage analytics, if requested. Defaults to None. |
duration |
float | None
|
The duration of the invocation in seconds, if requested. Defaults to None. |
finish_details |
dict[str, Any]
|
The details about how the generation finished, if requested. Defaults to an empty dictionary. |
text |
str
|
The first text response. |
structured_output |
dict[str, Any] | BaseModel | None
|
The first structured output. |
texts |
list[str]
|
The texts from the outputs. |
structured_outputs |
list[dict[str, Any] | BaseModel]
|
The structured outputs from the outputs. |
attachments |
list[Attachment]
|
The attachments from the outputs. |
tool_calls |
list[ToolCall]
|
The tool calls from the outputs. |
thinkings |
list[Reasoning]
|
The thinkings from the outputs. |
citations |
list[Chunk]
|
The citations from the outputs. |
code_exec_results |
list[CodeExecResult]
|
The code exec results from the outputs. |
mcp_calls |
list[MCPCall]
|
The MCP calls from the outputs. |
response |
str
|
Deprecated. Replaced by |
reasoning |
list[Reasoning]
|
Deprecated. Replaced by |
Initialize the LMOutput.
This constructor is created for backward compatibility with the legacy method to initialize the LMOutput. This constructor will be removed in v0.6.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outputs |
list[LMOutputItem] | None
|
The output items. Defaults to an empty list. |
None
|
token_usage |
TokenUsage | None
|
The token usage analytics. Defaults to None. |
None
|
duration |
float | None
|
The duration of the invocation in seconds. Defaults to None. |
None
|
finish_details |
dict[str, Any] | None
|
The details about how the generation finished. Defaults to an empty dictionary. |
None
|
response |
str
|
The first text response. Defaults to an empty string. |
''
|
structured_output |
dict[str, Any] | BaseModel | None
|
The first structured output. Defaults to None. |
None
|
tool_calls |
list[ToolCall] | None
|
The tool calls. Defaults to None. |
None
|
reasoning |
list[Reasoning] | None
|
The thinkings. Defaults to None. |
None
|
attachments |
list[Attachment] | None
|
The attachments. Defaults to None. |
None
|
citations |
list[Chunk] | None
|
The citations. Defaults to None. |
None
|
code_exec_results |
list[CodeExecResult] | None
|
The code exec results. Defaults to None. |
None
|
mcp_calls |
list[MCPCall] | None
|
The MCP calls. Defaults to None. |
None
|
attachments: list[Attachment]
property
writable
Get the attachments from the LMOutput.
Returns:
| Type | Description |
|---|---|
list[Attachment]
|
list[Attachment]: The attachments from the LMOutput. |
citations: list[Chunk]
property
writable
Get the citations from the LMOutput.
Returns:
| Type | Description |
|---|---|
list[Chunk]
|
list[Chunk]: The citations from the LMOutput. |
code_exec_results: list[CodeExecResult]
property
writable
Get the code exec results from the LMOutput.
Returns:
| Type | Description |
|---|---|
list[CodeExecResult]
|
list[CodeExecResult]: The code exec results from the LMOutput. |
mcp_calls: list[MCPCall]
property
writable
Get the MCP calls from the LMOutput.
Returns:
| Type | Description |
|---|---|
list[MCPCall]
|
list[MCPCall]: The MCP calls from the LMOutput. |
reasoning: list[Reasoning]
property
writable
Deprecated property to get the thinkings from the LMOutput.
Returns:
| Type | Description |
|---|---|
list[Reasoning]
|
list[Reasoning]: The thinkings from the LMOutput. |
response: str
property
writable
Deprecated property to get the first text response from the LMOutput.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The first text response from the LMOutput. |
structured_output: dict[str, Any] | BaseModel | None
property
writable
Deprecated property to get the first structured output from the LMOutput.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | BaseModel | None
|
dict[str, Any] | BaseModel | None: The first structured output from the LMOutput. |
structured_outputs: list[dict[str, Any] | BaseModel]
property
Get the structured outputs from the LMOutput.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any] | BaseModel]
|
list[dict[str, Any] | BaseModel]: The structured outputs from the LMOutput. |
text: str
property
Get the first text from the LMOutput.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The first text from the LMOutput. |
texts: list[str]
property
Get the texts from the LMOutput.
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The texts from the LMOutput. |
thinkings: list[Reasoning]
property
Get the thinkings from the LMOutput.
Returns:
| Type | Description |
|---|---|
list[Reasoning]
|
list[Reasoning]: The thinkings from the LMOutput. |
tool_calls: list[ToolCall]
property
writable
Get the tool calls from the LMOutput.
Returns:
| Type | Description |
|---|---|
list[ToolCall]
|
list[ToolCall]: The tool calls from the LMOutput. |
__repr__()
Return string representation of the LMOutput.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the LMOutput. |
__str__()
Return string representation of the LMOutput.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the LMOutput. |
add_attachment(attachment)
Add an attachment or a list of attachments to the LMOutput.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attachment |
Attachment | list[Attachment]
|
The attachment or a list of attachments to add. |
required |
add_citation(citation)
add_code_exec_result(code_exec_result)
Add a code exec result or a list of code exec results to the LMOutput.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code_exec_result |
CodeExecResult | list[CodeExecResult]
|
The code exec result or a list of code exec results to add. |
required |
add_mcp_call(mcp_call)
add_structured(structured)
Add a structured output or a list of structured outputs to the LMOutput.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structured |
dict[str, Any] | BaseModel | list[dict[str, Any] | BaseModel]
|
The structured output or a list of structured outputs to add. |
required |
add_text(text)
Add an output or a list of outputs to the LMOutput.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text |
str | list[str]
|
The text or a list of texts to add. |
required |
add_thinking(thinking)
LMOutputItem
Bases: BaseModel
Defines the output item of a language model.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
The type of the output item. |
output |
LMOutputData
|
The output data of the output item. |
__repr__()
Return string representation of the LMOutputItem.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the LMOutputItem. |
__str__()
Return string representation of the LMOutputItem.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the LMOutputItem. |
LMOutputType
Bases: StrEnum
Defines valid types for language model outputs.
MCPCall
Bases: BaseModel
Defines an MCP call.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The ID of the MCP call. Defaults to an empty string. |
server_name |
str
|
The name of the MCP server. Defaults to an empty string. |
tool_name |
str
|
The name of the tool. Defaults to an empty string. |
args |
dict[str, Any]
|
The arguments of the tool. Defaults to an empty dictionary. |
output |
str | None
|
The output of the tool. Defaults to None. |
MCPCallActivity
Bases: Activity
Schema for MCP tool call.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal[MCP_CALL]
|
The type of activity being performed. Defaults to ActivityType.MCP_CALL. |
server_name |
str
|
The name of the MCP server. |
tool_name |
str
|
The name of the tool. |
args |
dict[str, str]
|
The arguments of the tool. |
MCPListToolsActivity
Bases: Activity
Schema for listing tools in MCP.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal[MCP_LIST_TOOLS]
|
The type of activity being performed. Defaults to ActivityType.MCP_LIST_TOOLS. |
server_name |
str
|
The name of the MCP server. Defaults to an empty string. |
tools |
list[dict[str, str]] | None
|
The tools in the MCP server. Defaults to None. |
MCPServer
Bases: BaseModel
Defines an MCP server.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
The URL of the MCP server. |
name |
str
|
The name of the MCP server. |
allowed_tools |
list[str] | None
|
The allowed tools of the MCP server. Defaults to None, in which case all tools are allowed. |
Message
Bases: BaseModel
Defines a message schema to be used as inputs for a language model.
Attributes:
| Name | Type | Description |
|---|---|---|
role |
MessageRole
|
The role of the message. |
contents |
list[MessageContent]
|
The contents of the message. |
metadata |
dict[str, Any]
|
The metadata of the message. |
assistant(contents, metadata=None)
classmethod
Create an assistant message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents |
MessageContent | list[MessageContent]
|
The message contents. If a single content is provided, it will be wrapped in a list. |
required |
metadata |
dict[str, Any]
|
Additional metadata for the message. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
A new message with ASSISTANT role. |
system(contents, metadata=None)
classmethod
Create a system message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents |
MessageContent | list[MessageContent]
|
The message contents. If a single content is provided, it will be wrapped in a list. |
required |
metadata |
dict[str, Any]
|
Additional metadata for the message. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
A new message with SYSTEM role. |
user(contents, metadata=None)
classmethod
Create a user message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents |
MessageContent | list[MessageContent]
|
The message contents. If a single content is provided, it will be wrapped in a list. |
required |
metadata |
dict[str, Any]
|
Additional metadata for the message. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
A new message with USER role. |
MessageRole
Bases: StrEnum
Defines valid message roles.
ModelId
Bases: BaseModel
Defines a representation of a valid model id.
Attributes:
| Name | Type | Description |
|---|---|---|
provider |
ModelProvider
|
The provider of the model. |
name |
str | None
|
The name of the model. |
path |
str | None
|
The path of the model. |
Provider-specific examples
Using Anthropic
model_id = ModelId.from_string("anthropic/claude-sonnet-4-20250514")
Using Bedrock
model_id = ModelId.from_string("bedrock/us.anthropic.claude-sonnet-4-20250514-v1:0")
Using Cohere
model_id = ModelId.from_string("cohere/embed-english-v3.0")
Using Cohere with custom endpoint
model_id = ModelId.from_string("cohere/https://my-cohere-url:8000/v1:my-model-name")
Using Datasaur
model_id = ModelId.from_string("datasaur/https://deployment.datasaur.ai/api/deployment/teamId/deploymentId/")
Using Google
model_id = ModelId.from_string("google/gemini-2.5-flash-lite")
Using Jina
model_id = ModelId.from_string("jina/jina-embeddings-v2-large")
Using Jina with custom endpoint
model_id = ModelId.from_string("jina/https://my-jina-url:8000/v1:my-model-name")
Using OpenAI
model_id = ModelId.from_string("openai/gpt-5-nano")
Using OpenAI with Chat Completions API
model_id = ModelId.from_string("openai-chat-completions/gpt-5-nano")
Using OpenAI Responses API-compatible endpoints (e.g. SGLang)
model_id = ModelId.from_string("openai/https://my-sglang-url:8000/v1:my-model-name")
Using OpenAI Chat Completions API-compatible endpoints (e.g. Groq)
model_id = ModelId.from_string("openai-chat-completions/https://api.groq.com/openai/v1:llama3-8b-8192")
Using Azure OpenAI
model_id = ModelId.from_string("azure-openai/https://my-resource.openai.azure.com/openai/v1:my-deployment")
Using Voyage
model_id = ModelId.from_string("voyage/voyage-3.5-lite")
Using TwelveLabs
model_id = ModelId.from_string("twelvelabs/Marengo-retrieval-2.7")
Using LangChain
model_id = ModelId.from_string("langchain/langchain_openai.ChatOpenAI:gpt-4o-mini")
For the list of supported providers, please refer to the following table: https://python.langchain.com/docs/integrations/chat/#featured-providers
Using LiteLLM
model_id = ModelId.from_string("litellm/openai/gpt-4o-mini")
For the list of supported providers, please refer to the following page: https://docs.litellm.ai/docs/providers/
Using xAI
model_id = ModelId.from_string("xai/grok-4-0709")
For the list of supported models, please refer to the following page: https://docs.x.ai/docs/models
Custom model name validation example
validation_map = {
ModelProvider.ANTHROPIC: {"claude-sonnet-4-20250514"},
ModelProvider.GOOGLE: {"gemini-2.5-flash-lite"},
ModelProvider.OPENAI: {"gpt-4.1-nano", "gpt-5-nano"},
}
model_id = ModelId.from_string("...", validation_map)
from_string(model_id, validation_map=None)
classmethod
Parse a model id string into a ModelId object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id |
str
|
The model id to parse. Must be in the format defined in the following page: https://gdplabs.gitbook.io/sdk/resources/supported-models |
required |
validation_map |
dict[str, set[str]] | None
|
An optional dictionary that maps provider names to sets of valid model names. For the defined model providers, the model names will be validated against the set of valid model names. For the undefined model providers, the model name will not be validated. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ModelId |
ModelId
|
The parsed ModelId object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided model id is invalid or if the model name is not valid for the provider. |
to_string()
Convert the ModelId object to a string.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the ModelId object. The format is defined in the following page: https://gdplabs.gitbook.io/sdk/resources/supported-models |
ModelProvider
Bases: StrEnum
Defines the supported model providers.
OutputTokenDetails
Bases: BaseModel
Defines the output token details schema.
Attributes:
| Name | Type | Description |
|---|---|---|
reasoning_tokens |
int
|
The number of reasoning tokens. Defaults to 0. |
response_tokens |
int
|
The number of response tokens. Defaults to 0. |
__add__(other)
Add two OutputTokenDetails objects together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other |
OutputTokenDetails
|
The other OutputTokenDetails object to add. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
OutputTokenDetails |
OutputTokenDetails
|
A new OutputTokenDetails object with summed values. |
Reasoning
Bases: BaseModel
Defines a reasoning output when a language model is configured to use reasoning.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The ID of the reasoning output. Defaults to an empty string. |
reasoning |
str
|
The reasoning text. Defaults to an empty string. |
type |
str
|
The type of the reasoning output. Defaults to an empty string. |
data |
str
|
The additional data of the reasoning output. Defaults to an empty string. |
ThinkingEvent
Bases: BlockBasedEvent
Event schema for model-generated thinking.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The ID of the thinking event. Defaults to None. |
value |
str
|
The value of the thinking event. Defaults to an empty string. |
level |
EventLevel
|
The severity level of the thinking event. Defaults to EventLevel.INFO. |
type |
ThinkingEventType
|
The type of the thinking event. Defaults to EventType.THINKING. |
timestamp |
datetime
|
The timestamp of the thinking event. Defaults to the current timestamp. |
metadata |
dict[str, Any]
|
The metadata of the thinking event. Defaults to an empty dictionary. |
TokenUsage
Bases: BaseModel
Defines the token usage data structure of a language model.
Attributes:
| Name | Type | Description |
|---|---|---|
input_tokens |
int
|
The number of input tokens. Defaults to 0. |
output_tokens |
int
|
The number of output tokens. Defaults to 0. |
input_token_details |
InputTokenDetails | None
|
The details of the input tokens. Defaults to None. |
output_token_details |
OutputTokenDetails | None
|
The details of the output tokens. Defaults to None. |
__add__(other)
Add two TokenUsage objects together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other |
TokenUsage
|
The other TokenUsage object to add. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TokenUsage |
TokenUsage
|
A new TokenUsage object with summed values. |
__repr__()
Return string representation of the TokenUsage.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the TokenUsage. |
__str__()
Return string representation of the TokenUsage.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the TokenUsage. |
from_token_details(input_tokens=None, output_tokens=None, cached_tokens=None, reasoning_tokens=None)
classmethod
Creates a TokenUsage from token details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_tokens |
int | None
|
The number of input tokens. Defaults to None. |
None
|
output_tokens |
int | None
|
The number of output tokens. Defaults to None. |
None
|
cached_tokens |
int | None
|
The number of cached tokens. Defaults to None. |
None
|
reasoning_tokens |
int | None
|
The number of reasoning tokens. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
TokenUsage |
TokenUsage
|
The instantiated TokenUsage. |
ToolCall
Bases: BaseModel
Defines a tool call request when a language model decides to invoke a tool.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The ID of the tool call. |
name |
str
|
The name of the tool. |
args |
dict[str, Any]
|
The arguments of the tool call. |
ToolResult
Bases: BaseModel
Defines a tool result to be sent back to the language model.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The ID of the tool call. |
output |
str
|
The output of the tool call. |
TruncateSide
Bases: StrEnum
Enumeration for truncation sides.
TruncationConfig
Bases: BaseModel
Configuration for text truncation behavior.
Attributes:
| Name | Type | Description |
|---|---|---|
max_length |
int
|
Maximum length of text content. Required. |
truncate_side |
TruncateSide | None
|
Side to truncate from when max_length is exceeded. 1. TruncateSide.RIGHT: Keep the beginning of the text, truncate from the end (default) 2. TruncateSide.LEFT: Keep the end of the text, truncate from the beginning If None, defaults to TruncateSide.RIGHT |
WebSearchActivity
Bases: Activity
Schema for web search tool call.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
WebSearchActivityTypes
|
The type of activity being performed. Defaults to ActivityType.SEARCH. |
query |
str | None
|
The query of the web search. Defaults to None. |
url |
str | None
|
The URL of the page. Defaults to None. |
pattern |
str | None
|
The pattern of the web search. Defaults to None. |
sources |
list[dict[str, str]] | None
|
The sources of the web search. |
model_dump(*args, **kwargs)
Serialize the activity for display.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
dict[str, str]: The serialized activity. |