Repository navigation
Python: fix tools from context providers - #9403
sophia-ramsey wants to merge 9 commits into
Conversation
Code coverage overviewLanguages: Python Python / code-coverage/python
View coverage of the 8 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
There was a problem hiding this comment.
🟡 Changes recommended
Serialization and supported streaming/client paths can still lose or misrepresent tool definitions.
4 open findings
What changed in this PR
Addresses #9160 by capturing run-specific tool definitions for evaluation, including tools supplied by context providers.
Changes:
- Captures schema-only tool snapshots and preserves them through serialization.
- Adds an explicit
tools=evaluation override and loop aggregation support. - Adds regression tests and documents snapshot behavior.
| File | Description |
|---|---|
python/packages/core/tests/core/test_evaluation.py |
Tests tool discovery, overrides, and serialization. |
python/packages/core/AGENTS.md |
Documents evaluation snapshots. |
python/packages/core/agent_framework/_types.py |
Stores and restores tool schemas. |
python/packages/core/agent_framework/_harness/_loop.py |
Aggregates definitions across loop iterations. |
python/packages/core/agent_framework/_evaluation.py |
Uses captured definitions and explicit overrides. |
python/packages/core/agent_framework/_agents.py |
Captures tools during execution. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (2 commit(s)): 813d7c0994f1, 36a84a8608a6
Model: gpt-5.6-sol
Overview
The change captures run-specific tool declarations with deep-copied, JSON-validated schemas, restores them as non-executable tools, and carries them through normal response serialization and loop aggregation. Per-run capture, malformed-metadata validation, explicit overrides, and broad streaming/non-streaming tests are strong guardrails. Three serialization and lifecycle gaps remain: empty snapshots are erased, same-name progressive replacements retain stale schemas, and update-only streaming round trips omit the snapshots.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
3 verified findings remained after source verification (3 medium) across 2 files. Details are attached to the affected lines below.
Affected areas: python/packages/core/agent_framework/_agents.py, python/packages/core/agent_framework/_types.py
36a84a8 to
c1acc93
Compare
c1acc93 to
4fe130f
Compare
4fe130f to
3fef415
Compare
|
sophia-ramsey Two additional evaluation-metadata cases still misrepresent what the model could call:
Both cases reproduced against exact-head capture and evaluation logic. The already-raised continuation-token loss is separate and is not repeated here. |
0fa1ed0 to
80ec512
Compare
|
Updated the PR for snapshots to capture only tools exposed after chat middleware and to check for schema changes so that declarations with the same name but other changes will raise an error. Right now, I have it checking for any input-schema change, which means compatible changes would be rejected too. Can you confirm if this is the behavior we want? Eduard van Valkenburg (@eavanvalkenburg) |

Motivation & Context
The agent evaluation previously omitted tools injected by context providers, causing Foundry tool-selection and tool-input-accuracy evaluators to return null scores because tool definitions were missing. This change captures the tool definitions available during execution and preserves schema-only snapshots across response serialization, so they remain available for evaluation. It supports evaluating agents with dynamically provided tools, both immediately after execution and from saved responses. Tool snapshots are preserved through streaming reconstruction, approval continuations, and loops.
Description & Review Guide
tools=override.tools=was not explicitly required to resolve this issue, but it seemed like it would improve the developer experience. Similarly, responseadditional_propertiesmetadata now containsagent_framework.evaluationwith version and tools (which can include an empty"tools": []).Related Issue
Fixes #9160
AI Assistance
AI assistance details: Used copilot with GPT-6.1 Sol for solution planning, design evaluation, implementation, and testing.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.