File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
nemoguardrails/actions/llm Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -317,10 +317,26 @@ def _extract_and_remove_think_tags(response) -> Optional[str]:
317317
318318def _store_tool_calls (response ) -> None :
319319 """Extract and store tool calls from response in context."""
320- tool_calls = getattr (response , "tool_calls" , None )
320+ tool_calls = _extract_tool_calls_from_content_blocks (response )
321+ if not tool_calls :
322+ tool_calls = _extract_tool_calls_from_attribute (response )
321323 tool_calls_var .set (tool_calls )
322324
323325
326+ def _extract_tool_calls_from_content_blocks (response ) -> List | None :
327+ if hasattr (response , "content_blocks" ):
328+ tool_calls = []
329+ for block in response .content_blocks :
330+ if block .get ("type" ) == "tool_call" :
331+ tool_calls .append (block )
332+ return tool_calls if tool_calls else None
333+ return None
334+
335+
336+ def _extract_tool_calls_from_attribute (response ) -> List | None :
337+ return getattr (response , "tool_calls" , None )
338+
339+
324340def _store_response_metadata (response ) -> None :
325341 """Store response metadata excluding content for metadata preservation.
326342
You can’t perform that action at this time.
0 commit comments