feat(python): expose agent run trace#1705
Open
RitwijParmar wants to merge 2 commits into
Open
Conversation
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.
Why
This addresses part of the long-running request in #262 around seeing which MCP tools were actually called, how many times, and what each tool returned before the model turns those results into a final answer.
Right now users can watch stream updates, but after a run there is no simple object they can hand to a dashboard, debugger, or notebook. That makes it harder to answer questions like: did the model call the same tool twice, did the tool return the expected raw payload, or did the final answer rewrite a tool result in a misleading way?
What changed
AgentRunTraceandToolCallRecordfor the Python agentagent.get_last_run_trace(),agent.get_last_tool_calls(), andagent.get_last_tool_outputs()agent.run(...)oragent.stream(...)I kept this as an inspectable in-memory trace instead of changing the streaming contract, so existing callers should not see behavior changes.
Checks
uv run --extra dev pytest tests/unit/test_agent.py -quv run --extra dev ruff check mcp_use/agents/__init__.py mcp_use/agents/run_trace.py mcp_use/agents/mcpagent.py tests/unit/test_agent.pyuv run --extra dev ruff format --check mcp_use/agents/__init__.py mcp_use/agents/run_trace.py mcp_use/agents/mcpagent.py tests/unit/test_agent.pyuv run --extra dev python -m py_compile mcp_use/agents/__init__.py mcp_use/agents/run_trace.py mcp_use/agents/mcpagent.py tests/unit/test_agent.py