mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
Allow Task sub-sessions to be continued again.
This commit is contained in:
parent
c672a1963b
commit
8d373695e0
2 changed files with 10 additions and 3 deletions
|
|
@ -23,11 +23,14 @@ export const TaskTool = Tool.define("task", async () => {
|
|||
description: z.string().describe("A short (3-5 words) description of the task"),
|
||||
prompt: z.string().describe("The task for the agent to perform"),
|
||||
subagent_type: z.string().describe("The type of specialized agent to use for this task"),
|
||||
session_id: z.string().describe("Existing Task session to continue").optional(),
|
||||
}),
|
||||
async execute(params, ctx) {
|
||||
const agent = await Agent.get(params.subagent_type)
|
||||
if (!agent) throw new Error(`Unknown agent type: ${params.subagent_type} is not a valid agent type`)
|
||||
const session = await Session.create({
|
||||
const session = params.session_id
|
||||
? await Session.get(params.session_id)
|
||||
: await Session.create({
|
||||
parentID: ctx.sessionID,
|
||||
title: params.description + ` (@${agent.name} subagent)`,
|
||||
})
|
||||
|
|
@ -92,13 +95,17 @@ export const TaskTool = Tool.define("task", async () => {
|
|||
all = await Session.messages({ sessionID: session.id })
|
||||
all = all.filter((x) => x.info.role === "assistant")
|
||||
all = all.flatMap((msg) => msg.parts.filter((x: any) => x.type === "tool") as MessageV2.ToolPart[])
|
||||
const text = (result.parts.findLast((x: any) => x.type === "text") as any)?.text ?? ""
|
||||
const output = text ? `${text}
|
||||
|
||||
[task-session:${session.id}]` : `[task-session:${session.id}]`
|
||||
return {
|
||||
title: params.description,
|
||||
metadata: {
|
||||
summary: all,
|
||||
sessionId: session.id,
|
||||
},
|
||||
output: (result.parts.findLast((x: any) => x.type === "text") as any)?.text ?? "",
|
||||
output,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ When NOT to use the Task tool:
|
|||
Usage notes:
|
||||
1. Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
|
||||
2. When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.
|
||||
3. Each agent invocation is stateless. You will not be able to send additional messages to the agent, nor will the agent be able to communicate with you outside of its final report. Therefore, your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you.
|
||||
3. Each agent invocation is stateless. Provide the returned [task-session:<id>] marker as session_id to continue; otherwise include every instruction the agent needs upfront.
|
||||
4. The agent's outputs should generally be trusted
|
||||
5. Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent
|
||||
6. If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue