Model interface
ModelTracing
Bases: Enum
ソースコード位置: src/agents/models/interface.py
ENABLED
class-attribute
instance-attribute
Tracing is enabled, and all data is included.
Model
Bases: ABC
The base interface for calling an LLM.
Model implementations must assign a non-empty call ID to each tool invocation. A call ID must identify one canonical invocation for the lifetime of the run and its serialized resume lineage; it must not be reused for changed tool identity or payload. An exact completed replay may be omitted by the runtime without re-executing the invocation. Tool outputs must retain the call ID for correlation.
ソースコード位置: src/agents/models/interface.py
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
close
async
Release any resources held by the model.
Models that maintain persistent connections can override this. The default implementation is a no-op.
get_retry_advice
get_retry_advice(
request: ModelRetryAdviceRequest,
) -> ModelRetryAdvice | None
Return provider-specific retry guidance for a failed model request.
Models can override this to surface transport- or provider-specific hints such as replay safety, retry-after delays, or explicit server retry guidance.
ソースコード位置: src/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,
conversation_id: str | None,
prompt: ResponsePromptParam | None,
) -> ModelResponse
Get a response from the model.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
system_instructions
|
str | None
|
The system instructions to use. |
必須 |
input
|
str | list[TResponseInputItem]
|
The input items to the model, in OpenAI Responses format. |
必須 |
model_settings
|
ModelSettings
|
The model settings to use. |
必須 |
tools
|
list[Tool]
|
The tools available to the model. |
必須 |
output_schema
|
AgentOutputSchemaBase | None
|
The output schema to use. |
必須 |
handoffs
|
list[Handoff]
|
The handoffs available to the model. |
必須 |
tracing
|
ModelTracing
|
Tracing configuration. |
必須 |
previous_response_id
|
str | None
|
the ID of the previous response. Generally not used by the model, except for the OpenAI Responses API. |
必須 |
conversation_id
|
str | None
|
The ID of the stored conversation, if any. |
必須 |
prompt
|
ResponsePromptParam | None
|
The prompt config to use for the model. |
必須 |
戻り値:
| タイプ | デスクリプション |
|---|---|
ModelResponse
|
The full model response. |
ソースコード位置: src/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,
conversation_id: str | None,
prompt: ResponsePromptParam | None,
) -> AsyncIterator[TResponseStreamEvent]
Stream a response from the model.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
system_instructions
|
str | None
|
The system instructions to use. |
必須 |
input
|
str | list[TResponseInputItem]
|
The input items to the model, in OpenAI Responses format. |
必須 |
model_settings
|
ModelSettings
|
The model settings to use. |
必須 |
tools
|
list[Tool]
|
The tools available to the model. |
必須 |
output_schema
|
AgentOutputSchemaBase | None
|
The output schema to use. |
必須 |
handoffs
|
list[Handoff]
|
The handoffs available to the model. |
必須 |
tracing
|
ModelTracing
|
Tracing configuration. |
必須 |
previous_response_id
|
str | None
|
the ID of the previous response. Generally not used by the model, except for the OpenAI Responses API. |
必須 |
conversation_id
|
str | None
|
The ID of the stored conversation, if any. |
必須 |
prompt
|
ResponsePromptParam | None
|
The prompt config to use for the model. |
必須 |
戻り値:
| タイプ | デスクリプション |
|---|---|
AsyncIterator[TResponseStreamEvent]
|
An iterator of response stream events, in OpenAI Responses format. |
ソースコード位置: src/agents/models/interface.py
ModelProvider
Bases: ABC
The base interface for a model provider.
Model provider is responsible for looking up Models by name.
ソースコード位置: src/agents/models/interface.py
get_model
abstractmethod
get_model(model_name: str | None) -> Model
Get a model by name.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
model_name
|
str | None
|
The name of the model to get. |
必須 |
戻り値:
| タイプ | デスクリプション |
|---|---|
Model
|
The model. |
aclose
async
Release any resources held by the provider.
Providers that cache persistent models or network connections can override this. The default implementation is a no-op.