Fix Lab 02 (Python): reset input_list per turn and resolve tool calls in conversation - #247
Open
grajdeanserghei wants to merge 1 commit into
Open
Conversation
grajdeanserghei
force-pushed
the
fix-lab02-input-list-reset
branch
from
August 20, 2026 12:20
39f50cc to
131532b
Compare
… in conversation The chat loop created input_list once, before the loop, and never cleared it. After the first turn that called a tool, every later turn re-sent function call outputs that had already been handled, and always fired the follow-up request -- so a turn with no tool call had its answer silently overwritten by a re-summary of the previous turn's tool data. The follow-up request also used previous_response_id without conversation, so the agent's answers after tool calls were never saved to the conversation and the function calls were left unresolved in conversation state. Attaching the outputs to the conversation instead resolves them and stores the answer, and matches the pattern already used in the consolidated A4 lab. - Move the input_list comment inside the chat loop so the list is created per turn - Send function call outputs with conversation= instead of previous_response_id - Drop the duplicate FunctionTool import from the Add references snippet Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
grajdeanserghei
force-pushed
the
fix-lab02-input-list-reset
branch
from
August 20, 2026 12:36
131532b to
60aad5a
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.
Module: 02
Lab/Demo: 02 - Use a custom function in an AI agent (Python)
Fixes #245.
Changes proposed in this pull request:
input_listinside the chat loop instead of once before it. The list was never cleared, so after the first turn that called a tool, every later turn re-sent function call outputs that had already been handled and always fired the follow-up request. On a turn with no tool call,if input_list:was still truthy and the extra response overwrote the real answer — asking the agent something that needs no tool returned a re-summary of the previous turn's tool data instead. The stale outputs were also stored again in the conversation on each turn, duplicating items and growing the request payload every turn. The comment inagent.pymoved inside the loop so the existing "find the comment, add this code" step now lands in the right place.conversation=conversation.idinstead ofprevious_response_id=response.id. Withprevious_response_id, the agent's answer after a tool call was never written to the conversation, and the turn'sfunction_callitems were left with no matching output in conversation state — a later request then fails with400: No tool output found for function call <call_id>. The lab only avoided that error because the unresetinput_listaccidentally back-filled the missing outputs on the next turn, so the two bugs masked each other and both had to be fixed together. This also matches the pattern already used (and explained) inInstructions/Consolidated/A4-add-custom-function-tools.md. Note the two parameters are mutually exclusive — passing both returns400 invalid_payload: "Cannot provide both 'previous_response_id' and 'conversation' in the same request".FunctionToolimport from the Add references snippet — it was imported on its own line and again as part of thePromptAgentDefinition, FunctionToolline.Verification
Ran the completed lab app end-to-end against a live Foundry project (
azure-ai-projects==2.0.0b4,gpt-4.1-mini), using the two prompts from the exercise walkthrough plus a third no-tool prompt.Before the fix, turn 3 ("Just say hello, do not use any tools") returned a re-summary of the turn 1 telescope data instead of a greeting, and the conversation held each turn-1
function_call_outputtwice with only a single assistant message in the whole history.After the fix, all three turns answer correctly, the no-tool turn skips the follow-up request, and the conversation state is a clean per-turn trace with no duplicates:
Note on other labs
Instructions/Exercises/03-mcp-integration.mdandLabfiles/03-mcp-integration/Python/client.pyhave the same two patterns (input_listdeclared before thewhileloop, follow-up sent withprevious_response_id). I've left Lab 03 out of this PR to keep it scoped to the linked issue and to what I verified end-to-end — happy to extend this PR or open a separate one if you'd like that fixed too.