---
type: email
from: Yankuba Kuyateh <notifications@github.com>
subject: [openai/openai-agents-python] bound_context for deep sub-agents (PR

 #1719)
received: 2026-03-06 07:29:01
date_header: Thu, 11 Sep 2025 13:33:59 -0700
priority: normal
status: awaiting_approval
uid: 30163
---

## Email Content

**From:** Yankuba Kuyateh <notifications@github.com>
**Subject:** [openai/openai-agents-python] bound_context for deep sub-agents (PR

 #1719)
**Date:** Thu, 11 Sep 2025 13:33:59 -0700

### Body (preview)

This change introduces a new optional `bound_context` parameter to `Agent.as_tool` so callers can pass a Pydantic `BaseModel` instance that will be used as the run context for that tool invocation. When provided, the bound context overrides the parent agent&#39;s context for the duration of the tool call; when omitted, existing behaviour (inheriting the caller&#39;s context) is preserved.



### Why

- Enables safe, explicit context binding for sub-agent tools in orchestrations (e.g., orchestrator → multiple specialized agents).

- Prevents context leakage between parallel or sequential sub-agent invocations and makes it easy to pass typed metadata (email, agent_name, profile data) to sub-agents.

- Solves real-world need in the trading orchestrator example where each agent must receive its own `TradeAgentContext` (email/name) to correctly save trade signals.



### What changed

- `src/agents/agent.py`

  - Added parameter: `bound_context: BaseModel | None = None` to `Agent.as_tool(...)`.

  - `run_agent` now calls `Runner.run(..., context=bound_context or context.context)` so the provided `bound_context` is used when present; otherwise the original behavior is retained.

  - Docstring for `bound_context` describing its behavior and that it should be a Pydantic `BaseModel`.



This is a backward-compatible change: default is `None`, so existing uses of `as_tool` are unaffected.



### Example usage

```python

# create a typed context for the sub-agent

sub_agent_context = TradeAgentContext(agent_email=&quot;alice@example.com&quot;, agent_name=&quot;Alice&quot;)



# create a tool from an agent that will use the bound context

agent_tool = agent.as_tool(

    tool_name=&quot;alice_agent_tool&quot;,

    tool_description=&quot;Run Alice&#39;s agent for a ticker&quot;,

    bound_context=sub_agent_context,

)

```



You can view, comment on, or merge this pull request online at:



  https://github.com/openai/openai-agents-python/pull/1719



-- Commit Summary --

---

## Suggested Actions
- [ ] Reply
- [ ] Archive
- [ ] Escalate
