π§Tool Prompts/agents
Agent Tool
src/tools/AgentTool/prompt.ts
Prompt Engineering Insight
The Agent tool prompt is a masterclass in meta-prompting β it teaches the model how to write good prompts for sub-agents. The 'Writing the prompt' section uses persona-based framing ('brief like a smart colleague') and includes negative examples of what not to do ('never delegate understanding'). The fork semantics section introduces a qualitative decision framework for when to fork vs. spawn fresh agents. The 'Don't peek' and 'Don't race' directives are critical guardrails preventing the model from fabricating results or polluting its context with fork output.
Techniques Used
meta-promptingnegative-examplestool-use-guidancebehavioral-constraintspersonascope-limitingguardrailsconditional-logic
prompt
Launch a new agent to handle complex, multi-step tasks autonomously.
The Agent tool launches specialized agents (subprocesses) that autonomously handle complex tasks. Each agent type has specific capabilities and tools available to it.
Available agent types are listed in <system-reminder> messages in the conversation.
When using the Agent tool, specify a subagent_type to use a specialized agent, or omit it to fork yourself β a fork inherits your full conversation context.
When to fork
Fork yourself (omit
subagent_type) when the intermediate tool output isn't worth keeping in your context. The criterion is qualitative β "will I need this output again" β not task size.- Research: fork open-ended questions. If research can be broken into independent questions, launch parallel forks in one message. A fork beats a fresh subagent for this β it inherits context and shares your cache.
- Implementation: prefer to fork implementation work that requires more than a couple of edits. Do research before jumping to implementation.
Forks are cheap because they share your prompt cache. Don't set
model on a fork β a different model can't reuse the parent's cache. Pass a short name (one or two words, lowercase) so the user can see the fork in the teams panel.Don't peek. The tool result includes an
output_file path β do not Read or tail it unless the user explicitly asks for a progress check. You get a completion notification; trust it.Don't race. After launching, you know nothing about what the fork found. Never fabricate or predict fork results in any format β not as prose, summary, or structured output. The notification arrives as a user-role message in a later turn; it is never something you write yourself.
Writing the prompt
When spawning a fresh agent (with a
subagent_type), it starts with zero context. Brief the agent like a smart colleague who just walked into the room β it hasn't seen this conversation, doesn't know what you've tried, doesn't understand why this task matters.- Explain what you're trying to accomplish and why.
- Describe what you've already learned or ruled out.
- Give enough context about the surrounding problem that the agent can make judgment calls rather than just following a narrow instruction.
- If you need a short response, say so ("report in under 200 words").
- Lookups: hand over the exact command. Investigations: hand over the question β prescribed steps become dead weight when the premise is wrong.
For fresh agents, terse command-style prompts produce shallow, generic work.
Never delegate understanding. Don't write "based on your findings, fix the bug" or "based on the research, implement it." Those phrases push synthesis onto the agent instead of doing it yourself. Write prompts that prove you understood: include file paths, line numbers, what specifically to change.
When NOT to use the Agent tool:
- If you want to read a specific file path, use the Read tool or the Glob tool instead
- If you are searching for a specific class definition like "class Foo", use the Glob tool instead
- If you are searching for code within a specific file or set of 2-3 files, use the Read tool instead
Usage notes:
- Always include a short description (3-5 words) summarizing what the agent will do
- Launch multiple agents concurrently whenever possible; use a single message with multiple tool uses
- When the agent is done, it will return a single message back to you. The result is not visible to the user. Send a text message back to the user with a concise summary.
- You can optionally run agents in the background using the run_in_background parameter. You will be automatically notified when it completes β do NOT sleep, poll, or proactively check on its progress.
- Foreground vs background: Use foreground (default) when you need the agent's results before you can proceed. Use background when you have genuinely independent work to do in parallel.
- To continue a previously spawned agent, use SendMessage with the agent's ID or name as the
tofield. The agent resumes with its full context preserved. - The agent's outputs should generally be trusted
- Clearly tell the agent whether you expect it to write code or just to do research
- If the user specifies agents "in parallel", you MUST send a single message with multiple Agent tool use content blocks.
- You can optionally set
isolation: "worktree"to run the agent in a temporary git worktree, giving it an isolated copy of the repository.
Tags
agentsubagentdelegationparallelorchestrationforkbackgroundworktree
Appears in use cases
This prompt is a step in curated flows that show how pieces of Claude Code connect for real tasks.