How to pass runtime context (auth tokens, session data) to sub-agent tools in hierarchical delegation? #2251
-
ContextI'm using hierarchical agent delegation with Example Scenario@ai_function
async def send_email(to: str, subject: str, body: str) -> str:
"""Send email using authenticated API."""
# How do I access the API token here?
# The token is available at the parent agent level but not hardcoded
...
email_agent = client.create_agent(
name="email_sender",
tools=[send_email]
)
coordinator = client.create_agent(
name="coordinator",
tools=[email_agent.as_tool()]
)
# Parent receives API token from middleware/session
await coordinator.run(
"Send a welcome email to [email protected]",
api_token="secret-xyz-123" # How to make this available to send_email tool?
)Questions
Use CaseThis is needed for:
Any guidance on the correct architectural pattern would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hi @hayato-kishikawa, thanks for the questions. I've created an issue (see: #2290) from this as we should be passing kwargs through to as_tool(). Additionally, this can be done via middleware. I will add a sample showing both. Please check for updates on #2290. Thanks. |
Beta Was this translation helpful? Give feedback.
Hi @hayato-kishikawa, thanks for the questions. I've created an issue (see: #2290) from this as we should be passing kwargs through to as_tool(). Additionally, this can be done via middleware. I will add a sample showing both. Please check for updates on #2290. Thanks.