Building Workflows

Building Workflows

Create powerful AI applications by combining components.

Workflow Patterns

Simple Chain

The most basic pattern:

Input → LLM → Output

Use for: Simple Q&A, text generation

Chain with Context

Add context to improve responses:

Input → Prompt Template → LLM → Output
              ↑
        System Message

Use for: Specialized assistants, role-playing

RAG (Retrieval-Augmented Generation)

Ground responses in your data:

Input → Retriever → Prompt → LLM → Output
            ↑
      Vector Store

Use for: Q&A over documents, knowledge bases

Agent with Tools

Let the AI use tools:

Input → Agent → Output
          ↓
   [Search, Calculator, Database]

Use for: Complex tasks requiring external actions

Multi-Agent

Multiple specialized agents:

Input → Router → Agent A → Combiner → Output
           ↓
         Agent B

Use for: Complex workflows with different specialties

Building a RAG Pipeline

Step 1: Prepare Documents

Add document loading:

  1. Add Document Loader component
  2. Configure for your file type
  3. Connect to Text Splitter
  4. Splitter outputs document chunks

Step 2: Create Embeddings

Convert text to vectors:

  1. Add Embeddings component (OpenAI or local)
  2. Connect Text Splitter → Embeddings
  3. Embeddings outputs vector representations

Step 3: Set Up Vector Store

Store the vectors:

  1. Add Vector Store (Chroma for local)
  2. Connect Embeddings → Vector Store
  3. Vector Store is now searchable

Step 4: Build Retriever

Search for relevant content:

  1. Add Retriever component
  2. Connect to Vector Store
  3. Configure k (number of results)

Step 5: Create RAG Chain

Combine retrieval with generation:

  1. Add Prompt Template:
Use the following context to answer:
{context}

Question: {question}
  1. Connect: Retriever → context input
  2. Connect: Chat Input → question input
  3. Connect: Prompt → LLM → Output

Complete RAG Flow

Documents → Splitter → Embeddings → Vector Store
                                         ↓
Chat Input → Retriever ← ← ← ← ← ← ← ← ←
      ↓           ↓
      ↓      [context]
      ↓           ↓
      → → → → Prompt → LLM → Chat Output

Building an Agent

Step 1: Define Tools

Add tools the agent can use:

  1. Add Web Search for internet searches
  2. Add Calculator for math
  3. Add Python REPL for code execution

Step 2: Create Agent

  1. Add ReAct Agent component
  2. Connect your tools to the agent
  3. Connect LLM to the agent

Step 3: Configure Agent

Set agent behavior:

  • Max iterations: Limit reasoning steps
  • Early stopping: Stop when answer found
  • Return intermediate: Show reasoning

Step 4: Wire I/O

  1. Connect Chat Input → Agent
  2. Connect Agent → Chat Output

Example Agent Flow

            ┌─ Web Search
            │
Chat Input → ReAct Agent → Chat Output
            │      ↑
            ├─ Calculator
            │      ↑
            └─ Python

Building Conditional Flows

Simple Branching

Route based on input:

Input → Classifier → Branch A → Merge → Output
              ↓
           Branch B

Implementation

  1. Add Conditional component
  2. Set condition: "code" in {input}
  3. True path: Code assistant
  4. False path: General assistant

Multi-Way Routing

For multiple paths:

  1. Use Router component
  2. Define categories
  3. Each category → different chain

Parallel Processing

Run Branches Simultaneously

For independent operations:

        ┌→ Analysis A →┐
Input → ┼→ Analysis B →┼→ Combiner → Output
        └→ Analysis C →┘

Implementation

  1. Split input to multiple chains
  2. Each chain processes independently
  3. Combiner merges results

Loops and Iteration

Self-Improving Responses

  1. Initial response from LLM
  2. Critique by second LLM
  3. Revise based on critique
  4. Output final version
Input → LLM₁ → Critic → [needs revision?] → LLM₂ → Output
                              ↓
                          Output

Variables and State

Using Variables

Pass data between components:

  1. Define input variables in Prompt
  2. Map connections to variables
  3. Variables populate at runtime

State Management

For complex state:

  1. Use Memory components
  2. Store intermediate results
  3. Access across the flow

Best Practices

Keep It Simple

  • Start with minimal components
  • Add complexity incrementally
  • Test at each step

Name Your Components

  • Rename from defaults
  • Use descriptive names
  • Makes debugging easier

Document Your Flows

  • Add comments to components
  • Write flow descriptions
  • Note any non-obvious logic

Handle Errors

  • Add error handling paths
  • Set timeouts appropriately
  • Log for debugging

Optimize for Cost

  • Use cheaper models where possible
  • Cache repeated operations
  • Limit token usage

Common Issues

Circular Dependencies

Problem: A → B → A creates infinite loop

Solution: Ensure flows are directed (no cycles)

Missing Connections

Problem: Component shows error, not connected

Solution: Check all required inputs have connections

Type Mismatches

Problem: Connection shows incompatible

Solution: Check output/input types match

Token Limits

Problem: Response truncated

Solution:

  • Reduce context size
  • Summarize long inputs
  • Use larger context model