({
question,
cacheSafeParams,
}: {
question: string
cacheSafeParams: CacheSafeParams
})
| 51 | * All tools are blocked and we cap at 1 turn. |
| 52 | */ |
| 53 | export async function runSideQuestion({ |
| 54 | question, |
| 55 | cacheSafeParams, |
| 56 | }: { |
| 57 | question: string |
| 58 | cacheSafeParams: CacheSafeParams |
| 59 | }): Promise<SideQuestionResult> { |
| 60 | // Wrap the question with instructions to answer without tools |
| 61 | const wrappedQuestion = `<system-reminder>This is a side question from the user. You must answer this question directly in a single response. |
| 62 | |
| 63 | IMPORTANT CONTEXT: |
| 64 | - You are a separate, lightweight agent spawned to answer this one question |
| 65 | - The main agent is NOT interrupted - it continues working independently in the background |
| 66 | - You share the conversation context but are a completely separate instance |
| 67 | - Do NOT reference being interrupted or what you were "previously doing" - that framing is incorrect |
| 68 | |
| 69 | CRITICAL CONSTRAINTS: |
| 70 | - You have NO tools available - you cannot read files, run commands, search, or take any actions |
| 71 | - This is a one-off response - there will be no follow-up turns |
| 72 | - You can ONLY provide information based on what you already know from the conversation context |
| 73 | - NEVER say things like "Let me try...", "I'll now...", "Let me check...", or promise to take any action |
| 74 | - If you don't know the answer, say so - do not offer to look it up or investigate |
| 75 | |
| 76 | Simply answer the question with the information you have.</system-reminder> |
| 77 | |
| 78 | ${question}` |
| 79 | |
| 80 | const agentResult = await runForkedAgent({ |
| 81 | promptMessages: [createUserMessage({ content: wrappedQuestion })], |
| 82 | // Do NOT override thinkingConfig — thinking is part of the API cache key, |
| 83 | // and diverging from the main thread's config busts the prompt cache. |
| 84 | // Adaptive thinking on a quick Q&A has negligible overhead. |
| 85 | cacheSafeParams, |
| 86 | canUseTool: async () => ({ |
| 87 | behavior: 'deny' as const, |
| 88 | message: 'Side questions cannot use tools', |
| 89 | decisionReason: { type: 'other' as const, reason: 'side_question' }, |
| 90 | }), |
| 91 | querySource: 'side_question', |
| 92 | forkLabel: 'side_question', |
| 93 | maxTurns: 1, // Single turn only - no tool use loops |
| 94 | // No future request shares this suffix; skip writing cache entries. |
| 95 | skipCacheWrite: true, |
| 96 | }) |
| 97 | |
| 98 | return { |
| 99 | response: extractSideQuestionResponse(agentResult.messages), |
| 100 | usage: agentResult.totalUsage, |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Extract a display string from forked agent messages. |
no test coverage detected