fix(eval): implement function-call loop so agent can use tools#4
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the real evaluation path so deployed Foundry agents that emit Responses API function calls can execute local tools before evaluator scoring.
Changes:
- Adds a local function-tool registry and executor for the calculator tool.
- Replaces single-shot agent queries with a function-call loop using
function_call_output. - Adds diagnostic logging and stores tool-call traces when answers remain empty.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The deployed agent has a custom `function` tool (calculator). When the Responses API hits a function tool, it returns `function_call` output items and waits for the CLIENT to execute the tool and submit results via `function_call_output` items. The previous eval script never did this, so `response.output_text` was empty for any tool-using question, which crashed `GroundednessEvaluator` with `Response string cannot be empty`. Adds: - `_build_function_tool_registry()` — name -> local executor map - `_execute_function_tool()` — JSON args in, JSON output out - `_query_agent_with_tool_loop()` — drives the Responses tool loop using `previous_response_id` chaining, capped at 5 iterations - Diagnostic log when an answer is still empty after the loop Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3f7908c to
f51d8b6
Compare
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.
Problem
The CD pipeline fails at the
Evaluate Agent (DEV)step with:Root cause
The deployed agent has a custom
functiontool (calculator). When the Foundry Responses API hits a function tool, it returnsfunction_calloutput items and waits for the client to execute the tool locally and submit results back viafunction_call_outputitems. Until that happens,response.output_textis empty.The previous code did a single
responses.create()and readoutput_textdirectly — so every math question ineval_dataset.jsonlcame back with an empty answer, and the first call intoGroundednessEvaluatorcrashed the whole pipeline.Fix
Implement the function-call loop in
_query_agent_with_tool_loop():responses.create()withagent_referencefunction_callitems:_execute_function_tool()(looks up the name in a registry → callsagent.tools.<name>.execute_<name>)function_call_outputitems, chained withprevious_response_idAlso added a diagnostic log when an answer is still empty after the loop completes (prints the tool-call trace), so the next failure of this kind is actually debuggable.
Files
src/scripts/run_evaluation.py(+103 / -13)Verification
python -m py_compile src/scripts/run_evaluation.pypassesmainafter merge and exercise the tool loop against the deployedcalculatortoolOut of scope
src/scripts/test_agent.pyhas the same gap but is a smoke test, not a CI gate — leaving it for a follow-up if you wantCo-authored-by: Copilot 223556219+Copilot@users.noreply.github.com