Skip to content

Commit fa43720

Browse files
committed
add reasoning options to templates
1 parent db6d9e8 commit fa43720

File tree

8 files changed

+64
-13
lines changed

8 files changed

+64
-13
lines changed

.agents/base-lite.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const definition: SecretAgentDefinition = {
77
id: 'base-lite',
88
publisher,
99
...base('openai/gpt-5'),
10+
reasoningOptions: {
11+
enabled: true,
12+
exclude: false,
13+
effort: 'high',
14+
},
1015
}
1116

1217
export default definition

.agents/factory/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { AgentTemplateTypes } from '../types/secret-agent-definition'
99

1010
import type { SecretAgentDefinition } from '../types/secret-agent-definition'
11-
import { ModelName } from 'types/agent-definition'
11+
import type { ModelName } from 'types/agent-definition'
1212

1313
export const base = (
1414
model: ModelName,

.agents/types/agent-definition.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ export interface AgentDefinition {
3434
/** AI model to use for this agent. Can be any model in OpenRouter: https://openrouter.ai/models */
3535
model: ModelName
3636

37+
/**
38+
* https://openrouter.ai/docs/use-cases/reasoning-tokens
39+
* One of `max_tokens` or `effort` is required.
40+
* If `exclude` is true, reasoning will be removed from the response. Default is false.
41+
*/
42+
reasoningOptions?: {
43+
enabled?: boolean
44+
exclude?: boolean
45+
} & (
46+
| {
47+
max_tokens: number
48+
}
49+
| {
50+
effort: 'high' | 'medium' | 'low'
51+
}
52+
)
53+
3754
// ============================================================================
3855
// Tools and Subagents
3956
// ============================================================================

backend/src/llm-apis/vercel-ai-sdk/ai-sdk.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { openRouterLanguageModel } from '../openrouter'
2323
import { vertexFinetuned } from './vertex-finetuned'
2424

2525
import type { System } from '../claude'
26-
import type { GoogleGenerativeAIProviderOptions } from '@ai-sdk/google'
2726
import type {
2827
GeminiModel,
2928
Model,
@@ -98,14 +97,6 @@ export const promptAiSdkStream = async function* (
9897
...options,
9998
model: aiSDKModel,
10099
maxRetries: options.maxRetries,
101-
providerOptions: {
102-
google: {
103-
thinkingConfig: {
104-
includeThoughts: false,
105-
thinkingBudget: options.thinkingBudget ?? 128,
106-
},
107-
} satisfies GoogleGenerativeAIProviderOptions,
108-
},
109100
})
110101

111102
let content = ''

backend/src/prompt-agent-stream.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { globalStopSequence } from './tools/constants'
55

66
import type { AgentTemplate } from './templates/types'
77
import type { CodebuffMessage } from '@codebuff/common/types/message'
8+
import type { OpenRouterProviderOptions } from '@codebuff/internal/openrouter-ai-sdk'
89

910
export const getAgentStreamFromTemplate = (params: {
1011
clientSessionId: string
@@ -40,17 +41,23 @@ export const getAgentStreamFromTemplate = (params: {
4041
const provider =
4142
providerModelNames[primaryModel as keyof typeof providerModelNames]
4243

44+
if (!options.providerOptions) {
45+
options.providerOptions = {}
46+
}
4347
if (provider === 'gemini') {
44-
if (!options.providerOptions) {
45-
options.providerOptions = {}
46-
}
4748
if (!options.providerOptions.gemini) {
4849
options.providerOptions.gemini = {}
4950
}
5051
if (!options.providerOptions.gemini.thinkingConfig) {
5152
options.providerOptions.gemini.thinkingConfig = { thinkingBudget: 128 }
5253
}
5354
}
55+
if (!options.providerOptions.openrouter) {
56+
options.providerOptions.openrouter = {}
57+
}
58+
;(
59+
options.providerOptions.openrouter as OpenRouterProviderOptions
60+
).reasoning = template.reasoningOptions
5461

5562
return promptAiSdkStream(options)
5663
}

common/src/templates/initial-agents-dir/types/agent-definition.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ export interface AgentDefinition {
3434
/** AI model to use for this agent. Can be any model in OpenRouter: https://openrouter.ai/models */
3535
model: ModelName
3636

37+
/**
38+
* https://openrouter.ai/docs/use-cases/reasoning-tokens
39+
* One of `max_tokens` or `effort` is required.
40+
* If `exclude` is true, reasoning will be removed from the response. Default is false.
41+
*/
42+
reasoningOptions?: {
43+
enabled?: boolean
44+
exclude?: boolean
45+
} & (
46+
| {
47+
max_tokens: number
48+
}
49+
| {
50+
effort: 'high' | 'medium' | 'low'
51+
}
52+
)
53+
3754
// ============================================================================
3855
// Tools and Subagents
3956
// ============================================================================

common/src/types/agent-template.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Model } from '../constants'
22
import type { AgentState, AgentTemplateType } from './session-state'
33
import type { ToolCall } from '../templates/initial-agents-dir/types/agent-definition'
44
import type { ToolName } from '../tools/constants'
5+
import type { OpenRouterProviderOptions } from '@codebuff/internal/openrouter-ai-sdk'
56
import type { z } from 'zod/v4'
67

78
export type AgentTemplate<
@@ -11,6 +12,7 @@ export type AgentTemplate<
1112
id: AgentTemplateType
1213
displayName: string
1314
model: Model
15+
reasoningOptions: OpenRouterProviderOptions['reasoning']
1416

1517
toolNames: ToolName[]
1618
spawnableAgents: AgentTemplateType[]

common/src/types/dynamic-agent-template.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ export const DynamicAgentDefinitionSchema = z.object({
101101
// Required fields for new agents
102102
displayName: z.string(),
103103
model: z.string(),
104+
reasoningOptions: z
105+
.object({
106+
enabled: z.boolean().optional(),
107+
exclude: z.boolean().optional(),
108+
})
109+
.and(
110+
z.union([
111+
z.object({ max_tokens: z.number() }),
112+
z.object({ effort: z.enum(['high', 'medium', 'low']) }),
113+
]),
114+
)
115+
.optional(),
104116

105117
// Tools and spawnable agents
106118
toolNames: z.array(z.enum(toolNames)).optional().default([]),

0 commit comments

Comments
 (0)