Model interface
ModelTracing
Bases: Enum
Source code in agents/models/interface.py
Model
Bases: ABC
调用 LLM 的基础接口。
Source code in agents/models/interface.py
get_response
abstractmethod
async
get_response(system_instructions: str | None, input: str | list[TResponseInputItem], model_settings: ModelSettings, tools: list[Tool], output_schema: AgentOutputSchemaBase | None, handoffs: list[Handoff], tracing: ModelTracing, *, previous_response_id: str | None) -> ModelResponse
从模型获取响应。
参数
system_instructions: 要使用的系统指令。 input: 传递给模型的输入项,采用 OpenAI Responses 格式。 model_settings: 要使用的模型设置。 tools: 模型可用的工具列表。 output_schema: 要使用的输出模式。 handoffs: 模型可用的 handoff 列表。 tracing: 追踪配置。 previous_response_id: 上一个响应的 ID。通常模型不会用到,除了 OpenAI Responses API。
返回
完整的模型响应。
Source code in agents/models/interface.py
stream_response
abstractmethod
stream_response(system_instructions: str | None, input: str | list[TResponseInputItem], model_settings: ModelSettings, tools: list[Tool], output_schema: AgentOutputSchemaBase | None, handoffs: list[Handoff], tracing: ModelTracing, *, previous_response_id: str | None) -> AsyncIterator[TResponseStreamEvent]
从模型流式获取响应。
参数
system_instructions: 要使用的系统指令。 input: 传递给模型的输入项,采用 OpenAI Responses 格式。 model_settings: 要使用的模型设置。 tools: 模型可用的工具列表。 output_schema: 要使用的输出模式。 handoffs: 模型可用的 handoff 列表。 tracing: 追踪配置。 previous_response_id: 上一个响应的 ID。通常模型不会用到,除了 OpenAI Responses API。
返回
响应流事件的迭代器,采用 OpenAI Responses 格式。
Source code in agents/models/interface.py
ModelProvider
Bases: ABC
模型提供者的基础接口。
模型提供者负责通过名称查找模型。
Source code in agents/models/interface.py
get_model
abstractmethod
get_model(model_name: str | None) -> Model