Use this file to discover all available pages before exploring further.
The instructions() helper creates well-structured, consistent prompts for agents. It formats instructions into a standardized template with purpose and routine sections.
# Agent Context[purpose lines]<specialized_agents_placeholder>Use the following routine to fulfill the task.# Routine1. [first routine step]2. [second routine step]...
The <specialized_agents_placeholder> is replaced with handoff agent information when the agent has handoffs configured.
For multi-agent coordinators. Includes additional prompting about the multi-agent system:
agent.ts:397:418
instructions.swarm({ purpose, routine })
Adds a system context prefix:
# System contextYou are part of a multi-agent system called the DeepAgents SDK...Handoffs are achieved by calling a handoff function, generally named `transfer_to_<agent_name>`....# Agent Context[purpose]<specialized_agents_placeholder># Routine...
For supervisor agents that coordinate multiple specialists:
agent.ts:420:444
instructions.supervisor({ purpose, routine })
Adds supervisor-specific directives:
# System ContextYou are part of a multi-agent system called the DeepAgents SDK...Core Directives:- Begin with a concise checklist (3-7 bullets) of what you will do- Continue working until the user's query is completely resolved- Your thinking must be thorough and step-by-step...# Agent Context[purpose]<specialized_agents_placeholder># Routine...
import { agent, instructions } from '@deepagents/agent';import { openai } from '@ai-sdk/openai';const dataAnalyst = agent({ name: 'data_analyst', model: openai('gpt-4o'), prompt: instructions({ purpose: [ 'You are a data analyst specializing in business intelligence.', 'You help users understand their data through clear insights.', ], routine: [ 'Examine the provided data carefully', 'Identify key patterns and trends', 'Calculate relevant statistics', 'Present findings in a clear, actionable format', ], }),});
import { agent, instructions } from '@deepagents/agent';const supervisor = agent({ name: 'supervisor', model: openai('gpt-4o'), prompt: instructions.supervisor({ purpose: [ 'You are a project supervisor coordinating multiple specialist agents.', 'Delegate tasks and review results to ensure quality.', ], routine: [ 'Break down the user request into subtasks', 'Delegate each subtask to the appropriate specialist', 'Review specialist outputs', 'Synthesize results into a cohesive response', ], }), handoffs: [specialist1, specialist2, specialist3],});
const planner = agent({ model: openai('gpt-4o'), name: 'PlannerAgent', output: WebSearchPlanSchema, prompt: instructions({ purpose: [ 'You are a helpful research assistant. Given a query, come up with a set of web searches to perform to best answer the query.', ], routine: ['Output between 5 and 10 terms to query for.'], }),});
const riskAgent = agent({ name: 'RiskAnalystAgent', model: groq('openai/gpt-oss-20b'), output: AnalysisSummarySchema, prompt: instructions({ purpose: [ "You are a risk analyst looking for potential red flags in a company's outlook.", 'Given background research, produce a short analysis of risks such as competitive threats, regulatory issues, supply chain problems, or slowing growth.', ], routine: ['Keep it under 2 paragraphs.'], }),});
// ✅ Good - specificpurpose: [ 'You are a financial analyst specializing in tech companies.', 'You analyze earnings reports and market trends.',]// ❌ Vaguepurpose: 'You help with finance'
Actionable Routine Steps
Make routine steps concrete and actionable:
// ✅ Good - actionableroutine: [ 'Read the user\'s question carefully', 'Search for relevant documentation', 'Provide code examples from the docs', 'Verify the examples work',]// ❌ Vagueroutine: ['Help the user', 'Do a good job']