feat: #2228 persist tool origin metadata in run items#2654
Open
feat: #2228 persist tool origin metadata in run items#2654
Conversation
Co-authored-by: Hassan Abu Alhaj <136383052+habema@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds
ToolOriginmetadata for function-tool-backed run items and preserves it across runtime execution, streaming, andRunStateserialization. Resolves #2228The change introduces a serializable
ToolOriginmodel insrc/agents/tool.py, threads that metadata through tool-call and tool-output item creation in the runtime, and updatesRunStateschema 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 throughRunStateJSON, 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.