support agent options

This commit is contained in:
Dax Raad
2025-08-10 20:30:25 -04:00
parent b8d2aebf09
commit 3ab4f42ebb
4 changed files with 25 additions and 13 deletions

View File

@@ -14,6 +14,7 @@ export namespace Agent {
mode: z.union([z.literal("subagent"), z.literal("primary"), z.literal("all")]),
topP: z.number().optional(),
temperature: z.number().optional(),
options: z.record(z.any()),
model: z
.object({
modelID: z.string(),
@@ -39,15 +40,18 @@ export namespace Agent {
todoread: false,
todowrite: false,
},
options: {},
mode: "subagent",
},
build: {
name: "build",
tools: {},
options: {},
mode: "primary",
},
plan: {
name: "plan",
options: {},
tools: {
write: false,
edit: false,
@@ -66,6 +70,7 @@ export namespace Agent {
item = result[key] = {
name: key,
mode: "all",
options: {},
tools: {},
}
if (value.model) item.model = Provider.parseModel(value.model)
@@ -79,6 +84,11 @@ export namespace Agent {
if (value.temperature != undefined) item.temperature = value.temperature
if (value.top_p != undefined) item.topP = value.top_p
if (value.mode) item.mode = value.mode
if (value.options)
item.options = {
...item.options,
...value.options,
}
}
return result
})

View File

@@ -173,6 +173,7 @@ export namespace Config {
tools: z.record(z.string(), z.boolean()).optional(),
disable: z.boolean().optional(),
description: z.string().optional().describe("Description of when to use the agent"),
options: z.record(z.string(), z.any()).optional().describe("Additional model options passed through to provider"),
mode: z.union([z.literal("subagent"), z.literal("primary"), z.literal("all")]).optional(),
})
.openapi({

View File

@@ -852,20 +852,24 @@ export namespace Session {
tools[key] = item
}
const params = {
temperature: model.info.temperature
? (agent.temperature ?? ProviderTransform.temperature(input.providerID, input.modelID))
: undefined,
topP: agent.topP ?? ProviderTransform.topP(input.providerID, input.modelID),
}
await Plugin.trigger(
const params = await Plugin.trigger(
"chat.params",
{
model: model.info,
provider: await Provider.getProvider(input.providerID),
message: userMsg,
},
params,
{
temperature: model.info.temperature
? (agent.temperature ?? ProviderTransform.temperature(input.providerID, input.modelID))
: undefined,
topP: agent.topP ?? ProviderTransform.topP(input.providerID, input.modelID),
options: {
...ProviderTransform.options(input.providerID, input.modelID),
...model.info.options,
...agent.options,
},
},
)
const stream = streamText({
onError(e) {
@@ -946,10 +950,7 @@ export namespace Session {
return false
},
providerOptions: {
[input.providerID]: {
...ProviderTransform.options(input.providerID, input.modelID),
...model.info.options,
},
[input.providerID]: params.options,
},
temperature: params.temperature,
topP: params.topP,

View File

@@ -19,7 +19,7 @@ export interface Hooks {
*/
"chat.params"?: (
input: { model: Model; provider: Provider; message: UserMessage },
output: { temperature: number; topP: number },
output: { temperature: number; topP: number; options: Record<string, any> },
) => Promise<void>
"permission.ask"?: (input: Permission, output: { status: "ask" | "deny" | "allow" }) => Promise<void>
"tool.execute.before"?: (