@@ -254,12 +254,23 @@ async def test_tracks_tool_calls():
254254 """A tool_call event fires for each tool name found in the model response."""
255255 mock_ld_client = MagicMock ()
256256 graph = _make_graph (mock_ld_client , tool_names = ['get_weather' ])
257- fake_response = _make_fake_response ('Calling tool.' , tool_call_names = ['get_weather' ])
258257
259- tool_registry = {'get_weather' : lambda location = 'NYC' : 'sunny' }
258+ # Model returns a tool call on the first invoke, then a final answer.
259+ tool_response = _make_fake_response ('Calling tool.' , tool_call_names = ['get_weather' ])
260+ final_response = _make_fake_response ('It is sunny in NYC.' )
261+
262+ mock_model = MagicMock ()
263+ mock_model .invoke .side_effect = [tool_response , final_response ]
264+ mock_model .bind_tools .return_value = mock_model
265+
266+ def get_weather (location : str = 'NYC' ) -> str :
267+ """Return the current weather for a location."""
268+ return 'sunny'
269+
270+ tool_registry = {'get_weather' : get_weather }
260271
261272 with patch ('ldai_langchain.langgraph_agent_graph_runner.create_langchain_model' ,
262- return_value = _mock_model ( fake_response ) ):
273+ return_value = mock_model ):
263274 runner = LangGraphAgentGraphRunner (graph , tool_registry )
264275 await runner .run ('What is the weather?' )
265276
@@ -274,12 +285,27 @@ async def test_tracks_multiple_tool_calls():
274285 """One tool_call event fires per tool name in the response."""
275286 mock_ld_client = MagicMock ()
276287 graph = _make_graph (mock_ld_client , tool_names = ['search' , 'summarize' ])
277- fake_response = _make_fake_response ('Done.' , tool_call_names = ['search' , 'summarize' ])
278288
279- tool_registry = {'search' : lambda q = '' : q , 'summarize' : lambda text = '' : text }
289+ # Both tools called in one response; second invoke returns a final answer.
290+ tool_response = _make_fake_response ('Done.' , tool_call_names = ['search' , 'summarize' ])
291+ final_response = _make_fake_response ('Here is the summary.' )
292+
293+ mock_model = MagicMock ()
294+ mock_model .invoke .side_effect = [tool_response , final_response ]
295+ mock_model .bind_tools .return_value = mock_model
296+
297+ def search (q : str = '' ) -> str :
298+ """Search for information."""
299+ return q
300+
301+ def summarize (text : str = '' ) -> str :
302+ """Summarize the given text."""
303+ return text
304+
305+ tool_registry = {'search' : search , 'summarize' : summarize }
280306
281307 with patch ('ldai_langchain.langgraph_agent_graph_runner.create_langchain_model' ,
282- return_value = _mock_model ( fake_response ) ):
308+ return_value = mock_model ):
283309 runner = LangGraphAgentGraphRunner (graph , tool_registry )
284310 await runner .run ('Search and summarize.' )
285311
0 commit comments