instructions() helper creates well-structured, consistent prompts for agents. It formats instructions into a standardized template with purpose and routine sections.
Function Signature
agent.ts:377:395
Parameters
The agent’s role or purpose. Can be a single string or array of strings.
Step-by-step workflow for the agent. Array of strings.
Return Value
Returns a formatted string:<specialized_agents_placeholder> is replaced with handoff agent information when the agent has handoffs configured.
Variants
instructions.swarm()
For multi-agent coordinators. Includes additional prompting about the multi-agent system:agent.ts:397:418
instructions.supervisor()
For supervisor agents that coordinate multiple specialists:agent.ts:420:444
instructions.supervisor_subagent()
For agents that work under a supervisor:agent.ts:446:478
Examples
Basic Usage
Multi-Agent Coordinator
Supervisor Pattern
Research Bot Example
From the source code:research_bot.ts:48:53
Financial Analysis Example
From the source code:finanicals_bot.ts:73:83
Handoff Agent List
When an agent has handoffs, the<specialized_agents_placeholder> is replaced with a formatted table:
handoffDescription of each handoff agent.
Custom Prompt Formats
You can combineinstructions() with additional custom text:
Dynamic Instructions with Context
Combine with context-aware prompts:Best Practices
Be Specific in Purpose
Be Specific in Purpose
Clearly define what the agent does:
Actionable Routine Steps
Actionable Routine Steps
Make routine steps concrete and actionable:
Use Appropriate Variant
Use Appropriate Variant
Choose the right variant for your use case:
instructions()- Single agentinstructions.swarm()- Multi-agent coordinatorinstructions.supervisor()- Supervisor coordinating specialistsinstructions.supervisor_subagent()- Specialist under a supervisor
See Also
agent()
Create agents
Multi-Agent Guide
Build multi-agent systems