Skip to content

Add tool-calling support with emulation for providers without native tool calling#2

Open
neuwcodebox wants to merge 1 commit into
mainfrom
codex/add-emulation-layer-for-tool-calls
Open

Add tool-calling support with emulation for providers without native tool calling#2
neuwcodebox wants to merge 1 commit into
mainfrom
codex/add-emulation-layer-for-tool-calls

Conversation

@neuwcodebox
Copy link
Copy Markdown
Owner

Motivation

  • Enable clients to send tools and tool_choice in chat completion requests and support tool-calling flows even when a provider lacks native tool calling.
  • Provide a consistent emulation mode so providers can participate in tool workflows by exchanging special [tool-call]/[tool-result] messages.

Description

  • Add tool-related types and validation to src/openai/schemas.ts, including tools, tool_choice, tool_calls, and a role: 'tool' message shape.
  • Implement emulation logic in src/openai/tool-emulation.ts with functions to detect emulation (shouldEmulateTools), transform inbound messages (toProviderMessages), parse tool-call payloads, apply emulation responses (applyToolEmulationResponse), and convert streamed protocol JSON into structured tool_calls chunks (transformToolEmulationStream).
  • Integrate emulation into the server by resolving provider capabilities and routing through toProviderMessages, transformToolEmulationStream for streams, and applyToolEmulationResponse for non-streamed responses in src/server.ts.
  • Expose provider capability via supportsNativeToolCalling in src/providers/types.ts and mark the dummy provider as not supporting native tool calling while adding simple emulation-aware behavior in src/providers/dummy.ts.
  • Update README.md with usage notes and an example of the emulation protocol.

Testing

  • Added unit/integration tests in test/tool-emulation.test.ts and extended test/server.test.ts to cover schema validation, emulated tool call generation, plain-text passthrough, tool-result handling, and stream behavior, and executed the test suite with npm test (via vitest).
  • All automated tests completed successfully.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/openai/schemas.ts
Comment on lines +171 to +174
content: {
type: ['string', 'array'],
minLength: 1,
minItems: 1,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant