feat(cerebras): add chat language model provider#15420
Merged
Merged
Conversation
173d66f to
c786ac8
Compare
This was referenced May 19, 2026
Closed
gr2m
approved these changes
May 19, 2026
github-actions Bot
added a commit
that referenced
this pull request
May 19, 2026
## Background #15349 this is a follow up to #15416. cerebras models could return a valid structured JSON answer, like {"result":"2026"}, while also marking the response as `tool_calls` and repeating a tool call in the same response. The AI SDK interpreted that as “keep calling tools,” so the loop continued until stopWhen was hit. Because the final step still had finish reason `tool-calls`, `result.output` was never parsed and threw `NoOutputGeneratedError` ## Summary - Added a CerebrasChatLanguageModel wrapper around the OpenAI-compatible chat model - For structured JSON output calls only, when cerebras returns non-empty text with raw finish reason `tool_calls`, we treat it as the final structured answer - In that narrow case, we normalize the finish reason to `stop` and drop the stray repeated tool-call part - Real tool-call turns without text are still preserved and executed normally what would have been a bug fix was treated as an opportunity to handle cerebras quirks specifically ## Manual Verification verified by running the repro: ```ts import { NoOutputGeneratedError, Output, isStepCount, tool, ToolLoopAgent } from "ai"; import z from "zod"; import { cerebras } from "@ai-sdk/cerebras"; import { run } from '../../lib/run'; run(async () => { const agent = new ToolLoopAgent({ instructions: "Use the required structured output. For simple arithmetic you may answer directly.", model: cerebras("zai-glm-4.7"), tools: { nonUsefulTool: tool({ description: "A non-useful tool that returns a magic number", inputSchema: z.object({}), execute: () => { return 2026; }, }), }, output: Output.object({ schema: z.object({ result: z.string() }), }), stopWhen: isStepCount(5), }); const result = await agent.generate({ prompt: "what is the magic number?", }); console.log( 'steps:', JSON.stringify( result.steps.map(step => ({ finishReason: step.finishReason, text: step.text, toolCalls: step.toolCalls.map(toolCall => ({ toolName: toolCall.toolName, input: toolCall.input, })), })), null, 2, ), ); try { console.log(result.output); } catch (cause) { if (NoOutputGeneratedError.isInstance(cause)) { console.error( "Structured output missing (last step did not yield valid JSON).", "finishReason:", result.finishReason, "lastText:", JSON.stringify(result.text), ); throw cause; } throw cause; } }); ``` ## Checklist - [x] All commits are signed (PRs with unsigned commits cannot be merged) - [x] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues fixes #15349 --------- Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
Contributor
|
✅ Backport PR created: #15428 |
gr2m
added a commit
that referenced
this pull request
May 19, 2026
## Background #15349 this is a follow up to #15416. cerebras models could return a valid structured JSON answer, like {"result":"2026"}, while also marking the response as `tool_calls` and repeating a tool call in the same response. The AI SDK interpreted that as “keep calling tools,” so the loop continued until stopWhen was hit. Because the final step still had finish reason `tool-calls`, `result.output` was never parsed and threw `NoOutputGeneratedError` ## Summary - Added a CerebrasChatLanguageModel wrapper around the OpenAI-compatible chat model - For structured JSON output calls only, when cerebras returns non-empty text with raw finish reason `tool_calls`, we treat it as the final structured answer - In that narrow case, we normalize the finish reason to `stop` and drop the stray repeated tool-call part - Real tool-call turns without text are still preserved and executed normally what would have been a bug fix was treated as an opportunity to handle cerebras quirks specifically ## Manual Verification verified by running the repro: ```ts import { NoOutputGeneratedError, Output, isStepCount, tool, ToolLoopAgent } from "ai"; import z from "zod"; import { cerebras } from "@ai-sdk/cerebras"; import { run } from '../../lib/run'; run(async () => { const agent = new ToolLoopAgent({ instructions: "Use the required structured output. For simple arithmetic you may answer directly.", model: cerebras("zai-glm-4.7"), tools: { nonUsefulTool: tool({ description: "A non-useful tool that returns a magic number", inputSchema: z.object({}), execute: () => { return 2026; }, }), }, output: Output.object({ schema: z.object({ result: z.string() }), }), stopWhen: isStepCount(5), }); const result = await agent.generate({ prompt: "what is the magic number?", }); console.log( 'steps:', JSON.stringify( result.steps.map(step => ({ finishReason: step.finishReason, text: step.text, toolCalls: step.toolCalls.map(toolCall => ({ toolName: toolCall.toolName, input: toolCall.input, })), })), null, 2, ), ); try { console.log(result.output); } catch (cause) { if (NoOutputGeneratedError.isInstance(cause)) { console.error( "Structured output missing (last step did not yield valid JSON).", "finishReason:", result.finishReason, "lastText:", JSON.stringify(result.text), ); throw cause; } throw cause; } }); ``` ## Checklist - [x] All commits are signed (PRs with unsigned commits cannot be merged) - [x] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues fixes #15349 --------- Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
github-actions Bot
added a commit
that referenced
this pull request
May 19, 2026
This is an automated backport of #15420 to the release-v6.0 branch. FYI @aayush-kapoor --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com> Co-authored-by: Aayush Kapoor <aayushkapoor34@gmail.com>
aayush-kapoor
added a commit
that referenced
this pull request
May 19, 2026
…15427) ## Background observed in #15420; when creating a new language model file, it is now important to account for workflow serialization and deserialization (serde). this was highlighted by the vercel agent in #15420 (comment) so it makes sense to include it as rule ## Summary added a new rule that which ensures provider language model files must import the helpers/symbols needed to serialize and deserialize model instances across workflow step boundaries ## Manual Verification na ## Checklist - [x] All commits are signed (PRs with unsigned commits cannot be merged) - [x] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) --------- Co-authored-by: Felix Arntz <felix.arntz@vercel.com>
Contributor
|
🚀 Published in:
|
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.
Background
#15349
this is a follow up to #15416.
cerebras models could return a valid structured JSON answer, like {"result":"2026"}, while also marking the response as
tool_callsand repeating a tool call in the same response. The AI SDK interpreted that as “keep calling tools,” so the loop continued until stopWhen was hit. Because the final step still had finish reasontool-calls,result.outputwas never parsed and threwNoOutputGeneratedErrorSummary
tool_calls, we treat it as the final structured answerstopand drop the stray repeated tool-call partwhat would have been a bug fix was treated as an opportunity to handle cerebras quirks specifically
Manual Verification
verified by running the repro:
Checklist
pnpm changesetin the project root)Related Issues
fixes #15349