Building Agentic Pipelines

Introduction to Agentic Patterns

Welcome to the next step of your journey towards building effective agents! In our previous courses, you've built a solid foundation by exploring basic workflows with simple LLM calls, then progressing to integrate tools and create autonomous agents that can make decisions and execute tasks independently.Now we're taking the next major leap: agentic patterns. These are sophisticated workflows that leverage the power of autonomous agents working together in coordinated ways to solve complex problems.

In this lesson, we'll focus on agentic pipelines — one of the most fundamental and powerful agentic patterns. You'll learn how to design specialized agents, connect them in sequence, and create workflows where each agent contributes its unique expertise to produce comprehensive solutions. By the end of this lesson, you'll have built a complete three-agent pipeline that can tackle complex multi-step mathematical problems with remarkable clarity and precision.

What Are Agentic Pipelines?

An agentic pipeline is a workflow where multiple specialized autonomous agents work together in sequence, with each agent performing its specific role before passing the results to the next agent in the chain. This differs fundamentally from simple LLM prompt chaining in several crucial ways.

In basic prompt chaining, you send a series of prompts to an LLM, where each prompt builds on the previous response. The LLM processes each prompt independently without specialized context, tools, or persistent expertise. It's like asking the same person to wear different hats for each task — they might do okay, but they're not truly specialized.

Agentic pipelines, however, use autonomous agents that are each designed with specific expertise, dedicated tools, and focused system prompts. Each agent can perform multiple internal steps, make decisions about how to approach their part of the problem, and use tools autonomously. Importantly, within the pipeline, a single agent might take several internal steps — analyzing, planning, using tools, and refining its approach — before generating a final result that gets chained to the next agent. This means each stage of the pipeline can be as sophisticated as needed, while the overall flow remains clean and manageable.

Agent Specialization Principles

The foundation of effective agentic pipelines lies in proper agent specialization. Each agent should be designed as an expert in its specific domain, with clear boundaries about what it should and shouldn't do. This specialization is what transforms a simple sequence of LLM calls into a powerful, coordinated system.

When designing specialized agents, follow these key principles:

  • Single Responsibility: Each agent should have one clear, focused role and excel at that specific task
  • Appropriate Tools: Provide only the tools that are relevant to the agent's specific function
  • Focused System Prompt: Write system prompts that clearly define what the agent should do, what it should avoid, and how it should format outputs
  • Clear Boundaries: Explicitly state what the agent should not attempt, preventing scope creep
  • Output Formatting: Ensure each agent's output is structured to work seamlessly with the next agent in the pipeline

This separation of concerns makes each agent more reliable and the overall system easier to debug and maintain. The system prompt is particularly crucial for specialization, as it acts like a job description that keeps the agent focused on its expertise while ensuring its outputs integrate smoothly with the rest of the pipeline.

What We'll Build

In this lesson, we'll construct a sophisticated three-agent pipeline that can solve complex multi-step mathematical problems. Our pipeline will consist of:

  1. Problem Analyzer Agent - Breaks down complex problems into clear, sequential steps
  2. Calculator Agent - Executes mathematical operations using specialized tools
  3. Solution Presenter Agent - Formats results into educational, easy-to-understand solutions

By the end, you'll see how three specialized agents working together can produce more comprehensive and reliable results than a single general-purpose agent attempting to handle everything at once.

Setting Up Tools and Agent Class

Before we build our pipeline agents, let's quickly set up the necessary imports and tools:

import json
from agent import Agent
from functions import sum_numbers, multiply_numbers, subtract_numbers, divide_numbers, power, square_root

# Load tool schemas
with open('schemas.json', 'r') as f:
    tool_schemas = json.load(f)

# Math tools
math_tools = {
    "sum_numbers": sum_numbers,
    "multiply_numbers": multiply_numbers,
    "subtract_numbers": subtract_numbers,
    "divide_numbers": divide_numbers,
    "power": power,
    "square_root": square_root
}

Now we're ready to build our specialized agents for the pipeline.

Building the Problem Analyzer Agent

Let's start building our pipeline with the first agent — the Problem Analyzer. This agent's job is to take complex problems and break them down into clear, actionable steps without performing any calculations itself.

# Agent 1: Problem Analyzer
problem_analyzer = Agent(
    name="problem_analyzer",
    system_prompt=(
        "You are a mathematical problem analyzer. Your job is to:\n"
        "1. Break down complex math problems into clear, sequential steps\n"
        "2. Identify what calculations are needed at each step\n"
        "3. Output a structured plan that another agent can follow to perform "
        "calculations\n"
        "4. Do NOT perform the actual calculations - just create the "
        "step-by-step plan"
    )
)

Notice how this agent has no tools at all — this is intentional because we want it to focus purely on analysis and planning. The system prompt explicitly tells it not to perform calculations, which helps maintain clear boundaries between agents. This focused approach ensures our analyzer will create structured plans that the next agent can easily follow.

Building the Calculator Agent

The second agent in our pipeline is the Calculator Agent, which takes the analysis plan and executes all the mathematical operations using the available tools.

# Agent 2: Calculator Agent
calculator_agent = Agent(
    name="calculator_agent",
    system_prompt=(
        "You are a calculator agent. Your job is to:\n"
        "1. Take a step-by-step calculation plan\n"
        "2. Execute each calculation using your available math tools\n"
        "3. Show your work clearly for each step\n"
        "4. Provide the numerical results in a structured format"
    ),
    tools=math_tools,
    tool_schemas=tool_schemas,
)

This agent has access to all the mathematical tools (sum_numbers, multiply_numbers, subtract_numbers, etc.), but its system prompt focuses it on execution rather than planning. The emphasis on showing work and providing structured results ensures the next agent in the pipeline has clear information to work with.

Building the Solution Presenter Agent

The final agent in our pipeline is the Solution Presenter, which takes the raw calculation results and formats them into a clear, educational solution that's easy to understand.

# Agent 3: Solution Presenter
solution_presenter = Agent(
    name="solution_presenter",
    system_prompt=(
        "You are a solution presenter. Your job is to:\n"
        "1. Take calculation results and present them as a complete, "
        "educational solution\n"
        "2. Explain what each step accomplished and why it was necessary\n"
        "3. Provide the final answer clearly\n"
        "4. Make the solution easy to understand for someone learning math"
    )
)

Like the Problem Analyzer, this agent has no tools because its job is purely communicative. It focuses on taking technical calculation results and transforming them into human-friendly explanations that emphasize educational value. Now that we have our three specialized agents, let's see how they connect together in our pipeline.

Stage 1: Problem Analysis

Let's start our pipeline by running the Problem Analyzer agent with a complex mathematical problem:

# Define our complex problem
complex_problem = """
A rectangular garden is 12 meters long and 8 meters wide. 
How much fencing is needed to go around the perimeter? 
Also, if grass seed is needed at a rate of 0.25 kg per square meter, 
how much grass seed is required for the entire garden?
"""

# Create the initial message with the complex problem for the analyzer
analysis_messages = [{"role": "user", "content": complex_problem}]

# Run the problem analyzer to break down the problem into steps
analysis_messages, analysis_output = problem_analyzer.run(analysis_messages)

# Display the analysis output
print(analysis_output)

