fix(background-task): clarify task id contracts
This commit is contained in:
@@ -301,11 +301,12 @@ Fire similar parallel calls for error patterns (explore), JWT security best prac
|
||||
|
||||
### Background Result Collection:
|
||||
|
||||
1. Launch parallel agents → receive task_ids
|
||||
1. Launch parallel agents → receive background task IDs (\`bg_...\`) for results and continuation session IDs (\`ses_...\`) for follow-ups.
|
||||
2. Continue ONLY with non-overlapping work. If none → END YOUR RESPONSE.
|
||||
3. System sends \`<system-reminder>\` when tasks complete.
|
||||
4. Collect via \`background_output(task_id="...")\` ONLY after \`<system-reminder>\`.
|
||||
4. Collect via \`background_output(task_id="bg_...")\` ONLY after \`<system-reminder>\`.
|
||||
5. Cancel disposable tasks INDIVIDUALLY via \`background_cancel(taskId="...")\`. NEVER \`background_cancel(all=true)\`.
|
||||
6. Use \`task(task_id="ses_...")\` only to continue the same sub-agent session.
|
||||
|
||||
${buildAntiDuplicationSection()}
|
||||
|
||||
@@ -347,9 +348,10 @@ After delegation: VERIFY against MUST DO/MUST NOT DO + existing patterns. Vague
|
||||
|
||||
### Session Continuity (apply to ALL follow-ups)
|
||||
|
||||
Every \`task()\` returns \`task_id\`. **REUSE IT.**
|
||||
Every \`task()\` output exposes a continuation session ID (\`ses_...\`). Pass it to \`task(task_id="ses_...")\`. **REUSE IT.**
|
||||
|
||||
Use \`task_id\` for: failed/incomplete work, follow-up questions, multi-turn refinement, verification failures.
|
||||
Use \`task(task_id="ses_...")\` for: failed/incomplete work, follow-up questions, multi-turn refinement, verification failures.
|
||||
Keep IDs separate: background task IDs (\`bg_...\`) are for \`background_output(task_id="bg_...")\`; continuation session IDs (\`ses_...\`) are for \`task(task_id="ses_...")\`.
|
||||
|
||||
\`\`\`typescript
|
||||
// WRONG: starting fresh loses everything
|
||||
|
||||
@@ -327,14 +327,15 @@ result = task(..., run_in_background=false) // Never wait synchronously for exp
|
||||
\`\`\`
|
||||
|
||||
### Background Result Collection:
|
||||
1. Launch parallel agents → receive task_ids
|
||||
1. Launch parallel agents → receive background task IDs (\`bg_...\`) for results and continuation session IDs (\`ses_...\`) for follow-ups
|
||||
2. Continue only with non-overlapping work
|
||||
- If you have DIFFERENT independent work → do it now
|
||||
- Otherwise → **END YOUR RESPONSE.**
|
||||
3. **STOP. END YOUR RESPONSE.** The system will send \`<system-reminder>\` when tasks complete.
|
||||
4. On receiving \`<system-reminder>\` → collect results via \`background_output(task_id="...")\`
|
||||
4. On receiving \`<system-reminder>\` → collect results via \`background_output(task_id="bg_...")\`
|
||||
5. **NEVER call \`background_output\` before receiving \`<system-reminder>\`.** This is a BLOCKING anti-pattern.
|
||||
6. Cleanup: Cancel disposable tasks individually via \`background_cancel(taskId="...")\`
|
||||
7. Use \`task(task_id="ses_...")\` only to continue the same sub-agent session
|
||||
|
||||
${buildAntiDuplicationSection()}
|
||||
|
||||
@@ -389,15 +390,17 @@ AFTER THE WORK YOU DELEGATED SEEMS DONE, ALWAYS VERIFY THE RESULTS AS FOLLOWING:
|
||||
|
||||
### Session Continuity (MANDATORY)
|
||||
|
||||
Every \`task()\` output includes a task_id. **USE IT.**
|
||||
Every \`task()\` output exposes a continuation session ID (\`ses_...\`). Pass it to \`task(task_id="ses_...")\` for follow-ups. **USE IT.**
|
||||
|
||||
**ALWAYS continue when:**
|
||||
- Task failed/incomplete → \`task_id="{task_id}", prompt="Fix: {specific error}"\`
|
||||
- Follow-up question on result → \`task_id="{task_id}", prompt="Also: {question}"\`
|
||||
- Multi-turn with same agent → \`task_id="{task_id}"\` - NEVER start fresh
|
||||
- Verification failed → \`task_id="{task_id}", prompt="Failed verification: {error}. Fix."\`
|
||||
- Task failed/incomplete → \`task(task_id="ses_...", prompt="Fix: {specific error}")\`
|
||||
- Follow-up question on result → \`task(task_id="ses_...", prompt="Also: {question}")\`
|
||||
- Multi-turn with same agent → \`task(task_id="ses_...")\` - NEVER start fresh
|
||||
- Verification failed → \`task(task_id="ses_...", prompt="Failed verification: {error}. Fix.")\`
|
||||
|
||||
**Why task_id is CRITICAL:**
|
||||
**Keep IDs separate:** background task IDs (\`bg_...\`) are for \`background_output(task_id="bg_...")\`; continuation session IDs (\`ses_...\`) are for \`task(task_id="ses_...")\`.
|
||||
|
||||
**Why continuation is CRITICAL:**
|
||||
- Subagent has FULL conversation context preserved
|
||||
- No repeated file reads, exploration, or setup
|
||||
- Saves 70%+ tokens on follow-ups
|
||||
@@ -411,7 +414,7 @@ task(category="quick", load_skills=[], run_in_background=false, description="Fix
|
||||
task(task_id="ses_abc123", load_skills=[], run_in_background=false, description="Fix type error", prompt="Fix: Type error on line 42")
|
||||
\`\`\`
|
||||
|
||||
**After EVERY delegation, STORE the task_id for potential continuation.**
|
||||
**After EVERY delegation, STORE the \`ses_...\` continuation ID for potential continuation.**
|
||||
|
||||
### Code Changes:
|
||||
- Match existing patterns (if codebase is disciplined)
|
||||
|
||||
@@ -263,14 +263,15 @@ Each agent prompt should include:
|
||||
- [REQUEST]: What to find, what format, what to skip
|
||||
|
||||
Background result collection:
|
||||
1. Launch parallel agents → receive task_ids
|
||||
1. Launch parallel agents → receive background task IDs (\`bg_...\`) for results and continuation session IDs (\`ses_...\`) for follow-ups
|
||||
2. Continue only with non-overlapping work
|
||||
- If you have DIFFERENT independent work → do it now
|
||||
- Otherwise → **END YOUR RESPONSE.**
|
||||
3. **STOP. END YOUR RESPONSE.** The system will send \`<system-reminder>\` when tasks complete.
|
||||
4. On receiving \`<system-reminder>\` → collect results via \`background_output(task_id="...")\`
|
||||
4. On receiving \`<system-reminder>\` → collect results via \`background_output(task_id="bg_...")\`
|
||||
5. **NEVER call \`background_output\` before receiving \`<system-reminder>\`.** This is a BLOCKING anti-pattern.
|
||||
6. Cancel disposable tasks individually via \`background_cancel(taskId="...")\`
|
||||
7. Use \`task(task_id="ses_...")\` only to continue the same sub-agent session
|
||||
|
||||
${buildAntiDuplicationSection()}
|
||||
|
||||
@@ -387,10 +388,12 @@ Post-delegation: delegation never substitutes for verification. Always run \`<ve
|
||||
|
||||
### Session continuity
|
||||
|
||||
Every \`task()\` returns a task_id. Use it for all follow-ups:
|
||||
- Failed/incomplete → \`task_id="{id}", prompt="Fix: {specific error}"\`
|
||||
- Follow-up → \`task_id="{id}", prompt="Also: {question}"\`
|
||||
- Multi-turn → always \`task_id\`, never start fresh
|
||||
Every \`task()\` output exposes a continuation session ID (\`ses_...\`). Pass it to \`task(task_id="ses_...")\` for all follow-ups:
|
||||
- Failed/incomplete → \`task(task_id="ses_...", prompt="Fix: {specific error}")\`
|
||||
- Follow-up → \`task(task_id="ses_...", prompt="Also: {question}")\`
|
||||
- Multi-turn → always \`task(task_id="ses_...")\`, never start fresh
|
||||
|
||||
Keep IDs separate: background task IDs (\`bg_...\`) are for \`background_output(task_id="bg_...")\`; continuation session IDs (\`ses_...\`) are for \`task(task_id="ses_...")\`.
|
||||
|
||||
This preserves full context, avoids repeated exploration, saves 70%+ tokens.
|
||||
|
||||
|
||||
@@ -218,11 +218,13 @@ After a delegation completes, verification is not optional. Read every file the
|
||||
|
||||
### Session continuity
|
||||
|
||||
Every \`task()\` returns a \`task_id\`. Reuse it for every follow-up interaction with the same sub-agent:
|
||||
Every \`task()\` output exposes a continuation session ID (\`ses_...\`). Pass it to \`task(task_id="ses_...")\` for every follow-up with the same sub-agent:
|
||||
|
||||
- Failed or incomplete work: \`task(task_id="{id}", prompt="Fix: {specific error}")\`
|
||||
- Follow-up question on a result: \`task(task_id="{id}", prompt="Also: {question}")\`
|
||||
- Multi-turn refinement: always \`task_id\`, never a fresh session.
|
||||
- Failed or incomplete work: \`task(task_id="ses_...", prompt="Fix: {specific error}")\`
|
||||
- Follow-up question on a result: \`task(task_id="ses_...", prompt="Also: {question}")\`
|
||||
- Multi-turn refinement: always \`task(task_id="ses_...")\`, never a fresh session.
|
||||
|
||||
Keep IDs separate: background task IDs (\`bg_...\`) are for \`background_output(task_id="bg_...")\`; continuation session IDs (\`ses_...\`) are for \`task(task_id="ses_...")\`.
|
||||
|
||||
Starting fresh on a follow-up throws away the sub-agent's full context. Session continuity typically saves 70% of the tokens a fresh session would burn.
|
||||
|
||||
@@ -235,7 +237,7 @@ Exploration is cheap; assumption is expensive. Before implementation on anything
|
||||
|
||||
Each exploration prompt should include four fields: **CONTEXT** (what task, which modules), **GOAL** (what decision the results will unblock), **DOWNSTREAM** (how you will use the results), **REQUEST** (what to find, what format, what to skip).
|
||||
|
||||
After firing exploration agents, do not manually perform the same search yourself. That is duplicate work and wastes your context window. Continue only with non-overlapping preparation: setting up files, reading known-path files, drafting questions. If no non-overlapping work exists, end your response and wait for the completion notification; do not poll \`background_output\` on a running task.
|
||||
After firing exploration agents, keep the returned background task IDs (\`bg_...\`) for result collection and continuation session IDs (\`ses_...\`) for follow-ups. Continue only with non-overlapping preparation: setting up files, reading known-path files, drafting questions. If no non-overlapping work exists, end your response and wait for the completion notification; then use \`background_output(task_id="bg_...")\`, not \`task(task_id="ses_...")\`, to collect results.
|
||||
|
||||
Stop searching when you have enough context to proceed confidently, when the same information keeps appearing across sources, when two iterations yield no new useful data, or when you found a direct answer.
|
||||
|
||||
|
||||
@@ -307,14 +307,15 @@ Each agent prompt should include:
|
||||
- [REQUEST]: What to find, what format, what to skip
|
||||
|
||||
Background result collection:
|
||||
1. Launch parallel agents → receive task_ids
|
||||
1. Launch parallel agents → receive background task IDs (\`bg_...\`) for results and continuation session IDs (\`ses_...\`) for follow-ups
|
||||
2. Continue only with non-overlapping work
|
||||
- If you have DIFFERENT independent work → do it now
|
||||
- Otherwise → **END YOUR RESPONSE.**
|
||||
3. **STOP. END YOUR RESPONSE.** The system will send \`<system-reminder>\` when tasks complete.
|
||||
4. On receiving \`<system-reminder>\` → collect results via \`background_output(task_id="...")\`
|
||||
4. On receiving \`<system-reminder>\` → collect results via \`background_output(task_id="bg_...")\`
|
||||
5. **NEVER call \`background_output\` before receiving \`<system-reminder>\`.** This is a BLOCKING anti-pattern.
|
||||
6. Cancel disposable tasks individually via \`background_cancel(taskId="...")\`
|
||||
7. Use \`task(task_id="ses_...")\` only to continue the same sub-agent session
|
||||
|
||||
${buildAntiDuplicationSection()}
|
||||
|
||||
@@ -462,10 +463,12 @@ Post-delegation: delegation never substitutes for verification. Always run \`<ve
|
||||
|
||||
### Session continuity
|
||||
|
||||
Every \`task()\` returns a session_id. Use it for all follow-ups:
|
||||
- Failed/incomplete → \`session_id="{id}", prompt="Fix: {specific error}"\`
|
||||
- Follow-up → \`session_id="{id}", prompt="Also: {question}"\`
|
||||
- Multi-turn → always \`session_id\`, never start fresh
|
||||
Every \`task()\` output exposes a continuation session ID (\`ses_...\`). Pass it to \`task(task_id="ses_...")\` for all follow-ups:
|
||||
- Failed/incomplete → \`task(task_id="ses_...", prompt="Fix: {specific error}")\`
|
||||
- Follow-up → \`task(task_id="ses_...", prompt="Also: {question}")\`
|
||||
- Multi-turn → always \`task(task_id="ses_...")\`, never start fresh
|
||||
|
||||
Keep IDs separate: background task IDs (\`bg_...\`) are for \`background_output(task_id="bg_...")\`; continuation session IDs (\`ses_...\`) are for \`task(task_id="ses_...")\`.
|
||||
|
||||
This preserves full context, avoids repeated exploration, saves 70%+ tokens.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user