Skip to content

Commit 96886af

Browse files
authored
fix(responses): fix regression in support for mcp tool require_approval argument (#3731)
# What does this PR do? It prevents a tool call message being added to the chat completions message without a corresponding tool call result, which is needed in the case that an approval is required first or if the approval request is denied. In both these cases the tool call messages is popped of the next turn messages. Closes #3728 ## Test Plan Ran the integration tests Manual check of both approval and denial against gpt-4o Signed-off-by: Gordon Sim <[email protected]>
1 parent 5d711d4 commit 96886af

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

llama_stack/providers/inline/agents/meta_reference/responses/openai_responses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ async def _create_streaming_response(
269269
response_tools=tools,
270270
temperature=temperature,
271271
response_format=response_format,
272-
inputs=input,
272+
inputs=all_input,
273273
)
274274

275275
# Create orchestrator and delegate streaming logic

llama_stack/providers/inline/agents/meta_reference/responses/streaming.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ async def create_response(self) -> AsyncIterator[OpenAIResponseObjectStream]:
175175
):
176176
yield stream_event
177177

178+
messages = next_turn_messages
179+
178180
if not function_tool_calls and not non_function_tool_calls:
179181
break
180182

@@ -187,9 +189,7 @@ async def create_response(self) -> AsyncIterator[OpenAIResponseObjectStream]:
187189
logger.info(f"Exiting inference loop since iteration count({n_iter}) exceeds {self.max_infer_iters=}")
188190
break
189191

190-
messages = next_turn_messages
191-
192-
self.final_messages = messages.copy() + [current_response.choices[0].message]
192+
self.final_messages = messages.copy()
193193

194194
# Create final response
195195
final_response = OpenAIResponseObject(
@@ -232,9 +232,11 @@ def _separate_tool_calls(self, current_response, messages) -> tuple[list, list,
232232
non_function_tool_calls.append(tool_call)
233233
else:
234234
logger.info(f"Approval denied for {tool_call.id} on {tool_call.function.name}")
235+
next_turn_messages.pop()
235236
else:
236237
logger.info(f"Requesting approval for {tool_call.id} on {tool_call.function.name}")
237238
approvals.append(tool_call)
239+
next_turn_messages.pop()
238240
else:
239241
non_function_tool_calls.append(tool_call)
240242

0 commit comments

Comments
 (0)