Skip to content

Context variable passed down to my tool is not working properly. #1841

@division-sama

Description

@division-sama

Description

When invoking my tool, it is called twice with different versions of the context variable:

ToolContext -> RunContextWrapper -> Context (dict I passed)
ToolContext -> Context (dict I passed)

On the first call (with RunContextWrapper), the agent’s response is ignored (By ignored I mean the tool returns an answer but the agent calls it again).
On the second call (with the plain Context dict), the agent’s response is accepted and returned to the user.

This leads to redundant tool executions and inconsistent behavior.

Debug information

  • Agents SDK version: (e.g. v0.3.3)
  • Python version (e.g. Python 3.11)

Repro steps

Ideally provide a minimal python script that can be run to reproduce the bug.

run_context = {
    "available_agents": available_agents,
    "conversation_id": user_identity.platform_user_id,
    "conversation_manager": conversation_manager,
}

run_result = await agent_runner.run(
    initial_agent_instance,
    input=history_str,
    context=run_context,
)

@function_tool
async def tool_one(
    ctx: ToolContext,
    **kwargs
) -> dict:
    ...

Expected behavior

The tool should only be called once, with a consistent context structure.
The agent response from the first invocation should not be discarded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions