Skip to content

Fix OpenAI compat parallel tool calls - #6719

Merged
IMax153 merged 2 commits into
mainfrom
fix/openai-compat-tool-calls
Jul 29, 2026
Merged

Fix OpenAI compat parallel tool calls#6719
IMax153 merged 2 commits into
mainfrom
fix/openai-compat-tool-calls

Conversation

@IMax153

@IMax153 IMax153 commented Jul 28, 2026

Copy link
Copy Markdown
Member

Fixes #6702

Groups consecutive function calls into a single assistant message before emitting their tool outputs, matching strict Chat Completions message ordering requirements.

Adds a regression test covering two parallel tool calls and their adjacent outputs.

Testing

  • pnpm --filter @effect/ai-openai-compat test --run test/OpenAiLanguageModel.test.ts
  • pnpm --filter @effect/ai-openai-compat check
  • pnpm lint-fix

Summary by CodeRabbit

  • Bug Fixes

    • Improved compatibility with Chat Completions APIs by grouping consecutive parallel tool calls into a single assistant message.
    • Preserved correct tool call identifiers and responses when multiple tools are invoked together.
  • Tests

    • Added coverage verifying parallel tool calls are encoded and returned correctly.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 28, 2026
@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6fd2f74

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 29 packages
Name Type
@effect/ai-openai-compat Patch
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-slopcop effect-slopcop Bot added 4.0 bug Something isn't working labels Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@IMax153, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 36 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 162ac20b-66d8-4d41-8784-c2ab05d4a6ef

📥 Commits

Reviewing files that changed from the base of the PR and between 1a13b15 and 6fd2f74.

📒 Files selected for processing (1)
  • packages/ai/openai-compat/src/OpenAiLanguageModel.ts
📝 Walkthrough

Walkthrough

The OpenAI-compatible chat conversion now groups consecutive function calls into one assistant message with multiple tool_calls, followed by matching tool responses. A regression test verifies the request structure, and a patch changeset documents the behavior.

Changes

OpenAI-compatible parallel tool calls

Layer / File(s) Summary
Group consecutive tool calls
packages/ai/openai-compat/src/OpenAiLanguageModel.ts
Function-call items are converted through a shared typed helper and accumulated into one assistant message’s tool_calls array.
Validate grouped request behavior
packages/ai/openai-compat/test/OpenAiLanguageModel.test.ts, .changeset/openai-compat-parallel-tool-calls.md
A generateText test verifies grouped assistant calls and matching serialized tool responses; the changeset records a patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: tim-smart

Sequence Diagram(s)

sequenceDiagram
  participant Prompt
  participant OpenAiLanguageModel
  participant ChatCompletionsAPI
  Prompt->>OpenAiLanguageModel: provide consecutive function calls
  OpenAiLanguageModel->>OpenAiLanguageModel: group calls into one assistant tool_calls message
  OpenAiLanguageModel->>ChatCompletionsAPI: send assistant message and matching tool responses
Loading
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Consecutive function calls are now merged into one assistant message with combined tool_calls, matching the issue's required ordering.
Out of Scope Changes check ✅ Passed Changes stay focused on OpenAI compat message ordering and the regression test/changelog for that fix.

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Name Current Size Previous Size Difference
basic.ts 6.63 KB 6.63 KB 0.00 KB (0.00%)
batching.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
brand.ts 6.31 KB 6.31 KB 0.00 KB (0.00%)
cache.ts 10.12 KB 10.12 KB 0.00 KB (0.00%)
config.ts 19.90 KB 19.90 KB 0.00 KB (0.00%)
differ.ts 20.03 KB 20.03 KB 0.00 KB (0.00%)
http-client.ts 20.94 KB 20.94 KB 0.00 KB (0.00%)
logger.ts 10.28 KB 10.28 KB 0.00 KB (0.00%)
metric.ts 8.55 KB 8.55 KB 0.00 KB (0.00%)
optic.ts 7.46 KB 7.46 KB 0.00 KB (0.00%)
pubsub.ts 14.26 KB 14.26 KB 0.00 KB (0.00%)
queue.ts 11.09 KB 11.09 KB 0.00 KB (0.00%)
schedule.ts 10.27 KB 10.27 KB 0.00 KB (0.00%)
schema-class.ts 18.86 KB 18.86 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 28.78 KB 28.78 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 25.09 KB 25.09 KB 0.00 KB (0.00%)
schema-string-transformation.ts 12.95 KB 12.95 KB 0.00 KB (0.00%)
schema-string.ts 10.65 KB 10.65 KB 0.00 KB (0.00%)
schema-template-literal.ts 14.85 KB 14.85 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 21.66 KB 21.66 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.10 KB 24.10 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 19.00 KB 19.00 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.73 KB 18.73 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.59 KB 18.59 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.23 KB 22.23 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.27 KB 19.27 KB 0.00 KB (0.00%)
schema.ts 18.12 KB 18.12 KB 0.00 KB (0.00%)
stm.ts 12.05 KB 12.05 KB 0.00 KB (0.00%)
stream.ts 9.37 KB 9.37 KB 0.00 KB (0.00%)

@IMax153
IMax153 merged commit 20b9660 into main Jul 29, 2026
26 of 27 checks passed
@IMax153
IMax153 deleted the fix/openai-compat-tool-calls branch July 29, 2026 00:00
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Done in PR Backlog Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[@effect/ai-openai-compat] Invalid message ordering for parallel tool calls

1 participant