APIリファレンス¶
このページでは、mkdocstringsプラグインを使用してagents_sdk_models
パッケージのAPIリファレンスを自動生成します。
Agents SDK Models エージェントSDKモデル
AgentPipeline
¶
AgentPipeline class for managing the generation and evaluation of content using OpenAI Agents SDK OpenAI Agents SDKを使用してコンテンツの生成と評価を管理するパイプラインクラス
This class handles: このクラスは以下を処理します: - Content generation using instructions / instructionsを使用したコンテンツ生成 - Content evaluation with scoring / スコアリングによるコンテンツ評価 - Session history management / セッション履歴の管理 - Output formatting and routing / 出力のフォーマットとルーティング
Source code in src\agents_sdk_models\pipeline.py
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 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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
__init__(name, generation_instructions, evaluation_instructions, *, input_guardrails=None, output_guardrails=None, output_model=None, model=None, evaluation_model=None, generation_tools=None, evaluation_tools=None, routing_func=None, session_history=None, history_size=10, threshold=85, retries=3, improvement_callback=None, dynamic_prompt=None, retry_comment_importance=None)
¶
Initialize the Pipeline with configuration parameters 設定パラメータでパイプラインを初期化する
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Pipeline name / パイプライン名 |
required |
generation_instructions
|
str
|
System prompt for generation / 生成用システムプロンプト |
required |
evaluation_instructions
|
Optional[str]
|
System prompt for evaluation / 評価用システムプロンプト |
required |
input_guardrails
|
Optional[list]
|
Guardrails for generation / 生成用ガードレール |
None
|
output_guardrails
|
Optional[list]
|
Guardrails for evaluation / 評価用ガードレール |
None
|
output_model
|
Optional[Type[Any]]
|
Model for output formatting / 出力フォーマット用モデル |
None
|
model
|
str | None
|
LLM model name / LLMモデル名 |
None
|
evaluation_model
|
str | None
|
Optional LLM model name for evaluation; if None, uses model. 日本語: 評価用のLLMモデル名(Noneの場合はmodelを使用) |
None
|
generation_tools
|
Optional[list]
|
Tools for generation / 生成用ツール |
None
|
evaluation_tools
|
Optional[list]
|
Tools for evaluation / 評価用ツール |
None
|
routing_func
|
Optional[Callable[[Any], Any]]
|
Function for output routing / 出力ルーティング用関数 |
None
|
session_history
|
Optional[list]
|
Session history / セッション履歴 |
None
|
history_size
|
int
|
Size of history to keep / 保持する履歴サイズ |
10
|
threshold
|
int
|
Evaluation score threshold / 評価スコアの閾値 |
85
|
retries
|
int
|
Number of retry attempts / リトライ試行回数 |
3
|
improvement_callback
|
Optional[Callable[[Any, EvaluationResult], None]]
|
Callback for improvement suggestions / 改善提案用コールバック |
None
|
dynamic_prompt
|
Optional[Callable[[str], str]]
|
Optional function to dynamically build prompt / 動的プロンプト生成関数(任意) |
None
|
retry_comment_importance
|
Optional[list[str]]
|
Importance levels of comments to include on retry / リトライ時にプロンプトに含めるコメントの重大度レベル(任意) |
None
|
Source code in src\agents_sdk_models\pipeline.py
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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
run(user_input)
¶
Run the pipeline with user input ユーザー入力でパイプラインを実行する
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_input
|
str
|
User input text / ユーザー入力テキスト |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Processed output or None if evaluation fails / 処理済み出力、または評価失敗時はNone |
Source code in src\agents_sdk_models\pipeline.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
ClaudeModel
¶
Bases: OpenAIChatCompletionsModel
Anthropic Claude model implementation that extends OpenAI's chat completions model OpenAIのチャット補完モデルを拡張したAnthropic Claudeモデルの実装
Source code in src\agents_sdk_models\anthropic.py
11 12 13 14 15 16 17 18 19 20 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 81 82 83 84 85 86 87 88 89 90 |
|
__init__(model='claude-3-5-sonnet-latest', temperature=0.3, api_key=None, base_url='https://api.anthropic.com/v1/', thinking=False, **kwargs)
¶
Initialize the Anthropic Claude model with OpenAI compatible interface OpenAI互換インターフェースでAnthropic Claudeモデルを初期化する
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
Name of the Claude model to use (e.g. "claude-3-5-sonnet-latest") 使用するClaudeモデルの名前(例:"claude-3-5-sonnet-latest") |
'claude-3-5-sonnet-latest'
|
temperature
|
float
|
Sampling temperature between 0 and 1 サンプリング温度(0から1の間) |
0.3
|
api_key
|
str
|
Anthropic API key Anthropic APIキー |
None
|
base_url
|
str
|
Base URL for the Anthropic OpenAI compatibility API Anthropic OpenAI互換APIのベースURL |
'https://api.anthropic.com/v1/'
|
thinking
|
bool
|
Enable extended thinking for complex reasoning 複雑な推論のための拡張思考を有効にする |
False
|
**kwargs
|
Any
|
Additional arguments to pass to the OpenAI API OpenAI APIに渡す追加の引数 |
{}
|
Source code in src\agents_sdk_models\anthropic.py
17 18 19 20 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 |
|
EvaluationResult
dataclass
¶
Result of evaluation for generated content 生成されたコンテンツの評価結果を保持するクラス
Source code in src\agents_sdk_models\pipeline.py
24 25 26 27 28 29 30 31 |
|
GeminiModel
¶
Bases: OpenAIChatCompletionsModel
Gemini model implementation that extends OpenAI's chat completions model OpenAIのチャット補完モデルを拡張したGeminiモデルの実装
Source code in src\agents_sdk_models\gemini.py
11 12 13 14 15 16 17 18 19 20 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 |
|
__init__(model='gemini-2.0-flash', temperature=0.3, api_key=None, base_url='https://generativelanguage.googleapis.com/v1beta/openai/', **kwargs)
¶
Initialize the Gemini model with OpenAI compatible interface OpenAI互換インターフェースでGeminiモデルを初期化する
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
Name of the Gemini model to use (e.g. "gemini-2.0-flash") 使用するGeminiモデルの名前(例:"gemini-2.0-flash") |
'gemini-2.0-flash'
|
temperature
|
float
|
Sampling temperature between 0 and 1 サンプリング温度(0から1の間) |
0.3
|
api_key
|
str
|
Gemini API key Gemini APIキー |
None
|
base_url
|
str
|
Base URL for the Gemini API Gemini APIのベースURL |
'https://generativelanguage.googleapis.com/v1beta/openai/'
|
**kwargs
|
Any
|
Additional arguments to pass to the OpenAI API OpenAI APIに渡す追加の引数 |
{}
|
Source code in src\agents_sdk_models\gemini.py
17 18 19 20 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 |
|
OllamaModel
¶
Bases: OpenAIChatCompletionsModel
Ollama model implementation that extends OpenAI's chat completions model OpenAIのチャット補完モデルを拡張したOllamaモデルの実装
Source code in src\agents_sdk_models\ollama.py
10 11 12 13 14 15 16 17 18 19 20 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 |
|
__init__(model='phi4-mini:latest', temperature=0.3, base_url=None, **kwargs)
¶
Initialize the Ollama model with OpenAI compatible interface OpenAI互換インターフェースでOllamaモデルを初期化する
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
Name of the Ollama model to use (e.g. "phi4-mini") 使用するOllamaモデルの名前(例:"phi4-mini") |
'phi4-mini:latest'
|
temperature
|
float
|
Sampling temperature between 0 and 1 サンプリング温度(0から1の間) |
0.3
|
base_url
|
str
|
Base URL for the Ollama API Ollama APIのベースURL |
None
|
**kwargs
|
Any
|
Additional arguments to pass to the OpenAI API OpenAI APIに渡す追加の引数 |
{}
|
Source code in src\agents_sdk_models\ollama.py
16 17 18 19 20 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 |
|
disable_tracing()
¶
English: Disable all tracing. 日本語: トレーシング機能をすべて無効化します。
Source code in src\agents_sdk_models\tracing.py
124 125 126 127 128 129 |
|
enable_console_tracing()
¶
English: Enable console tracing by registering ConsoleTracingProcessor and enabling tracing. 日本語: ConsoleTracingProcessorを登録してトレーシングを有効化します。
Source code in src\agents_sdk_models\tracing.py
113 114 115 116 117 118 119 120 121 |
|
get_llm(model=None, provider=None, temperature=0.3, api_key=None, base_url=None, thinking=False, **kwargs)
¶
Factory function to get an instance of a language model based on the provider.
English: Factory function to get an instance of a language model based on the provider.
日本語: プロバイダーに基づいて言語モデルのインスタンスを取得するファクトリ関数。
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider
|
ProviderType
|
The LLM provider ("openai", "google", "anthropic", "ollama"). Defaults to "openai". LLM プロバイダー ("openai", "google", "anthropic", "ollama")。デフォルトは "openai"。 |
None
|
model
|
Optional[str]
|
The specific model name for the provider. If None, uses the default for the provider. プロバイダー固有のモデル名。None の場合、プロバイダーのデフォルトを使用します。 |
None
|
temperature
|
float
|
Sampling temperature. Defaults to 0.3. サンプリング温度。デフォルトは 0.3。 |
0.3
|
api_key
|
Optional[str]
|
API key for the provider, if required. プロバイダーの API キー (必要な場合)。 |
None
|
base_url
|
Optional[str]
|
Base URL for the provider's API, if needed (e.g., for self-hosted Ollama or OpenAI-compatible APIs). プロバイダー API のベース URL (必要な場合、例: セルフホストの Ollama や OpenAI 互換 API)。 |
None
|
thinking
|
bool
|
Enable thinking mode for Claude models. Defaults to False. Claude モデルの思考モードを有効にするか。デフォルトは False。 |
False
|
tracing
|
bool
|
Whether to enable tracing for the Agents SDK. Defaults to False. Agents SDK のトレーシングを有効化するか。デフォルトは False。 |
required |
**kwargs
|
Any
|
Additional keyword arguments to pass to the model constructor. モデルのコンストラクタに渡す追加のキーワード引数。 |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Model |
Model
|
An instance of the appropriate language model class. 適切な言語モデルクラスのインスタンス。 |
Raises:
Type | Description |
---|---|
ValueError
|
If an unsupported provider is specified. サポートされていないプロバイダーが指定された場合。 |
Source code in src\agents_sdk_models\llm.py
19 20 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 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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
クラス・関数一覧¶
名前 | 種別 | 概要 |
---|---|---|
get_llm | 関数 | モデル名・プロバイダー名からLLMインスタンスを取得 |
AgentPipeline | クラス | 生成・評価・ツール・ガードレールを統合したパイプライン |
ConsoleTracingProcessor | クラス | コンソール色分けトレース出力用プロセッサ |
enable_console_tracing | 関数 | コンソールトレーシングを有効化 |
disable_tracing | 関数 | トレーシング機能をすべて無効化 |
OpenAIResponsesModel | クラス | OpenAI用モデルラッパー |
GeminiModel | クラス | Google Gemini用モデルラッパー |
ClaudeModel | クラス | Anthropic Claude用モデルラッパー |
OllamaModel | クラス | Ollama用モデルラッパー |
get_llm¶
-
モデル名・プロバイダー名からLLMインスタンスを返すファクトリ関数
-
引数:
- model (str): モデル名
- provider (str, optional): プロバイダー名(省略時は自動推論)
- temperature (float, optional): サンプリング温度
- api_key (str, optional): プロバイダーAPIキー
- base_url (str, optional): プロバイダーAPIベースURL
- thinking (bool, optional): Claudeモデル思考モード
- tracing (bool, optional): Agents SDK トレーシング有効化
- 戻り値: LLMインスタンス
引数¶
名前 | 型 | 必須/オプション | デフォルト | 説明 |
---|---|---|---|---|
model | str | 必須 | - | 使用するLLMモデル名 |
provider | str (optional) | オプション | None | モデルのプロバイダー名(自動推論可) |
temperature | float (optional) | オプション | 0.3 | サンプリング温度 |
api_key | str (optional) | オプション | None | プロバイダーAPIキー |
base_url | str (optional) | オプション | None | プロバイダーAPIベースURL |
thinking | bool (optional) | オプション | False | Claudeモデルの思考モード |
tracing | bool (optional) | オプション | False | Agents SDKのトレーシングを有効化するか |
戻り値¶
LLMインスタンス
enable_console_tracing¶
- コンソールトレーシング(
ConsoleTracingProcessor
)を有効化します。 - 引数: なし
- 戻り値: なし
disable_tracing¶
- 全てのトレーシング機能(SDKおよびコンソール)を無効化します。
- 引数: なし
- 戻り値: なし
AgentPipeline¶
- 生成・評価・ツール・ガードレールを統合したパイプライン管理クラス
- 主な引数:
- name (str): パイプライン名
- generation_instructions (str): 生成用プロンプト
- evaluation_instructions (str, optional): 評価用プロンプト
- model (str or LLM): 使用するモデル
- evaluation_model (str or LLM, optional): 評価に使用するモデル名またはLLMインスタンス(省略時は
model
を使用) - generation_tools (list, optional): 生成時ツール
- input_guardrails/output_guardrails (list, optional): 入出力ガードレール
- threshold (int): 評価閾値
- retries (int): リトライ回数
- retry_comment_importance (list[str], optional): 重要度指定
- 主なメソッド:
- run(input): 入力に対して生成・評価・自己改善を実行
- 戻り値: 生成・評価結果
引数¶
名前 | 型 | 必須/オプション | デフォルト | 説明 |
---|---|---|---|---|
name | str | 必須 | - | パイプライン名 |
generation_instructions | str | 必須 | - | 生成用システムプロンプト |
evaluation_instructions | str (optional) | オプション | None | 評価用システムプロンプト |
model | str or LLM | オプション | None | 使用するLLMモデル名またはLLMインスタンス |
evaluation_model | str or LLM | オプション | None | 評価に使用するモデル名またはLLMインスタンス(省略時はmodelを使用) |
generation_tools | list (optional) | オプション | [] | 生成時に使用するツールのリスト |
evaluation_tools | list (optional) | オプション | [] | 評価時に使用するツールのリスト |
input_guardrails | list (optional) | オプション | [] | 生成時の入力ガードレールリスト |
output_guardrails | list (optional) | オプション | [] | 評価時の出力ガードレールリスト |
routing_func | Callable (optional) | オプション | None | 出力ルーティング用関数 |
session_history | list (optional) | オプション | [] | セッション履歴 |
history_size | int | オプション | 10 | 履歴保持数 |
threshold | int | オプション | 85 | 評価スコアの閾値 |
retries | int | オプション | 3 | リトライ試行回数 |
improvement_callback | Callable[[Any, EvaluationResult], None] (optional) | オプション | None | 改善提案用コールバック |
dynamic_prompt | Callable[[str], str] (optional) | オプション | None | 動的プロンプト生成関数 |
retry_comment_importance | list[str] (optional) | オプション | [] | リトライ時にプロンプトに含めるコメント重大度 |
戻り値¶
生成・評価結果(
EvaluationResultを含むオブジェクト)
モデルラッパークラス¶
クラス名 | 概要 |
---|---|
OpenAIResponsesModel | OpenAI API用 |
GeminiModel | Google Gemini API用 |
ClaudeModel | Anthropic Claude API用 |
OllamaModel | Ollama API用 |
クラス図(mermaid)¶
classDiagram
class AgentPipeline {
+run(input)
-_build_generation_prompt()
-_build_evaluation_prompt()
}
class OpenAIResponsesModel
class GeminiModel
class ClaudeModel
class OllamaModel
AgentPipeline --> OpenAIResponsesModel
AgentPipeline --> GeminiModel
AgentPipeline --> ClaudeModel
AgentPipeline --> OllamaModel