File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -5807,3 +5807,29 @@ def test_agent_builtin_tools_runtime_vs_agent_level():
58075807 MCPServerTool (id = 'example' , url = 'https://mcp.example.com/mcp' ),
58085808 ]
58095809 )
5810+
5811+
5812+ async def test_run_with_unapproved_tool_call_in_history ():
5813+ def should_not_call_model (_messages : list [ModelMessage ], _info : AgentInfo ) -> ModelResponse :
5814+ raise ValueError ('The agent should not call the model.' ) # pragma: no cover
5815+
5816+ agent = Agent (
5817+ model = FunctionModel (function = should_not_call_model ),
5818+ output_type = [str , DeferredToolRequests ],
5819+ )
5820+
5821+ @agent .tool_plain (requires_approval = True )
5822+ def delete_file () -> None :
5823+ print ('File deleted.' ) # pragma: no cover
5824+
5825+ messages = [
5826+ ModelRequest (parts = [UserPromptPart (content = 'Hello' )]),
5827+ ModelResponse (parts = [ToolCallPart (tool_name = 'delete_file' )]),
5828+ ]
5829+
5830+ result = await agent .run (message_history = messages )
5831+
5832+ assert result .all_messages () == messages
5833+ assert result .output == snapshot (
5834+ DeferredToolRequests (approvals = [ToolCallPart (tool_name = 'delete_file' , tool_call_id = IsStr ())])
5835+ )
You can’t perform that action at this time.
0 commit comments