Lesson 2 of 6·10 min read

Defining Agent Roles

The key to a successful multi-agent system lies in clearly defining agent roles. Each agent needs a precise task, a defined input/output contract, and a specialized prompt. Poorly defined roles lead to overlaps, conflicts, and inconsistent results.

The Three Core Roles

1. Researcher Agent

The researcher collects and structures information. It serves as the system's knowledge base.

System prompt (example):

You are a research specialist. Your task:
- Collect relevant information on the given topic
- Structure results into clear sections
- Rate the reliability of each source (1-5)
- Explicitly flag uncertainties

Output format: JSON with { "findings": [], "confidence": 0-100, "gaps": [] }

2. Writer Agent

The writer creates content based on the researcher's findings.

System prompt (example):

You are a content writer. Your task:
- Create well-structured texts based on research data
- Keep the tone professional and accessible
- Use subheadings and bullet points
- Maximum length: 800 words

Input: Research results (JSON)
Output: Formatted text (Markdown)

3. Reviewer Agent

The reviewer checks quality and provides feedback.

System prompt (example):

You are a quality reviewer. Your task:
- Check factual accuracy against research data
- Evaluate style, structure, and completeness
- Provide concrete, actionable feedback
- Decide: APPROVE, REVISE (with notes), or REJECT

Output format: JSON with { "decision": "", "score": 0-100, "feedback": [] }

Role-Based Prompt Engineering

Effective agent prompts follow the RACE Framework:

ElementDescriptionExample
RoleWho is the agent?"You are a financial analyst"
ActionWhat should it do?"Analyze the quarterly figures"
ContextWhat constraints apply?"For a Fortune 500 company, in English"
ExpectationWhat does the result look like?"JSON with metrics and assessment"

Specialist Agents for Extended Pipelines

Beyond the three core roles, you can deploy specialized agents:

AgentTaskTrigger
ValidatorSchema and format checkingAfter each agent output
TranslatorMultilingual outputAfter the writer
SummarizerSummarize lengthy resultsBefore the end user
RouterDecides which agent acts nextDynamic pipelines
GuardrailChecks for compliance and safetyBefore output

Input/Output Contracts

Define a clear contract for each agent:

{
  "agent": "researcher",
  "input_schema": {
    "topic": "string (required)",
    "depth": "shallow | medium | deep",
    "max_sources": "number (default: 5)"
  },
  "output_schema": {
    "findings": "array of { title, content, source, confidence }",
    "overall_confidence": "number 0-100",
    "knowledge_gaps": "array of string"
  },
  "constraints": {
    "max_tokens": 2000,
    "timeout_seconds": 30
  }
}

Practical tip: Start with three agents (researcher, writer, reviewer) and expand incrementally. Each new agent increases complexity exponentially. Document input/output contracts in a shared schema — this saves debugging time and makes agents interchangeable.