Sandbox
SandboxAgent
dataclass
Bases: Agent[TContext]
An Agent with sandbox-specific configuration.
Runtime transport details such as the sandbox client, client options, and live session are
provided at run time through RunConfig(sandbox=...), not stored on the agent itself.
ソースコード位置: src/agents/sandbox/sandbox_agent.py
handoff_description
class-attribute
instance-attribute
A description of the agent. This is used when the agent is used as a handoff, so that an LLM knows what it does and when to invoke it.
tools
class-attribute
instance-attribute
tools: list[Tool] = field(default_factory=list)
A list of tools that the agent can use.
mcp_servers
class-attribute
instance-attribute
mcp_servers: list[MCPServer] = field(default_factory=list)
A list of Model Context Protocol servers that the agent can use. Every time the agent runs, it will include tools from these servers in the list of available tools.
NOTE: You are expected to manage the lifecycle of these servers. Specifically, you must call
server.connect() before passing it to the agent, and server.cleanup() when the server is no
longer needed. Consider using MCPServerManager from agents.mcp to keep connect/cleanup
in the same task.
mcp_config
class-attribute
instance-attribute
Configuration for MCP servers.
instructions
class-attribute
instance-attribute
instructions: (
str
| Callable[
[RunContextWrapper[TContext], Agent[TContext]],
MaybeAwaitable[str],
]
| None
) = None
The instructions for the agent. Will be used as the "system prompt" when this agent is invoked. Describes what the agent should do, and how it responds.
Can either be a string, or a function that dynamically generates instructions for the agent. If you provide a function, it will be called with the context and the agent instance. It must return a string.
prompt
class-attribute
instance-attribute
prompt: Prompt | DynamicPromptFunction | None = None
A prompt object (or a function that returns a Prompt). Prompts allow you to dynamically configure the instructions, tools and other config for an agent outside of your code. Only usable with OpenAI models, using the Responses API.
handoffs
class-attribute
instance-attribute
Handoffs are sub-agents that the agent can delegate to. You can provide a list of handoffs, and the agent can choose to delegate to them if relevant. Allows for separation of concerns and modularity.
model
class-attribute
instance-attribute
model: str | Model | None = None
The model implementation to use when invoking the LLM.
By default, if not set, the agent will use the default model configured in
agents.models.get_default_model() (currently "gpt-4.1").
model_settings
class-attribute
instance-attribute
model_settings: ModelSettings = field(
default_factory=get_default_model_settings
)
Configures model-specific tuning parameters (e.g. temperature, top_p).
input_guardrails
class-attribute
instance-attribute
input_guardrails: list[InputGuardrail[TContext]] = field(
default_factory=list
)
A list of checks that run in parallel to the agent's execution, before generating a response. Runs only if the agent is the first agent in the chain.
output_guardrails
class-attribute
instance-attribute
output_guardrails: list[OutputGuardrail[TContext]] = field(
default_factory=list
)
A list of checks that run on the final output of the agent, after generating a response. Runs only if the agent produces a final output.
output_type
class-attribute
instance-attribute
output_type: type[Any] | AgentOutputSchemaBase | None = None
The type of the output object. If not provided, the output will be str. In most cases,
you should pass a regular Python type (e.g. a dataclass, Pydantic model, TypedDict, etc).
You can customize this in two ways:
1. If you want non-strict schemas, pass AgentOutputSchema(MyClass, strict_json_schema=False).
2. If you want to use a custom JSON schema (i.e. without using the SDK's automatic schema)
creation, subclass and pass an AgentOutputSchemaBase subclass.
hooks
class-attribute
instance-attribute
hooks: AgentHooks[TContext] | None = None
A class that receives callbacks on various lifecycle events for this agent.
tool_use_behavior
class-attribute
instance-attribute
tool_use_behavior: (
Literal["run_llm_again", "stop_on_first_tool"]
| StopAtTools
| ToolsToFinalOutputFunction
) = "run_llm_again"
This lets you configure how tool use is handled.
- "run_llm_again": The default behavior. Tools are run, and then the LLM receives the results
and gets to respond.
- "stop_on_first_tool": The output from the first tool call is treated as the final result.
In other words, it isn’t sent back to the LLM for further processing but is used directly
as the final output.
- A StopAtTools object: The agent will stop running if any of the tools listed in
stop_at_tool_names is called.
The final output will be the output of the first matching tool call.
The LLM does not process the result of the tool call.
- A function: If you pass a function, it will be called with the run context and the list of
tool results. It must return a ToolsToFinalOutputResult, which determines whether the tool
calls result in a final output.
NOTE: This configuration is specific to FunctionTools. Hosted tools, such as file search, web search, etc. are always processed by the LLM.
reset_tool_choice
class-attribute
instance-attribute
Whether to reset the tool choice to the default value after a tool has been called. Defaults to True. This ensures that the agent doesn't enter an infinite loop of tool usage.
default_manifest
class-attribute
instance-attribute
default_manifest: Manifest | None = None
Default sandbox manifest for new sessions created by Runner sandbox execution.
base_instructions
class-attribute
instance-attribute
base_instructions: (
str
| Callable[
[RunContextWrapper[TContext], Agent[TContext]],
Awaitable[str | None] | str | None,
]
| None
) = None
Override for the SDK sandbox base prompt. Most callers should use instructions.
capabilities
class-attribute
instance-attribute
capabilities: Sequence[Capability] = field(
default_factory=default
)
Sandbox capabilities that can mutate the manifest, add instructions, and expose tools.
run_as
class-attribute
instance-attribute
run_as: User | str | None = None
User identity used for model-facing sandbox tools such as shell, file reads, and patches.
get_mcp_tools
async
get_mcp_tools(
run_context: RunContextWrapper[TContext],
) -> list[Tool]
Fetches the available tools from the MCP servers.
ソースコード位置: src/agents/agent.py
get_all_tools
async
get_all_tools(
run_context: RunContextWrapper[TContext],
) -> list[Tool]
All agent tools, including MCP tools and function tools.
ソースコード位置: src/agents/agent.py
clone
clone(**kwargs: Any) -> Agent[TContext]
Make a copy of the agent, with the given arguments changed.
Notes:
- Uses dataclasses.replace, which performs a shallow copy.
- Mutable attributes like tools and handoffs are shallow-copied:
new list objects are created only if overridden, but their contents
(tool functions and handoff objects) are shared with the original.
- To modify these independently, pass new lists when calling clone().
Example:
ソースコード位置: src/agents/agent.py
as_tool
as_tool(
tool_name: str | None,
tool_description: str | None,
custom_output_extractor: Callable[
[RunResult | RunResultStreaming], Awaitable[str]
]
| None = None,
is_enabled: bool
| Callable[
[RunContextWrapper[Any], AgentBase[Any]],
MaybeAwaitable[bool],
] = True,
on_stream: Callable[
[AgentToolStreamEvent], MaybeAwaitable[None]
]
| None = None,
run_config: RunConfig | None = None,
max_turns: int | None = None,
hooks: RunHooks[TContext] | None = None,
previous_response_id: str | None = None,
conversation_id: str | None = None,
session: Session | None = None,
failure_error_function: ToolErrorFunction
| None = default_tool_error_function,
needs_approval: bool
| Callable[
[RunContextWrapper[Any], dict[str, Any], str],
Awaitable[bool],
] = False,
parameters: type[Any] | None = None,
input_builder: StructuredToolInputBuilder | None = None,
include_input_schema: bool = False,
) -> FunctionTool
Transform this agent into a tool, callable by other agents.
This is different from handoffs in two ways: 1. In handoffs, the new agent receives the conversation history. In this tool, the new agent receives generated input. 2. In handoffs, the new agent takes over the conversation. In this tool, the new agent is called as a tool, and the conversation is continued by the original agent.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
tool_name
|
str | None
|
The name of the tool. If not provided, the agent's name will be used. |
必須 |
tool_description
|
str | None
|
The description of the tool, which should indicate what it does and when to use it. |
必須 |
custom_output_extractor
|
Callable[[RunResult | RunResultStreaming], Awaitable[str]] | None
|
A function that extracts the output from the agent. If not
provided, the last message from the agent will be used. Nested run results expose
|
None
|
is_enabled
|
bool | Callable[[RunContextWrapper[Any], AgentBase[Any]], MaybeAwaitable[bool]]
|
Whether the tool is enabled. Can be a bool or a callable that takes the run context and agent and returns whether the tool is enabled. Disabled tools are hidden from the LLM at runtime. |
True
|
on_stream
|
Callable[[AgentToolStreamEvent], MaybeAwaitable[None]] | None
|
Optional callback (sync or async) to receive streaming events from the nested
agent run. The callback receives an |
None
|
failure_error_function
|
ToolErrorFunction | None
|
If provided, generate an error message when the tool (agent) run fails. The message is sent to the LLM. If None, the exception is raised instead. |
default_tool_error_function
|
needs_approval
|
bool | Callable[[RunContextWrapper[Any], dict[str, Any], str], Awaitable[bool]]
|
Bool or callable to decide if this agent tool should pause for approval. |
False
|
parameters
|
type[Any] | None
|
Structured input type for the tool arguments (dataclass or Pydantic model). |
None
|
input_builder
|
StructuredToolInputBuilder | None
|
Optional function to build the nested agent input from structured data. |
None
|
include_input_schema
|
bool
|
Whether to include the full JSON schema in structured input. |
False
|
ソースコード位置: src/agents/agent.py
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 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | |
get_prompt
async
get_prompt(
run_context: RunContextWrapper[TContext],
) -> ResponsePromptParam | None
Get the prompt for the agent.
ソースコード位置: src/agents/agent.py
Manifest
Bases: BaseModel
ソースコード位置: src/agents/sandbox/manifest.py
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 | |
describe
print a nice fs representation of things inside root with inline descriptions depth controls how deep the tree is rendered; None renders all levels eg:
/workspace (root) ├── repo/ # /workspace/repo — my repo │ └── README.md # /workspace/repo/README.md ├── data/ # /workspace/data │ └── config.json # /workspace/data/config.json — config ├── mount-data/ # /workspace/mount-data (mount) └── notes.txt # /workspace/notes.txt ...
ソースコード位置: src/agents/sandbox/manifest.py
SandboxRunConfig
dataclass
Grouped sandbox runtime configuration for Runner.
ソースコード位置: src/agents/run_config.py
client
class-attribute
instance-attribute
client: BaseSandboxClient[Any] | None = None
Sandbox client used to create or resume sandbox sessions.
options
class-attribute
instance-attribute
Sandbox-client-specific options used when creating a fresh session.
session
class-attribute
instance-attribute
session: BaseSandboxSession | None = None
Live sandbox session override for the current process.
session_state
class-attribute
instance-attribute
session_state: SandboxSessionState | None = None
Explicit sandbox session state to resume from when not using RunState payloads.
manifest
class-attribute
instance-attribute
manifest: Manifest | None = None
Optional sandbox manifest override for fresh session creation.
snapshot
class-attribute
instance-attribute
snapshot: SnapshotSpec | SnapshotBase | None = None
Optional sandbox snapshot used for fresh session creation.
concurrency_limits
class-attribute
instance-attribute
concurrency_limits: SandboxConcurrencyLimits = field(
default_factory=SandboxConcurrencyLimits
)
Concurrency limits for sandbox materialization work.
Capability
Bases: BaseModel
ソースコード位置: src/agents/sandbox/capabilities/capability.py
clone
clone() -> Capability
Return a per-run copy of this capability.
ソースコード位置: src/agents/sandbox/capabilities/capability.py
bind
bind(session: BaseSandboxSession) -> None
bind_run_as
bind_run_as(user: User | None) -> None
required_capability_types
instructions
async
instructions(manifest: Manifest) -> str | None
Return a deterministic instruction fragment appended during run preparation.
sampling_params
Return additional model request parameters needed for this capability.
process_context
process_context(
context: list[TResponseInputItem],
) -> list[TResponseInputItem]