fix: convert tool_calls to string when no available_functions provided #4037
+225
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4036 - Models with native function calling (like Ollama) fail with
'list' object has no attribute 'rstrip'error.When a model returns
tool_callswithout text content and noavailable_functionsare provided, the code previously returned the rawtool_callslist. This list would then cause an error when passed toformat_message_for_llm()which expects a string.This PR converts tool_calls to a human-readable string representation containing the tool name and arguments, allowing the agent to see what tool the model wanted to call.
Changes:
_handle_non_streaming_responseto convert tool_calls to string_ahandle_non_streaming_responsewith the same fixReview & Testing Checklist for Human
ollama_chat/gpt-oss:20bas mentioned in the issue)Tool: {name}\nArguments: {args}is somewhat arbitrary. Confirm this format works well with the agent's text-based tool parsing, or if a different format (e.g., JSON) would be more appropriateRecommended test plan:
Notes
except Exceptioncatch in the conversion is intentional as a fallback tostr(tool_calls)if the tool_call structure is unexpectedLink to Devin run: https://app.devin.ai/sessions/196112f708ab4589be19e3987b8c584c
Requested by: João ([email protected])