Skip to content

Access to call_id in custom_output_extractor for agent-as-tool pattern #2247

@habema

Description

@habema

Problem

When using the agent-as-tool pattern, custom_output_extractor doesn't have access to the tool call's call_id, making it not possible to associate the nested agent's RunResult (e.g., to_input_list()) back to the original ToolCallItem/ToolCallOutputItem for debugging.

Current flow:

  1. Agent B is defined and has a number of tools. Agent A is defined and uses Agent B as a tool.
  2. Agent A calls Agent B as a tool → creates ToolCallItem with call_id
  3. Agent B runs, calls its own tools, and creates its final output → produces RunResult
  4. custom_output_extractor receives the RunResult object, but it has no association to the original call_id

As a result, the nested RunResult is lost. This way, there is no visibility over what the agent-as-tool is doing under the hood.

Proposed Solution

Pass the call_id through the RunResult's context_wrapper so custom_output_extractor can access it.

This would enable something like this:

async def my_custom_output_extractor(run_result: RunResult) -> str:
    call_id = run_result.context_wrapper.context.tool_call_id  # Currently not available
    my_custom_session.attach_nested_run_result(call_id, run_result.to_input_list())
    return run_result.final_output

Would love to here if there is a better solution, and if there is a temporary workaround for this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions