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: Coordinator β†’ ResearchAgent β†’ FactCheckerAgent β†’ WriterAgent
Each 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 flowOrchestrator picks ONE branchALL stages run in fixed sequence
Data flowUser input β†’ specialist β†’ userEach stage builds on the last
OrchestrationLLM decides routing dynamicallyCode controls stage order explicitly
Best forClassification and delegationMulti-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 β€” FactCheckerAgent and ResearchAgent can be composed into other pipelines without modification.

Next Steps