Skip to content

Commit 4c41eb9

Browse files
committed
feat(task): allow runtime systemPrompt for subtasks
Add runtime system prompt override support for subagent subtasks. - add optional systemPrompt to MessageV2.SubtaskPart schema so subtask inputs accept and preserve it - thread systemPrompt through subtask execution plumbing into task tool args - pass systemPrompt to SessionPrompt.prompt as the child session system override - regenerate OpenAPI and JS SDK v2 generated types to expose SubtaskPartInput.systemPrompt - update subtask conversion test to use the general subagent with a systemPrompt example Verification: - bun test test/session/message-v2.test.ts Refs anomalyco#7351
1 parent bab3124 commit 4c41eb9

6 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎packages/opencode/src/session/message-v2.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export namespace MessageV2 {
206206
prompt: z.string(),
207207
description: z.string(),
208208
agent: z.string(),
209+
systemPrompt: z.string().optional(),
209210
model: z
210211
.object({
211212
providerID: z.string(),

‎packages/opencode/src/session/prompt.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ export namespace SessionPrompt {
390390
prompt: task.prompt,
391391
description: task.description,
392392
subagent_type: task.agent,
393+
systemPrompt: task.systemPrompt,
393394
command: task.command,
394395
},
395396
time: {
@@ -401,6 +402,7 @@ export namespace SessionPrompt {
401402
prompt: task.prompt,
402403
description: task.description,
403404
subagent_type: task.agent,
405+
systemPrompt: task.systemPrompt,
404406
command: task.command,
405407
}
406408
await Plugin.trigger(

‎packages/opencode/src/tool/task.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const parameters = z.object({
2121
"This should only be set if you mean to resume a previous task (you can pass a prior task_id and the task will continue the same subagent session as before instead of creating a fresh one)",
2222
)
2323
.optional(),
24+
systemPrompt: z.string().describe("Override the subagent system prompt for this task").optional(),
2425
command: z.string().describe("The command that triggered this task").optional(),
2526
})
2627

@@ -133,6 +134,7 @@ export const TaskTool = Tool.define("task", async (ctx) => {
133134
providerID: model.providerID,
134135
},
135136
agent: agent.name,
137+
system: params.systemPrompt,
136138
tools: {
137139
todowrite: false,
138140
todoread: false,

‎packages/opencode/test/session/message-v2.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ describe("session.message-v2.toModelMessage", () => {
239239
type: "subtask",
240240
prompt: "prompt",
241241
description: "desc",
242-
agent: "agent",
242+
agent: "general",
243+
systemPrompt: "You are a Security Auditor specializing in OWASP.",
243244
},
244245
] as MessageV2.Part[],
245246
},

‎packages/sdk/js/src/v2/gen/types.gen.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ export type SubtaskPart = {
285285
prompt: string
286286
description: string
287287
agent: string
288+
systemPrompt?: string
288289
model?: {
289290
providerID: string
290291
modelID: string
@@ -2093,6 +2094,7 @@ export type SubtaskPartInput = {
20932094
prompt: string
20942095
description: string
20952096
agent: string
2097+
systemPrompt?: string
20962098
model?: {
20972099
providerID: string
20982100
modelID: string

‎packages/sdk/openapi.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6648,6 +6648,9 @@
66486648
"agent": {
66496649
"type": "string"
66506650
},
6651+
"systemPrompt": {
6652+
"type": "string"
6653+
},
66516654
"model": {
66526655
"type": "object",
66536656
"properties": {
@@ -10640,6 +10643,9 @@
1064010643
"agent": {
1064110644
"type": "string"
1064210645
},
10646+
"systemPrompt": {
10647+
"type": "string"
10648+
},
1064310649
"model": {
1064410650
"type": "object",
1064510651
"properties": {

0 commit comments

Comments
 (0)