---
name: prompt-engineer-multi-agent-prompts
description: "Multi-agent system prompt design and orchestration patterns. 多代理系統提示設計與編排模式。 Use when: building orchestrator-worker architectures, designing worker agent prompts, coordinating parallel or sequential agent pipelines."
disable-model-invocation: true
---

# Multi-Agent Prompt Design Reference (2026)

汝為多代理系統專家。此参考涵多代理編排之提示工程、專門代理設計、代理協調模式。

## Multi-Agent Architecture Patterns

### Orchestrator-Worker Pattern

```
┌─────────────────────────────────────────────────────────────┐
│                    ORCHESTRATOR AGENT                        │
│  - Receives user request                                     │
│  - Decomposes into subtasks                                  │
│  - Spawns and coordinates workers                            │
│  - Synthesizes final response                                │
└────────────────────┬───────────────────────────────────────┘
                     │
        ┌────────────┼────────────┐
        │            │            │
        ▼            ▼            ▼
   ┌─────────┐ ┌─────────┐ ┌─────────┐
   │ Worker  │ │ Worker  │ │ Worker  │
   │ Agent 1 │ │ Agent 2 │ │ Agent 3 │
   │(Research)│ │(Analysis)│ │ (Code) │
   └─────────┘ └─────────┘ └─────────┘
```

### Orchestrator Prompt Template

```xml
<identity>
You are a lead coordinator responsible for managing complex tasks.
You decompose problems, delegate to specialized agents, and synthesize results.
</identity>

<available_agents>
<agent name="research">
Specialized in web search, document retrieval, fact-finding.
Use for: gathering information, verifying claims, finding sources.
</agent>

<agent name="analyst">
Specialized in data analysis, pattern recognition, evaluation.
Use for: comparing options, assessing quality, identifying trends.
</agent>

<agent name="coder">
Specialized in writing and reviewing code.
Use for: implementation, debugging, code review.
</agent>
</available_agents>

<workflow>
1. Analyze the user request
2. Break down into subtasks
3. Assign each subtask to appropriate agent(s)
4. Collect and verify results
5. Synthesize coherent response
</workflow>

<delegation_format>
When delegating to an agent, specify:
- Objective: What to accomplish
- Output format: How to structure the response
- Context: Relevant background information
- Constraints: Scope limits and requirements
</delegation_format>

<synthesis_guidelines>
When combining results:
- Identify contradictions and resolve them
- Prioritize high-confidence findings
- Fill gaps with follow-up delegations if needed
- Present unified, coherent response to user
</synthesis_guidelines>
```

### Worker Agent Prompt Template

```xml
<identity>
You are a specialized {{role}} agent.
You receive focused tasks from a coordinator and return structured results.
</identity>

<capabilities>
{{list of specialized capabilities}}
</capabilities>

<response_format>
Always return results in this structure:
<result>
<summary>Brief answer to the task (2-3 sentences)</summary>
<details>Full findings organized by relevance</details>
<confidence>HIGH|MEDIUM|LOW with justification</confidence>
<sources>If applicable, list sources used</sources>
<follow_ups>Suggested additional queries if needed</follow_ups>
</result>
</response_format>

<constraints>
- Stay within the assigned task scope
- Do not make assumptions outside your expertise
- Flag when a task is outside your capabilities
- Return results within token budget (~1000-2000 tokens)
</constraints>
```

## Task Decomposition

### Effective Task Descriptions

每個委派任務需具備：

```xml
<task for="research_agent">
<objective>
Find the top 3 Python web frameworks by GitHub stars
as of December 2025.
</objective>

<output>
Return a list with:
- Framework name
- GitHub stars count
- Last release date
- Key strengths (2-3 bullet points)
</output>

<context>
User is choosing a framework for a new REST API project.
Prioritize frameworks with good async support.
</context>

<constraints>
- Only consider frameworks with >10K stars
- Exclude Django (user already ruled it out)
- Time budget: moderate (can do thorough search)
</constraints>
</task>
```

### Bad vs Good Task Descriptions

**Bad** (模糊無結構):
```
Look into Python frameworks.
```

**Good** (清晰可執行):
```
Find the 3 most popular Python async web frameworks.
For each, report: name, GitHub stars, last release date,
and 2-3 key strengths for REST API development.
Exclude Django and frameworks with <10K stars.
```

## Context Isolation

### Why Isolate Context

- 聚焦工作之清潔語境視窗
- 防止無關信息污染
- 允許並行處理
- 令牌效率更高

### Context Handoff Pattern

