Skip to content

join assistant text with tool calls for configured Chat models - #260

Closed
polyominal wants to merge 3 commits into
model-chat-bridgefrom
model-request-repair
Closed

polyominal wants to merge 3 commits into
model-chat-bridgefrom
model-request-repair

Conversation

@polyominal

@polyominal polyominal commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Some Chat deployments need the assistant's text and function calls together and every tool result immediately afterward. A Responses history can place text between the calls and their results. An operator can now select request_repair = "join_assistant_tool_text" on a model with responses_via_chat = true. Replaying output with the bridge’s own item IDs uses ordinary conversion, even on a model with this repair. Each repaired group keeps its text parts, call IDs, and result order. An ambiguous group is refused before a provider request is sent.

The configuration gains the optional model field request_repair. A run's model_answered line gains the optional field kept.request_repair only when the outgoing history changed. The record continues to store the actual Chat exchange. The route owns the enum shared by machine configuration and the record writer. It adds a direct dependency on the workspace's already-pinned serde crate so both use the same spelling. Keep::upstream receives the applied repair together with the upstream protocol and header names.

The repair looks one item ahead in the existing translation pass. Joining text takes time and space proportional to the joined content. The exchange still makes one upstream request, with its original entry's admission, prices and budget. The applied marker adds one string to its existing log line.

Loopback tests compare the archived Chat request with the bytes received upstream, including a pair of count calls answered in reverse order. A budgeted simulated run records two Chat forwards, one repaired, and a third request refused before forwarding. The Responses route totals 20 input tokens (including 6 cache reads and 8 cache writes), 2 output tokens and $0.000066 in spend. Only the repaired exchange carries the marker. Native and strict models, ordinary histories, malformed groups and the configuration requirement are covered. The public Chat message types and LiteLLM's conversion informed the text-part handling. OpenAI Chat assistant message · LiteLLM history conversion

cargo xtask ci passed all 380 selected tests, including the existing budget exhaustion test, and the workspace documentation checks.

Addresses the model-specific repair in #73.

AI-assisted: gpt-6.2-astra

Allow a model that serves Responses through Chat to accept one assistant
text message between a group of function calls and their matching
results. Keep existing content and each text part in order on the
calling turn. Preserve the result order and require a result for each
call ID before forwarding the request.

Record the applied repair with the actual upstream exchange so an
operator can distinguish a transformed history from an ordinary one.

AI-assisted: gpt-6.2-astra
Group replayed output from one Chat response before checking for the
configured history repair. A replay with its original item IDs then
takes the same path for a strict model and one with the repair enabled.

Exercise a repaired call alongside an ordinary call in a budgeted
route. Keep the actual upstream bodies, the applied repair on its
exchange, and the reported cache reads and writes in the route's spend.

AI-assisted: gpt-6.2-astra
Read the repair from the completed conversion before handing the
exchange to its record, alongside the actual upstream protocol and
dropped headers.

AI-assisted: gpt-6.2-astra
@polyominal
polyominal marked this pull request as ready for review November 18, 2026 21:31
@polyominal
polyominal marked this pull request as draft November 22, 2026 08:16
@polyominal

Copy link
Copy Markdown
Collaborator Author

Closing at the owner's request: depends on #259, closed with it; to be redone together when a task needs a Chat-only model.

AI-assisted: claude-opus-5.5

@polyominal polyominal closed this Nov 23, 2026
@polyominal
polyominal deleted the model-request-repair branch November 24, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant