Items
TResponseInputItem 模块属性
OpenAI SDK 中的 ResponseInputItemParam 类型的别名。
TResponseOutputItem 模块属性
OpenAI SDK 中的 ResponseOutputItem 类型的别名。
TResponseStreamEvent 模块属性
OpenAI SDK 中的 ResponseStreamEvent 类型的别名。
ToolCallItemTypes 模块属性
ToolCallItemTypes: TypeAlias = Union[
ResponseFunctionToolCall,
ResponseComputerToolCall,
ResponseFileSearchToolCall,
ResponseFunctionWebSearch,
McpCall,
ResponseCodeInterpreterToolCall,
ImageGenerationCall,
LocalShellCall,
dict[str, Any],
]
表示工具调用项的类型。
RunItem 模块属性
RunItem: TypeAlias = Union[
MessageOutputItem,
HandoffCallItem,
HandoffOutputItem,
ToolCallItem,
ToolCallOutputItem,
ReasoningItem,
MCPListToolsItem,
MCPApprovalRequestItem,
MCPApprovalResponseItem,
CompactionItem,
]
代理生成的项目。
RunItemBase dataclass
基础: Generic[T], ABC
源代码在 src/agents/items.py
raw_item 实例属性
运行中的原始 Responses 项目。 这始终是输出项目(即 openai.types.responses.ResponseOutputItem)或输入项目(即 openai.types.responses.ResponseInputItemParam)。
release_agent
释放对代理的强引用,同时保留弱引用。
源代码在 src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
将此项目转换为适合传递给模型的输入项目。
源代码在 src/agents/items.py
MessageOutputItem dataclass
基础: RunItemBase[ResponseOutputMessage]
表示来自 LLM 的消息。
源代码在 src/agents/items.py
release_agent
释放对代理的强引用,同时保留弱引用。
源代码在 src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
将此项目转换为适合传递给模型的输入项目。
源代码在 src/agents/items.py
HandoffCallItem dataclass
基础: RunItemBase[ResponseFunctionToolCall]
表示从一个代理到另一个代理的交接的工具调用。
源代码在 src/agents/items.py
release_agent
释放对代理的强引用,同时保留弱引用。
源代码在 src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
将此项目转换为适合传递给模型的输入项目。
源代码在 src/agents/items.py
HandoffOutputItem dataclass
基础: RunItemBase[TResponseInputItem]
表示交接的输出。
源代码在 src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
将此项目转换为适合传递给模型的输入项目。
源代码在 src/agents/items.py
ToolCallItem dataclass
基础: RunItemBase[Any]
表示工具调用,例如函数调用或计算机操作调用。
源代码在 src/agents/items.py
release_agent
释放对代理的强引用,同时保留弱引用。
源代码在 src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
将此项目转换为适合传递给模型的输入项目。
源代码在 src/agents/items.py
ToolCallOutputItem dataclass
基础: RunItemBase[Any]
表示工具调用的输出。
源代码在 src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
将工具输出转换为下一个模型轮次的输入项目。
托管工具输出(例如 shell/apply_patch)带有 SDK 的记录保留的 status 字段,但 Responses API 尚未接受该参数。 在将内容发送回模型时,将其从有效负载中删除,同时保留原始 raw_item 不变。
源代码在 src/agents/items.py
release_agent
释放对代理的强引用,同时保留弱引用。
源代码在 src/agents/items.py
ReasoningItem dataclass
基础: RunItemBase[ResponseReasoningItem]
表示推理项目。
源代码在 src/agents/items.py
release_agent
释放对代理的强引用,同时保留弱引用。
源代码在 src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
将此项目转换为适合传递给模型的输入项目。
源代码在 src/agents/items.py
MCPListToolsItem dataclass
基础: RunItemBase[McpListTools]
表示调用 MCP 服务器以列出工具。
源代码在 src/agents/items.py
release_agent
释放对代理的强引用,同时保留弱引用。
源代码在 src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
将此项目转换为适合传递给模型的输入项目。
源代码在 src/agents/items.py
MCPApprovalRequestItem dataclass
基础: RunItemBase[McpApprovalRequest]
表示请求 MCP 批准。
源代码在 src/agents/items.py
release_agent
释放对代理的强引用,同时保留弱引用。
源代码在 src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
将此项目转换为适合传递给模型的输入项目。
源代码在 src/agents/items.py
MCPApprovalResponseItem dataclass
基础: RunItemBase[McpApprovalResponse]
表示对 MCP 批准请求的响应。
源代码在 src/agents/items.py
release_agent
释放对代理的强引用,同时保留弱引用。
源代码在 src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
将此项目转换为适合传递给模型的输入项目。
源代码在 src/agents/items.py
CompactionItem dataclass
基础: RunItemBase[TResponseInputItem]
表示来自 responses.compact 的压缩项目。
源代码在 src/agents/items.py
raw_item 实例属性
运行中的原始 Responses 项目。 这始终是输出项目(即 openai.types.responses.ResponseOutputItem)或输入项目(即 openai.types.responses.ResponseInputItemParam)。
to_input_item
to_input_item() -> TResponseInputItem
release_agent
释放对代理的强引用,同时保留弱引用。
源代码在 src/agents/items.py
ModelResponse
源代码在 src/agents/items.py
response_id 实例属性
可用于在后续调用模型中引用响应的 ID。 并非所有模型提供程序都支持。 如果使用 Responses API 中的 OpenAI 模型,这是 response_id 参数,可以传递给 Runner.run。
to_input_items
to_input_items() -> list[TResponseInputItem]
将输出转换为适合传递给模型的输入项目列表。
源代码在 src/agents/items.py
ItemHelpers
源代码在 src/agents/items.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | |
extract_last_content 类方法
extract_last_content(message: TResponseOutputItem) -> str
从消息中提取最后一个文本内容或拒绝。
源代码在 src/agents/items.py
extract_last_text 类方法
extract_last_text(
message: TResponseOutputItem,
) -> str | None
从消息中提取最后一个文本内容(如果有)。 忽略拒绝。
源代码在 src/agents/items.py
input_to_new_input_list 类方法
input_to_new_input_list(
input: str | list[TResponseInputItem],
) -> list[TResponseInputItem]
将字符串或输入项目列表转换为输入项目列表。
源代码在 src/agents/items.py
text_message_outputs 类方法
text_message_outputs(items: list[RunItem]) -> str
连接消息输出项目列表中所有文本内容。
源代码在 src/agents/items.py
text_message_output 类方法
text_message_output(message: MessageOutputItem) -> str
从单个消息输出项目中提取所有文本内容。
源代码在 src/agents/items.py
tool_call_output_item 类方法
从工具调用及其输出创建工具调用输出项目。
接受纯值(字符串化)或使用 input_text/input_image/input_file 形状的结构化输出。 结构化输出可以作为 Pydantic 模型或字典提供,也可以是这些项目的可迭代对象。