Skip to content

feat(providers): Add Cerebras Reasoning Support - #10417

Closed
aaalaniz wants to merge 45 commits into
aaif-goose:mainfrom
aaalaniz:phase2-reasoning-refactor
Closed

aaalaniz wants to merge 45 commits into
aaif-goose:mainfrom
aaalaniz:phase2-reasoning-refactor

Conversation

@aaalaniz

@aaalaniz aaalaniz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

This PR introduces flexible reasoning support for providers that use non-standard parameters, starting with Cerebras.

It adds a new ReasoningConfig that lets models declare:

  • Which property name to use for reasoning in requests
  • How to map reasoning effort levels (low / medium / high) to provider-specific values via effort_mapping
  • Optional extra_body JSON that gets merged into the request when reasoning is enabled

The primary goal was to unblock reliable multi-turn usage with Cerebras models. The design is intentionally provider-agnostic so future models can adapt requests to their specific requirements without changing core logic.

flowchart TD
    A[Model declares ReasoningConfig] --> B{Reasoning enabled?}
    B -->|No| C[Omit reasoning params]
    B -->|Yes| D[Apply effort_mapping]
    D --> E[Merge extra_body if present]
    E --> F[Send request to provider<br/>e.g. Cerebras]
    F --> G[Receive response with thinking]
    G --> H[Apply ThinkingPreservationFormat<br/>to message history]
Loading

Problem

Prior to this change, any multi-turn conversation with a Cerebras model that had thinking/reasoning enabled would fail with:

Before

before-400.mov

After

after.mp4

Fixes #10406

@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: e2d2001b0f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-provider-types/src/formats/openai.rs Outdated
Comment thread crates/goose-providers/src/openai.rs Outdated
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: 1031a98f33

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-providers/src/openai.rs Outdated
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: 76ff9b932f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-providers/src/openai.rs Outdated
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: 93ec063c04

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-provider-types/src/formats/openai.rs Outdated
Comment thread crates/goose-provider-types/src/formats/openai.rs
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: 899c346e35

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-provider-types/src/formats/openai.rs
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: 9b89e25a80

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-providers/src/openai.rs
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: 3b46d13ced

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-providers/src/openai.rs Outdated
Comment thread crates/goose-providers/src/anthropic.rs Outdated
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: a73529d933

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-providers/src/openai.rs Outdated
Comment thread crates/goose-providers/src/anthropic.rs Outdated
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: 615d519249

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-provider-types/src/model.rs
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: d37097fe79

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-providers/src/ollama.rs
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: 64084b8aca

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-providers/src/openai.rs
Comment thread crates/goose-providers/src/ollama.rs
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: c48266945b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-providers/src/openai.rs Outdated
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: 7f0087e2c0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-providers/src/openai.rs Outdated
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: e46c224c50

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/goose-provider-types/src/formats/openai.rs
Comment thread crates/goose-sdk/src/bindings.rs Outdated
@aaalaniz

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: ef3030cd03

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@aaalaniz
aaalaniz force-pushed the phase2-reasoning-refactor branch from a5d2c50 to 975c5fc Compare July 21, 2026 13:09

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

Copy link
Copy Markdown

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: 975c5fc9c4

ℹ️ 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 crates/goose-providers/src/openai.rs Outdated
aaalaniz and others added 2 commits July 21, 2026 18:51
Resolves conflicts with the uniffi API layer change (aaif-goose#10427), which added
`ModelConfig::request_headers` alongside this branch's `reasoning:
Option<Reasoning>` / `reasoning_is_explicit` fields. Both sides are kept in
`ModelConfig`, its `Deserialize` impl, `ModelConfig::new`, and the uniffi
`ProviderModelConfig` conversion, where `with_reasoning` now runs after
`with_request_headers`.

Also adapts two tests added upstream to the new `Reasoning` enum and the
`reasoning_is_explicit` field.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

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

Copy link
Copy Markdown

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: 81d9fbbb0b

ℹ️ 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 on lines +13 to +15
"reasoning": {
"enabled": true,
"thinking_preservation_format": "content_prepend",

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 Add reasoning coverage to the self-test recipe

This introduces provider-specific reasoning payload and history-preservation behavior, but the commit does not update goose-self-test.yaml, leaving the required end-to-end recipe validation for the new feature absent. Add a self-test case that exercises the Cerebras reasoning configuration and replay format.

AGENTS.md reference: AGENTS.md:L71-L71

Useful? React with 👍 / 👎.

};
model_config.reasoning = Some(crate::base::Reasoning::ReasoningConfig(reasoning));

// Use `true` for streaming

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 Remove self-evident test narration

This comment only restates the literal true streaming argument, and the nearby comment similarly narrates the assertion rather than explaining non-obvious behavior. Remove these comments so the tests comply with the repository's explicit prohibition on comments for self-evident operations.

AGENTS.md reference: AGENTS.md:L112-L112

Useful? React with 👍 / 👎.

@filipkujawa

Copy link
Copy Markdown
Collaborator

Hey @aaalaniz, thanks for the PR! I reviewed and tested this in depth, and discussed with team:

The core fix is real and verified. I reproduced the bug E2E on main, with your branch the same session works with the reasoning correctly re-embedded into content, exactly as the Cerebras docs require. Your thinking_preservation_format design is the right shape for this.

My ask: split the PR so we can land that fix now

Part A (this PR but trimmed): thinking preservation + the typed reasoning format, scoped to OpenAI-compatible providers, plus the cerebras.json refresh. This unblocks Cerebras reasoning users

Part B (defer): the generalized reasoning config (Reasoning enum, effort_mapping, extra_body, reasoning_is_explicit). There are a few issues that came up with it in testing and the team has ideas for a unified reasoning design that we'd like to flesh out to get this design right.

@aaalaniz

Copy link
Copy Markdown
Contributor Author

Hey @aaalaniz, thanks for the PR! I reviewed and tested this in depth, and discussed with team:

The core fix is real and verified. I reproduced the bug E2E on main, with your branch the same session works with the reasoning correctly re-embedded into content, exactly as the Cerebras docs require. Your thinking_preservation_format design is the right shape for this.

My ask: split the PR so we can land that fix now

Part A (this PR but trimmed): thinking preservation + the typed reasoning format, scoped to OpenAI-compatible providers, plus the cerebras.json refresh. This unblocks Cerebras reasoning users

Part B (defer): the generalized reasoning config (Reasoning enum, effort_mapping, extra_body, reasoning_is_explicit). There are a few issues that came up with it in testing and the team has ideas for a unified reasoning design that we'd like to flesh out to get this design right.

Agreed, and great feedback. Will do!

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.

Cerebras Reasoning Support

2 participants