feat(server): OpenAI tools pass-through (/v1/chat/completions)#64
Merged
Conversation
Server half of tool-calling (wave 1 shipped engine detection; the GUI agent loop is separate). The server does NOT run an agent loop — it passes tools into the template and returns detected tool_calls; external clients (Zed/Cursor/etc.) run their own loop. - ChatCompletionRequest gains tools:[JSONValue]? + tool_choice:JSONValue? (decodeIfPresent — back-compat). tools forwarded verbatim into GenerateRequest.tools (template + engine consume the OpenAI function-spec shape directly). tool_choice "none" suppresses tools; anything else offers them (fine-grained forcing deferred, documented). - Non-streaming: terminal chunk's toolCalls → message.tool_calls in exact OpenAI shape (id/type:function/function.name + arguments as a JSON-encoded STRING); content=null when tool-calls-only; finish_reason:tool_calls. - Streaming: buffered-text delta → delta.tool_calls (complete-in-one-delta with index) → final finish_reason:tool_calls frame; non-tool path byte-identical; [DONE] still emitted. - Anthropic/Ollama pass-through + fine-grained tool_choice = follow-ups. Reviewed APPROVE (all 6 wire behaviors correct, back-compat preserved, no scope creep, no force-unwrap). 5 new tests; 241 MacMLXCore tests green under xcodebuild + bare swift test; CLI builds.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
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.
The server half of tool-calling — completes the story alongside the just-merged GUI agent loop (#63). The server does NOT run an agent loop: it passes OpenAI
toolsinto the chat template and returns detectedtool_callsin OpenAI shape; external clients (Zed, Cursor, the OpenAI SDK) run their own loop.What lands (
HummingbirdServer.swiftonly)ChatCompletionRequestgainstools+tool_choice(decodeIfPresent, back-compat).toolsforwarded verbatim intoGenerateRequest.tools;tool_choice:"none"suppresses, anything else offers (fine-grained forcing deferred).message.tool_callsin exact OpenAI shape —argumentsas a JSON-encoded string (the Chat inference aborts when switching sidebar tabs #1 thing clients choke on, done right + tested),content:nullwhen tool-calls-only,finish_reason:"tool_calls".delta.tool_calls(complete-in-one-delta withindex) → finalfinish_reason:"tool_calls"frame; non-tool path byte-identical;[DONE]preserved.tool_choice= documented follow-ups.Review + verification
Adversarially reviewed APPROVE — all 6 wire behaviors (serialization shape,
content:null, streaming frames,tool_choice, back-compat, interaction with reasoning/watchdog/lock) confirmed correct against the OpenAI contract; back-compat preserved on three axes; no scope creep; no force-unwrap. 5 non-tautological tests. Independently verified green (merged with wave-2 core):** TEST SUCCEEDED **, 244 tests, bareswift testclean, CLI builds.