0
Phase 8

LlamaIndex Workflows

~3 min read

Concept & How It Works

    Why Does It Exist?

    RAG agents need retrieval, reranking, synthesis, and validation as distinct steps. Workflows make each step testable and replace implicit chain logic with explicit event handlers.

    Real-World Analogy

    LlamaIndex Workflows are a factory assembly line with sensors: each station emits a signal (event) when done, triggering the next machine.
    Loading diagram...

    Visual Workflows

    What is LlamaIndex Workflows?

    Loading diagram...

    Example

    Scenario

    Query workflow: `QueryEvent` → retrieve chunks → `RetrieveEvent` → rerank → `SynthesizeEvent` → answer with citations.

    Solution

    In Agent Frameworks, apply LlamaIndex Workflows to this scenario: Query workflow: `QueryEvent` → retrieve chunks → `RetrieveEvent` → rerank → `SynthesizeEvent` → answer with citations. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.

    Practice Task

    Do this before moving to the next module — reading alone is not enough.

    Open the Code Walkthrough below and run it locally. Change one parameter related to LlamaIndex Workflows (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.

    Code Walkthrough

    Highlighted lines show where LlamaIndex Workflows happens in the code.

    LlamaIndex Workflows
    1from llama_index.core.workflow import Workflow, step, StartEvent, StopEvent, Event  # import dependencies2
    3class QueryEvent(Event):  # define a data structure or component4    query: str5
    6class AnswerEvent(Event):  # define a data structure or component7    answer: str8
    9class RAGWorkflow(Workflow):  # define a data structure or component10    @step11    async def retrieve(self, ev: StartEvent) -> QueryEvent:12        return QueryEvent(query=ev.query)  # return the result13
    14    @step15    async def synthesize(self, ev: QueryEvent) -> StopEvent:16        return StopEvent(result=AnswerEvent(answer="..."))  # return the result

    Commands to Remember

    Commands to Remember

    • pip install langgraph langchain-openai # LangGraph agent framework
    • pip install openai-agents # OpenAI Agents SDK
    • pip install crewai # multi-agent CrewAI framework

    Common Mistakes

    • Treating LlamaIndex Workflows as a black box without evaluation
    • Ignoring cost and latency in production
    • Skipping error handling for llamaindex workflows

    Cheat Sheet

    Quick recap — the most important points from this module.

    Cheat Sheet

    quick ref
    • LlamaIndex Workflows
    • Event
    • @step
    • Context