diff --git a/packages/opencode/src/tool/task.ts b/packages/opencode/src/tool/task.ts
index ac28d9f322f..6a34983f837 100644
--- a/packages/opencode/src/tool/task.ts
+++ b/packages/opencode/src/tool/task.ts
@@ -16,7 +16,12 @@ const parameters = z.object({
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(),
+ task_id: z
+ .string()
+ .describe(
+ "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)",
+ )
+ .optional(),
command: z.string().describe("The command that triggered this task").optional(),
})
@@ -60,8 +65,8 @@ export const TaskTool = Tool.define("task", async (ctx) => {
const hasTaskPermission = agent.permission.some((rule) => rule.permission === "task")
const session = await iife(async () => {
- if (params.session_id) {
- const found = await Session.get(params.session_id).catch(() => {})
+ if (params.task_id) {
+ const found = await Session.get(params.task_id).catch(() => {})
if (found) return found
}
@@ -176,7 +181,13 @@ export const TaskTool = Tool.define("task", async (ctx) => {
}))
const text = result.parts.findLast((x) => x.type === "text")?.text ?? ""
- const output = text + "\n\n" + ["", `session_id: ${session.id}`, ""].join("\n")
+ const output = [
+ `task_id: ${session.id} (for resuming to continue this task if needed)`,
+ "",
+ "",
+ text,
+ "",
+ ].join("\n")
return {
title: params.description,
diff --git a/packages/opencode/src/tool/task.txt b/packages/opencode/src/tool/task.txt
index 7af2a6f60dd..585cce8f9d0 100644
--- a/packages/opencode/src/tool/task.txt
+++ b/packages/opencode/src/tool/task.txt
@@ -17,10 +17,10 @@ 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 unless you provide a session_id. 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.
+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. The output includes a task_id you can reuse later to continue the same subagent session.
+3. Each agent invocation starts with a fresh context unless you provide task_id to resume the same subagent session (which continues with its previous messages and tool outputs). When starting fresh, 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.
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
+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. Tell it how to verify its work if possible (e.g., relevant test commands).
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.
Example usage (NOTE: The agents below are fictional examples for illustration only - use the actual agents listed above):