|
| 1 | +import { FREEBUFF_PROJECTS_SUBAGENT_ID } from '@codebuff/common/constants/free-agents' |
| 2 | + |
| 3 | +import { publisher } from './constants' |
| 4 | + |
| 5 | +import type { SecretAgentDefinition } from './types/secret-agent-definition' |
| 6 | + |
| 7 | +/** |
| 8 | + * The subagent a Freebuff Projects account's threads may spawn (the |
| 9 | + * Projects allowlist only; the completions route refuses the id for anyone |
| 10 | + * else). Unlike fast mode's worker it is a full agent: it has the root's |
| 11 | + * coding tools, terminal included, and may spawn more of itself, so a thread |
| 12 | + * can fan out as wide and as deep as the work calls for. |
| 13 | + * |
| 14 | + * It runs the root's model with `inheritParentSystemPrompt` and |
| 15 | + * `includeMessageHistory`, like the fast-mode worker (agents/base3-fast.ts): |
| 16 | + * the request is the root's prefix plus the assignment, a prompt-cache hit on |
| 17 | + * a prefix-cached provider, and the session gate accepts it because the model |
| 18 | + * is the session's own. |
| 19 | + * |
| 20 | + * There is no count cap. What bounds a runaway tree is unchanged: every agent |
| 21 | + * has its step budget, and the server refuses a run more than |
| 22 | + * MAX_ANCESTOR_RUN_IDS (32) levels deep (web/src/app/api/v1/agent-runs/_post.ts). |
| 23 | + */ |
| 24 | +export function createProjectsSubagent(options: { |
| 25 | + model: SecretAgentDefinition['model'] |
| 26 | + /** The tools the subagent may run: the root's own, minus any that address |
| 27 | + * the human. `spawn_agents` is added here. */ |
| 28 | + toolNames: readonly string[] |
| 29 | + /** Other agents it may spawn besides itself (they must be in the run's |
| 30 | + * agent definitions). */ |
| 31 | + extraSpawnableAgents?: readonly string[] |
| 32 | +}): SecretAgentDefinition { |
| 33 | + return { |
| 34 | + id: FREEBUFF_PROJECTS_SUBAGENT_ID, |
| 35 | + publisher, |
| 36 | + model: options.model, |
| 37 | + displayName: 'Buffy Subagent', |
| 38 | + spawnerPrompt: |
| 39 | + 'A full coding agent that takes one piece of the current task and works it to the end in parallel with any siblings: it reads, edits, runs commands and tests, and can spawn subagents of its own. It sees this whole conversation and inherits your system prompt, so brief it rather than re-explaining. Spawn as many as the work splits into. Its last message is its report.', |
| 40 | + inputSchema: { |
| 41 | + prompt: { |
| 42 | + type: 'string', |
| 43 | + description: |
| 44 | + 'The assignment: what this subagent owns (files, area, question), what it must not touch because a sibling owns it, and what to report back. Brief: it already has the context above.', |
| 45 | + }, |
| 46 | + }, |
| 47 | + outputMode: 'last_message', |
| 48 | + includeMessageHistory: true, |
| 49 | + inheritParentSystemPrompt: true, |
| 50 | + windowedFileReads: true, |
| 51 | + toolNames: Array.from( |
| 52 | + new Set([...options.toolNames, 'spawn_agents']), |
| 53 | + ) as SecretAgentDefinition['toolNames'], |
| 54 | + spawnableAgents: Array.from( |
| 55 | + new Set([ |
| 56 | + FREEBUFF_PROJECTS_SUBAGENT_ID, |
| 57 | + ...(options.extraSpawnableAgents ?? []), |
| 58 | + ]), |
| 59 | + ), |
| 60 | + instructionsPrompt: `You are a SUBAGENT spawned by the agent whose conversation appears above, possibly one of several running in parallel. The plan to spawn you has already happened: you are that spawn. |
| 61 | +
|
| 62 | +- Do your assignment and only that. Stay inside what it says you own; if the work needs a change a sibling owns, leave it and say so in your report. |
| 63 | +- Do not re-explore what the conversation above already established. |
| 64 | +- If your piece itself splits into independent parts, you may spawn subagents of your own for them, in one spawn_agents call. |
| 65 | +- Verify what you changed when the assignment calls for it. Never commit, push or open a PR unless the assignment says to. |
| 66 | +- Your last message is your report: what you did, every file you changed, and anything left undone or worth checking, in a few sentences.`, |
| 67 | + } |
| 68 | +} |
0 commit comments