Skip to content

Commit 60aad5a

Browse files
Fix Lab 02 (Python): reset input_list per turn and resolve tool calls 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>
1 parent d227890 commit 60aad5a

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

Instructions/Exercises/02-agent-custom-tools.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ Now you're ready to create an AI agent that uses MCP server tools to access exte
153153
```python
154154
# Add references
155155
from azure.ai.projects import AIProjectClient
156-
from azure.ai.projects.models import FunctionTool
157156
from azure.identity import DefaultAzureCredential
158157
from azure.ai.projects.models import PromptAgentDefinition, FunctionTool
159158
from openai.types.responses.response_input_param import FunctionCallOutput, ResponseInputParam
@@ -312,6 +311,8 @@ Now that you've created the agent with the function tools, you can send messages
312311
input_list: ResponseInputParam = []
313312
```
314313
314+
This list is created inside the chat loop so that each turn starts with a fresh set of function call outputs.
315+
315316
1. Find the comment **Send a prompt to the agent** and add the following code:
316317
317318
```python
@@ -375,8 +376,8 @@ Now that you've created the agent with the function tools, you can send messages
375376
# Send function call outputs back to the model and retrieve a response
376377
if input_list:
377378
response = openai_client.responses.create(
379+
conversation=conversation.id,
378380
input=input_list,
379-
previous_response_id=response.id,
380381
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
381382
)
382383
# Display the agent's response
@@ -385,6 +386,8 @@ Now that you've created the agent with the function tools, you can send messages
385386
386387
This code checks if there are any function call outputs in the input list, and if so, it sends them back to the agent as input to retrieve an updated response. Finally, it prints the agent's response.
387388
389+
Note that the outputs are attached to the same **conversation**, so the function calls are resolved in conversation state and the agent's answer is saved to the chat history. Sending them back with `previous_response_id` instead would make the *next* message fail with *"No tool output found for function call"*.
390+
388391
1. Find the comment **Delete the agent when done** and add the following code:
389392
390393
```python

Labfiles/02-agent-custom-tools/Python/agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ def main():
3232
# Create a thread for the chat session
3333

3434

35-
# Create a list to hold function call outputs that will be sent back as input to the agent
36-
37-
3835
while True:
3936
user_input = input("Enter a prompt for the astronomy agent. Use 'quit' to exit.\nUSER: ").strip()
4037
if user_input.lower() == "quit":
4138
print("Exiting chat.")
4239
break
4340

41+
# Create a list to hold function call outputs that will be sent back as input to the agent
42+
43+
4444
# Send a prompt to the agent
4545

4646

0 commit comments

Comments
 (0)