Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
vishxrad
marked this pull request as ready for review
September 29, 2026 07:47
vishxrad
added this pull request to stack #1262
September 29, 2026 07:48
6 tasks done
vishxrad
force-pushed
the
visharad/cookbooks-run-tools
branch
from
September 29, 2026 09:37
4d89eed to
e1efce0
Compare
vishxrad
force-pushed
the
visharad/cookbooks-run-tools
branch
from
September 29, 2026 09:43
e1efce0 to
964f3da
Compare
Replace each cookbook's hand-written Chat Completions tool loop (src/lib/tool-loop.ts) with gateway.chat.completions.runTools(). The chat route passes the tool's existing JSON schema with its executor and translates the runner's events into the same AG-UI events, so Agent Interface still shows each call and its result. Behavior differences from the old loop: - A tool's arguments reach the browser when the completion that calls it finishes, instead of streaming in. - Tools the model calls in one completion run in parallel. - runTools() ends the run when a tool throws, so each executor returns its error to the model as the tool result instead. - maxChatCompletions has no final text-only round, so a run that hits the cap on a tool call ends with a RUN_ERROR instead of an answer. The route still waits for the first completion before responding, so a rejected key returns Gateway's HTTP status. The docs no longer say an unknown model does: Gateway accepts it with 200 and fails inside the stream, with the old loop too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow the self-hosted template: the chat route forwards the runTools() runner's completion chunks as server-sent events, the format Gateway streams, and Agent Interface reads them with openAIAdapter() instead of AG-UI events built in the route. This drops the event mapping from each route. The route still waits for the first completion before responding, so a rejected key or rate limit returns Gateway's HTTP status. What changes for readers, and the docs now say so: - Tool call arguments stream in again. - Chat Completions has no chunk for a tool result, so Behind the scenes shows each call's arguments but not its result. - A later error ends the stream, and Agent Interface reports that the request failed instead of showing Gateway's message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vishxrad
force-pushed
the
visharad/cookbooks-run-tools
branch
from
September 29, 2026 10:01
1b86cae to
e63b315
Compare
14 tasks done
This branch was successfully deployed
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.
Stacked on #1258. The cookbooks run their tools with the OpenAI SDK's
runTools()instead of the hand-written tool loop, and stream raw completion chunks to Agent Interface, following the self-hosted template (route, page).Summary
src/lib/tool-loop.tsis gone (about 150 lines each). The chat route callsgateway.chat.completions.runTools()with the tool's existing JSON schema plus its executor, typed with the SDK's own runnable-tool types (no casts).openAIAdapter()andopenAIMessageFormat, as in the template, so the route no longer builds AG-UI events.maxChatCompletionsis 3, 4 and 3, matching the oldmaxRounds.runner.emitted("connect")raced withrunner.done()), so a rejected key or rate limit still returns Gateway's HTTP status.runTools()andopenAIAdapter().What changes for readers
openAIAdapter()reads only text and tool-call chunks. Behind the scenes shows each call with its arguments, but the call stays at "Calling …" with no result. The docs and Verify steps say so.runTools()ends the run when a tool throws. Each route wraps its executor so the error goes back to the model as the tool result, as the old loop did.tool_choice: "none"on its last round.maxChatCompletionsjust stops, so a run that hits the cap on a tool call ends without an answer.Docs correction
The pages said "a rejected key, rate limit, or unknown model returns as an HTTP error". An unknown model doesn't: Gateway accepts it with 200 and fails inside the stream, with the old loop too. The pages now say "a rejected key or rate limit".
Test plan
tsc --noEmitin all three cookbooksnpm run verifyin all three cookbooks, on the first commit (before switching to raw chunks)npm run verifyafter switching to raw chunksquery_lap_timescall with its arguments, and the table. The call has no result.search_documentscalls in one roundOPENUI_MODEL: Agent Interface shows "Something went wrong: Failed to fetch"THESYS_API_KEY:/api/chatreturns HTTP 401 with Gateway's message (tested on the first commit; this path is unchanged)🤖 Generated with Claude Code