Remember that the run method of our Agent class returns two values: the updated message history (useful for continuing conversations with the same agent, though we won't need that in this pipeline example since each agent is used once), and the final text output that we'll pass to the next stage.

When we run this first stage, the Problem Analyzer breaks down our multi-step problem into a clear, structured plan:

I'll break down this multi-part problem into a clear, sequential plan for solving it step by step.

## Problem Analysis and Step-by-Step Plan

**Given Information:**
- Rectangular garden dimensions: 12 meters long × 8 meters wide
- Grass seed requirement: 0.25 kg per square meter
- Need to find: Total amount of grass seed required

**Sequential Solution Plan:**

### Step 1: Calculate the Perimeter
- **Task:** Find the perimeter of the rectangular garden
- **Formula to use:** Perimeter = 2 × (length + width)
- **Calculation needed:** 2 × (12 + 8)
- **Purpose:** This answers the fencing question

### Step 2: Calculate the Area
- **Task:** Find the area of the rectangular garden
- **Formula to use:** Area = length × width
- **Calculation needed:** 12 × 8
- **Purpose:** This gives us the total area that needs grass seed

### Step 3: Calculate Total Grass Seed Required
- **Task:** Determine total seed needed based on area and seed rate
- **Formula to use:** Total seed = Area × seed rate per square meter
- **Calculation needed:** (Result from Step 2) × 0.25
- **Purpose:** This gives the final answer in kilograms

**Expected Output Units:**
- Step 1: Perimeter in meters
- Step 2: Area in square meters
- Step 3: Total seed in kilograms

This plan will systematically solve all parts of the problem: perimeter for fencing, area calculation, and finally the grass seed requirement.

Notice how the Problem Analyzer successfully identified all the necessary steps and formulas without performing any calculations. This structured plan now becomes the input for our Calculator Agent in the next stage.

Stage 2: Mathematical Calculations

Now we pass the analysis plan to our Calculator Agent to execute all the mathematical operations:

# Pass the analysis plan to the calculator agent for execution
calculation_messages = [
    {
        "role": "user",
        "content": (
            "Execute this calculation plan: "
            f"{analysis_output}"  # Insert the step-by-step plan from stage 1
        ),
    }
]

# Run the calculator agent to perform all mathematical operations
calculation_messages, calculation_output = calculator_agent.run(calculation_messages)

# Display the calculation final output
print(calculation_output)

The Calculator Agent takes the structured plan and methodically executes each calculation using its mathematical tools:

🔧 Tool called: sum_numbers({'a': 12, 'b': 8})
🔧 Tool called: multiply_numbers({'a': 2, 'b': 20})
🔧 Tool called: multiply_numbers({'a': 12, 'b': 8})
🔧 Tool called: multiply_numbers({'a': 96, 'b': 0.25})

## Final Results Summary

**Step 1: Perimeter Calculation**
- Formula: 2 × (12 + 8) = 2 × 20 = 40
- **Perimeter: 40 meters**

**Step 2: Area Calculation**
- Formula: 12 × 8 = 96
- **Area: 96 square meters**

**Step 3: Grass Seed Requirement**
- Formula: 96 × 0.25 = 24.0
- **Total grass seed needed: 24.0 kilograms**

The rectangular garden has a perimeter of 40 meters (for fencing purposes), covers an area of 96 square meters, and will require exactly 24 kilograms of grass seed at the rate of 0.25 kg per square meter.

Notice how the tool logs show exactly which mathematical functions were called during the calculation process. The Calculator Agent successfully executed all the mathematical operations using its tools and provided clear numerical results. These calculation results now flow to our final agent for presentation.

Stage 3: Solution Presentation

Finally, we use the Solution Presenter to format the results into a comprehensive, educational solution:

# Combine original problem and calculation results for final presentation
presentation_prompt = (
    "Present this solution clearly based on the original problem and "
    "calculations:\n\n"
    f"Original Problem: {complex_problem}\n\n"    # Provide context
    f"Calculation Results: {calculation_output}"  # Include all calculations
)

# Create the final message for the solution presenter
presentation_messages = [{"role": "user", "content": presentation_prompt}]

# Run the solution presenter to create the final educational output
presentation_messages, presentation_output = solution_presenter.run(presentation_messages)

# Display the final output
print(presentation_output)

The Solution Presenter transforms the raw calculations into a polished, educational explanation:

# Complete Solution: Garden Fencing and Grass Seed Calculation

## Problem Overview
We need to solve a multi-step problem involving a rectangular garden that is **12 meters long** and **8 meters wide**. The goal is to:
1. Calculate the perimeter (for fencing)
2. Calculate the area 
3. Determine total grass seed needed

---

## Step-by-Step Solution

### Step 1: Calculate the Perimeter (for fencing)
**Why this step:** We need to know how much fencing is required to go around the entire garden.

**Formula:** Perimeter of rectangle = 2 × (length + width)

**Calculation:**
- Perimeter = 2 × (12 + 8)
- Perimeter = 2 × 20
- **Perimeter = 40 meters**

This means you'll need **40 meters of fencing** to enclose the garden completely.

### Step 2: Calculate the Area
**Why this step:** We need the total surface area to determine how much grass seed is required.

**Formula:** Area of rectangle = length × width

**Calculation:**
- Area = 12 × 8
- **Area = 96 square meters**

The garden covers **96 square meters** of ground space.

### Step 3: Calculate Grass Seed Requirements
**Why this step:** Each square meter needs a specific amount of seed, so we multiply the total area by the seed rate.

**Given:** 0.25 kg of seed per square meter
**Formula:** Total seed = Area × seed rate per square meter

**Calculation:**
- Total seed needed = 96 × 0.25
- **Total seed needed = 24.0 kilograms**

---

## Final Answer
For your 12m × 8m rectangular garden, you will need:
- **40 meters of fencing** to enclose the perimeter
- **24 kilograms of grass seed** to cover the entire area at the rate of 0.25 kg per square meter

The garden has a total area of 96 square meters, which, when multiplied by the seeding rate, gives us exactly 24 kg of grass seed needed.

This final stage demonstrates how the Solution Presenter takes technical calculation results and transforms them into a clear, educational explanation that shows the reasoning behind each step. Our three-agent pipeline has successfully tackled a complex multi-step problem through specialized collaboration, with each agent contributing its unique expertise to produce a comprehensive solution.

Reflecting on Pipeline Architecture

Notice what we accomplished architecturally: we defined a simple three-stage sequence (analyze → calculate → present), while each agent handled significant internal complexity we didn't need to manage. The Calculator Agent made multiple tool calls and formatting decisions internally, but we only orchestrated the high-level flow between agents.

This separation of orchestration from execution makes complex problems manageable — you focus on workflow while each agent handles its domain expertise.

We could specialize our agents further with additional tools:

  • Problem Analyzer: formula lookup tools, problem-type databases
  • Calculator Agent: unit conversion, statistical functions, graphing tools
  • Solution Presenter: diagram generation, readability checkers, LaTeX formatting

More specialized tools make each agent more capable within its domain, while keeping the overall pipeline structure clean and understandable.

Summary and Next Steps

You've now mastered the fundamentals of agentic pipelines by building specialized agents that work together in sequence. This pipeline pattern breaks complex problems into manageable pieces, makes systems easier to debug, and allows each agent to excel at its specific task.

In the upcoming practice exercises, you'll build your own agentic pipeline. The three-agent math pipeline you've learned here will serve as your foundation for creating much more sophisticated agentic systems!

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal