Add tool-calling support with emulation for providers without native tool calling#2
Add tool-calling support with emulation for providers without native tool calling#2neuwcodebox wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7fe19f3644
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| content: { | ||
| type: ['string', 'array'], | ||
| minLength: 1, | ||
| minItems: 1, |
There was a problem hiding this comment.
Accept null assistant content when tool_calls are present
The assistant-message schema currently forces content to be a non-empty string/array, but this same change emits content: null when a tool call is detected (applyToolEmulationResponse). In a normal tool-calling loop, clients replay that assistant tool-call message on the next request; with this schema branch, the follow-up request is rejected with 400 before provider handling, so emulated multi-turn tool calling cannot continue. Please allow content: null for assistant messages that carry tool_calls.
Useful? React with 👍 / 👎.
Motivation
toolsandtool_choicein chat completion requests and support tool-calling flows even when a provider lacks native tool calling.[tool-call]/[tool-result]messages.Description
src/openai/schemas.ts, includingtools,tool_choice,tool_calls, and arole: 'tool'message shape.src/openai/tool-emulation.tswith functions to detect emulation (shouldEmulateTools), transform inbound messages (toProviderMessages), parse tool-call payloads, apply emulation responses (applyToolEmulationResponse), and convert streamed protocol JSON into structuredtool_callschunks (transformToolEmulationStream).toProviderMessages,transformToolEmulationStreamfor streams, andapplyToolEmulationResponsefor non-streamed responses insrc/server.ts.supportsNativeToolCallinginsrc/providers/types.tsand mark thedummyprovider as not supporting native tool calling while adding simple emulation-aware behavior insrc/providers/dummy.ts.README.mdwith usage notes and an example of the emulation protocol.Testing
test/tool-emulation.test.tsand extendedtest/server.test.tsto cover schema validation, emulated tool call generation, plain-text passthrough, tool-result handling, and stream behavior, and executed the test suite withnpm test(viavitest).Codex Task