Advanced
Real-World
π¬ Research & Report Pipeline
A sequential pipeline where a coordinator passes work through three specialist agents: ResearchAgent β FactCheckerAgent β WriterAgent β each building on the previous output.
The Pipeline pattern differs from the Router pattern: instead of choosing one branch to handle a task, each stage passes its output to the next agent in sequence. This enables quality gates, iterative refinement, and clear separation of concerns across complex multi-step tasks.
ποΈ Pipeline:
Each agent receives the accumulated context from all previous stages.
Coordinator β ResearchAgent β FactCheckerAgent β WriterAgentEach agent receives the accumulated context from all previous stages.
NuGet Packages
dotnet add package Microsoft.Agents.AI.OpenAI --prerelease
dotnet add package Azure.AI.OpenAI --prerelease
dotnet add package Azure.Identity
Full Example β Research & Report Pipeline
using System.ComponentModel;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
// ββ Tool functions (deterministic data retrieval β no LLM needed) ββ
string SearchWeb(
[Description("The search query to find sources about")] string query)
=> $"""
Search results for "{query}":
[1] Nature.com: "Quantum entanglement enables instant correlation across arbitrary distances..."
[2] PhysicsToday: "2023 Nobel Prize awarded for entanglement experiments confirming Bell inequalities..."
[3] ArXiv preprint: "Practical quantum key distribution using entangled photon pairs..."
""";
string FetchArticle(
[Description("The article title or URL to fetch")] string source)
=> $"""
Article content from {source}:
Quantum entanglement is a phenomenon where two particles become correlated such that the
quantum state of each particle cannot be described independently. Measuring one particle
instantly affects the other, regardless of distance. Einstein called this 'spooky action
at a distance'. The 2022 Nobel Prize confirmed this is a real physical effect.
""";
string VerifyClaim(
[Description("The factual claim to verify")] string claim)
=> claim.Contains("Nobel")
? $"β
VERIFIED: The Nobel Prize for quantum entanglement was awarded in 2022 (not 2023). Correction noted."
: $"β
VERIFIED: Claim '{claim}' is consistent with peer-reviewed sources.";
// ββ Azure OpenAI client ββ
var azureClient = new AzureOpenAIClient(
new Uri(Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")!),
new AzureCliCredential());
// ββ Stage 1: Research Agent ββ
// Sub-agent because: needs to reason about which sources are relevant, synthesise multiple results
AIAgent researchAgent = azureClient
.GetChatClient("gpt-4o-mini")
.AsAIAgent(
instructions: """
You are a thorough research specialist. Given a topic:
1. Search for 2-3 relevant sources using your search tool.
2. Fetch the most promising article.
3. Synthesise a structured research summary with:
- Key findings (bullet list)
- Important dates and figures
- Notable controversies or open questions
Output ONLY the research summary β do not write the final article.
""",
name: "ResearchAgent",
description: "Gathers raw research on a topic. Call this first with the topic to investigate.",
tools:
[
AIFunctionFactory.Create(SearchWeb),
AIFunctionFactory.Create(FetchArticle)
]);
// ββ Stage 2: Fact Checker Agent ββ
// Sub-agent because: needs domain reasoning to identify which claims require verification
AIAgent factCheckerAgent = azureClient
.GetChatClient("gpt-4o-mini")
.AsAIAgent(
instructions: """
You are a meticulous fact-checker. Given a research summary:
1. Extract every specific factual claim (dates, names, statistics, attributions).
2. Verify each claim using your verification tool.
3. Return a fact-check report listing:
- Each claim and its verification status (β
Verified / β Disputed / β οΈ Uncertain)
- Any corrections needed
- An overall confidence score (0-100%)
Be strict β flag anything that cannot be confirmed.
""",
name: "FactCheckerAgent",
description: "Verifies factual claims in a research summary. Call this after ResearchAgent with the research output.",
tools:
[
AIFunctionFactory.Create(VerifyClaim)
]);
// ββ Stage 3: Writer Agent ββ
// Sub-agent because: creative reasoning, audience targeting, narrative structure β all need LLM judgment
AIAgent writerAgent = azureClient
.GetChatClient("gpt-4o-mini")
.AsAIAgent(
instructions: """
You are an expert science writer. Given research notes and a fact-check report:
1. Write a polished, engaging article for a general audience (800-1000 words).
2. Structure: Compelling headline β Hook paragraph β Key findings β Context β Implications β Conclusion.
3. Incorporate all fact-checker corrections before writing.
4. Use clear language β no unexplained jargon.
5. End with a "Key Takeaways" box (3 bullet points).
Output ONLY the final article β no commentary about the writing process.
""",
name: "WriterAgent",
description: "Writes a polished article from research notes and fact-check results. Call this last with both previous outputs combined.");
// ββ Coordinator β orchestrates the pipeline explicitly ββ
// Note: the coordinator passes each stage's output to the next stage as context.
// This gives us control over the pipeline order and allows error handling at each stage.
string topic = "quantum entanglement and its real-world applications";
Console.WriteLine($"π Starting research pipeline for: \"{topic}\"");
Console.WriteLine(new string('β', 60));
// Stage 1: Research
Console.WriteLine("\nπ Stage 1: Researching...");
string researchNotes = await researchAgent.RunAsync(
$"Research this topic thoroughly: {topic}");
Console.WriteLine(researchNotes);
// Stage 2: Fact Check β passes Stage 1 output as context
Console.WriteLine("\nβ
Stage 2: Fact checking...");
string factCheckReport = await factCheckerAgent.RunAsync(
$"Fact-check these research notes:\n\n{researchNotes}");
Console.WriteLine(factCheckReport);
// Stage 3: Write β receives BOTH previous outputs
Console.WriteLine("\nβοΈ Stage 3: Writing article...");
string finalArticle = await writerAgent.RunAsync(
$"""
Write an article about: {topic}
Research notes:
{researchNotes}
Fact-check report (incorporate all corrections):
{factCheckReport}
""");
Console.WriteLine("\n" + new string('β', 60));
Console.WriteLine("π FINAL ARTICLE");
Console.WriteLine(new string('β', 60));
Console.WriteLine(finalArticle);
Pipeline Flow
Topic: "quantum entanglement..."
β
βΌ
[ResearchAgent] β SearchWeb(), FetchArticle() tools
β research notes (structured summary)
βΌ
[FactCheckerAgent] β VerifyClaim() tool β receives research notes
β fact-check report (verified claims + corrections)
βΌ
[WriterAgent] β receives BOTH research notes + fact-check report
β
βΌ
Final polished article β
Pipeline vs Router: Key Differences
| Router (Customer Support) | Pipeline (Research) | |
|---|---|---|
| Control flow | Orchestrator picks ONE branch | ALL stages run in fixed sequence |
| Data flow | User input β specialist β user | Each stage builds on the last |
| Orchestration | LLM decides routing dynamically | Code controls stage order explicitly |
| Best for | Classification and delegation | Multi-step refinement workflows |
Why Not Use One Big Agent?
You could ask one agent to "research, fact-check, and write an article" in a single prompt. But splitting into specialist agents gives you:
- Quality gates β the fact-checker runs before the writer, so corrections are incorporated from the start, not bolted on.
- Focused system prompts β the writer has no access to raw search results and can't skip fact-checking. Each agent's context window is clean and relevant.
- Observability β you can log and inspect the output of each stage independently, making debugging and evaluation much easier.
- Reusability β
FactCheckerAgentandResearchAgentcan be composed into other pipelines without modification.
Next Steps
All Examples
- π€ Hello Agent
- π§ Function Tools
- π¬ Multi-Turn Conversations
- β‘ Streaming Responses
- π¦ Structured Output
- π Sequential Workflows
- πΈοΈ Multi-Agent Orchestration
- π¦ Ollama β Local AI
- π₯οΈ LM Studio β Local AI
- π§ Agent Memory
- π RAG
- π MCP Tools
- π OpenTelemetry
- π§ Customer Support Triage
- π¬ Research Pipeline
- π€ Tools vs Sub-Agents
Concepts Used
Pipeline Pattern
AsAIFunction()
Sequential Agents
Context Passing
Quality Gates
π€ Tools vs Sub-Agents Guide π Agents Documentation