feat: multi-tool enhanced passthrough with format:json + content→tool_calls fixup#6
Merged
Merged
Conversation
…_calls fixup When multiple custom tools are present: 1. Inject format:json (native) / response_format:json_object (OpenAI) to force Ollama to produce valid JSON output 2. Post-process response: if model puts tool call JSON in content field instead of tool_calls, parse and convert it to proper tool_calls format This fixes the real-world issue where Ollama returns tool calls as text in the content field instead of structured tool_calls, which breaks frameworks like OpenClaw that expect proper tool_calls objects. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… metadata 1. Multi-tool enhanced passthrough now applies regardless of whether tool results are present. Previously, follow-up requests (role: tool) would skip the fixup and use plain passthrough, so the model's next response could still have JSON-in-content instead of tool_calls. 2. Strip __header_schema from request body before forwarding to Ollama (internal proxy metadata should not leak to the backend). Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 the real-world issue where Ollama returns tool calls as JSON text in
contentinstead of propertool_callsobjects — breaking frameworks like OpenClaw.When >1 custom tools detected:
Injects format constraint before forwarding to Ollama:
/api/chat:format: "json"/v1/chat/completions:response_format: {type: "json_object"}Post-processes response via
tool_call_fixup.py:tool_callsalready present → no-opcontentcontains parseable JSON matching{name, arguments}pattern → moves it intotool_calls, setsfinish_reason: "tool_calls"tools[]from the request{tool_calls: [...]}wrapper, markdown fences, prose-prefixed JSONRouting logic in
main.py:112 tests pass, ruff clean.