Skip to content

feat: #2228 persist tool origin metadata in run items#2654

Open
seratch wants to merge 2 commits intomainfrom
feat/tool-origin-run-state
Open

feat: #2228 persist tool origin metadata in run items#2654
seratch wants to merge 2 commits intomainfrom
feat/tool-origin-run-state

Conversation

@seratch
Copy link
Member

@seratch seratch commented Mar 12, 2026

This pull request adds ToolOrigin metadata for function-tool-backed run items and preserves it across runtime execution, streaming, and RunState serialization. Resolves #2228

The change introduces a serializable ToolOrigin model in src/agents/tool.py, threads that metadata through tool-call and tool-output item creation in the runtime, and updates RunState schema handling to store and restore the new optional field while keeping older schema versions readable. It also expands exports and MCP/tool helpers where needed so tool-backed items can retain their source information consistently.

Compared with #2242, this version is more durable and less error-prone because it stores only scalar metadata (mcp_server_name, agent_name, agent_tool_name) instead of retaining live MCP server or agent objects. That avoids object pinning and release-time weakref cleanup, makes the metadata safe to round-trip through RunState JSON, and removes identity ambiguity when multiple nested agent tools share the same agent name but have different tool names.

The main behavior change is that tool call/output items can now report whether they came from a plain function tool, MCP-backed function tool, or agent-as-tool path. The serialized state format advances to schema 1.6, but the implementation continues to accept prior released schema versions, so the compatibility risk is limited to consumers that assume the exact emitted snapshot shape rather than using the SDK deserializer.

Co-authored-by: Hassan Abu Alhaj <136383052+habema@users.noreply.github.com>
@seratch seratch modified the milestones: 0.12.x, 0.14.x Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable to access MCP server name via its converted function tool object

1 participant