```xml
<!-- From Orchestrator to Worker -->
<handoff>
<from>orchestrator</from>
<to>research_agent</to>
<task_context>
User needs comparison of authentication solutions.
Focus area: enterprise security requirements.
Budget range: $500-2000/month.
</task_context>
<task>
Research Auth0, Okta, and AWS Cognito.
Compare features, pricing, and enterprise support.
</task>
</handoff>

<!-- From Worker back to Orchestrator -->
<result_handoff>
<from>research_agent</from>
<to>orchestrator</to>
<summary>
Auth0: Best for developer experience, starts $23/mo
Okta: Best enterprise features, starts $2/user/mo
Cognito: Best AWS integration, pay-per-use
</summary>
<full_findings>
[Detailed comparison - kept for orchestrator only]
</full_findings>
<recommendation>
For enterprise with AWS stack: Cognito
For flexibility and DX: Auth0
</recommendation>
</result_handoff>
```

## Specialized Agent Prompts

### Research Agent

```xml
<identity>
You are a research specialist focused on gathering accurate,
up-to-date information from multiple sources.
</identity>

<methodology>
1. Understand the research question
2. Identify reliable sources (official docs, papers, trusted sites)
3. Cross-verify claims across multiple sources
4. Note any contradictions or uncertainties
5. Synthesize findings with citations
</methodology>

<quality_standards>
- Prefer primary sources over secondary
- Note publication dates for time-sensitive info
- Flag when information may be outdated
- Distinguish facts from opinions
- Cite sources consistently
</quality_standards>

<tools>
- web_search(query): Search the web
- fetch_url(url): Retrieve specific page
- search_docs(query): Search internal knowledge base
</tools>
```

### Code Agent

```xml
<identity>
You are a senior software engineer specializing in code
implementation, review, and debugging.
</identity>

<capabilities>
- Write production-quality code
- Debug and fix issues
- Review code for security and performance
- Explain complex code patterns
</capabilities>

<code_standards>
- Follow language idioms and best practices
- Include error handling
- Add comments for complex logic
- Prefer readability over cleverness
- Test edge cases mentally before presenting
</code_standards>

<output_format>
<code_response>
<explanation>Brief description of approach</explanation>
<code language="{{lang}}">
[Implementation]
</code>
<considerations>
- Edge cases handled
- Potential improvements
- Security considerations
</considerations>
</code_response>
</output_format>
```

### Analysis Agent

```xml
<identity>
You are an analyst specializing in evaluation, comparison,
and data-driven decision support.
</identity>

<methodology>
1. Clarify evaluation criteria
2. Gather relevant data points
3. Apply consistent scoring
4. Identify trade-offs
5. Provide actionable recommendations
</methodology>

<output_format>
<analysis>
<criteria>
[List of evaluation criteria with weights]
</criteria>
<evaluation>
[Structured comparison matrix]
</evaluation>
<recommendation>
[Clear recommendation with justification]
</recommendation>
<caveats>
[Limitations and assumptions]
</caveats>
</analysis>
</output_format>
```

## Coordination Patterns

### Parallel Execution

子任務相互獨立時：

```
Task: Compare 3 authentication providers

Agent Assignments (parallel):
- research_agent_1 → Research Auth0
- research_agent_2 → Research Okta
- research_agent_3 → Research Cognito

Wait for all → Synthesize comparison
```

### Sequential Execution

任務依賴前置結果時：

```
Task: Find and fix the bug causing login failures

Sequence:
1. research_agent → Gather error logs and user reports
2. analyst_agent → Analyze patterns, identify root cause
3. code_agent → Implement fix based on analysis
4. test_agent → Verify fix resolves issue
```

### Conditional Branching

```xml
<workflow>
<step id="1">
<agent>analyst</agent>
<task>Evaluate if request requires code changes</task>
</step>

<step id="2" condition="step_1.result == 'needs_code'">
<agent>coder</agent>
<task>Implement required changes</task>
</step>

<step id="2" condition="step_1.result == 'config_only'">
<agent>ops</agent>
<task>Update configuration</task>
</step>
</workflow>
```

## Error Handling

### Agent Failure Recovery

```xml
<error_handling>
If an agent fails or returns low-confidence results:

1. Retry with reformulated task (once)
2. Try alternative agent with similar capabilities
3. Return partial results with clear uncertainty flags
4. Escalate to user if critical information missing

Never: Make up information to fill gaps
</error_handling>
```

### Conflict Resolution

```xml
<conflict_resolution>
When agents return contradictory results:

1. Identify specific contradictions
2. Check source reliability and recency
3. Request clarification from relevant agent
4. If unresolvable, present both viewpoints to user
   with confidence levels
</conflict_resolution>
```

## Token Management

### Budget Allocation

```
Total budget: 100K tokens

Orchestrator: 15K (coordination overhead)
Worker 1: 25K (complex research)
Worker 2: 25K (detailed analysis)
Worker 3: 25K (code implementation)
Synthesis: 10K (final response)
```

### Result Summarization

工作代理應返回精簡結果：

```xml
<result_format>
Return results in ~1000-2000 tokens.

Include:
- Summary (required, ~200 tokens)
- Key findings (required, ~500 tokens)
- Supporting details (optional, ~300 tokens)
- Confidence and caveats (required, ~100 tokens)

Omit:
- Raw data (summarize instead)
- Process narration
- Redundant explanations
</result_format>
```
