n4nAI

What is LlamaIndex? A guide to agent workflows

LlamaIndex is a data framework for LLM apps. This guide explains what it is, how agents and workflows operate, with code and common misconceptions.

n4n Team4 min read824 words

Audio narration

Coming soon — every post will get a voice note here.

LlamaIndex is a Python and TypeScript framework that bridges LLMs and external data via indexing, retrieval, and agent orchestration. When engineers ask what is llamaindex, they are usually looking for a system that handles document ingestion, embedding, and multi-step reasoning without hand-rolling pipelines.

How LlamaIndex works

At its core, LlamaIndex transforms raw data into structures an LLM can efficiently consume. The framework splits documents into nodes, embeds them, and stores them in a vector index or graph. A query engine then retrieves relevant context and synthesizes an answer.

Data connectors and transformations

Ingestion starts with a Reader that returns Document objects. SimpleDirectoryReader covers PDFs, Markdown, and HTML. Documents are parsed into Node objects by a TransformComponent such as SentenceSplitter.

from llama_index.core import SimpleDirectoryReader, SentenceSplitter

docs = SimpleDirectoryReader("policies/").load_data()
splitter = SentenceSplitter(chunk_size=512, chunk_overlap=64)
nodes = splitter.get_nodes_from_documents(docs)

Each node carries metadata (source file, page, tags). This metadata drives filtered retrieval later. Understanding this pipeline is part of answering what is llamaindex at the data layer.

Indexes and query engines

The simplest path is a VectorStoreIndex. You build the index from nodes, then query it.

from llama_index.core import VectorStoreIndex

index = VectorStoreIndex(nodes)
query_engine = index.as_query_engine(similarity_top_k=3)
response = query_engine.query("What is our refund policy?")
print(response)

This covers retrieval-augmented generation (RAG). But what is llamaindex beyond a wrapper around embeddings? Its value multiplies when you compose multiple indexes, routers, and tools.

Agents and tools

An agent in LlamaIndex is a loop that decides which tools to call based on a user goal. Tools are Python functions exposed with schemas. The agent observes outputs and iterates.

from llama_index.core.agent import ReActAgent
from llama_index.core.tools import FunctionTool

def calculator(expr: str) -> str:
    return str(eval(expr))

calc_tool = FunctionTool.from_defaults(fn=calculator, name="calc")
agent = ReActAgent.from_tools([calc_tool], llm=llm)
agent.chat("What is 12 * (3 + 4)?")

The framework ships ReActAgent, FunctionAgent, and workflow-based orchestration. Workflows let you define explicit state machines instead of relying on the model’s emergent reasoning.

Workflows

A workflow is a directed graph of steps. Each step is a Python function decorated with @step. This is useful when you need deterministic ordering, human-in-the-loop, or parallel fan-out.

from llama_index.core.workflow import Workflow, step, StartEvent, StopEvent

class SupportFlow(Workflow):
    @step
    def classify(self, ev: StartEvent):
        topic = llm.classify(ev.query)
        return {"topic": topic}
    
    @step
    def respond(self, ev: dict):
        return StopEvent(result=generate(ev["topic"]))

This explicit structure answers what is llamaindex in production: a hybrid of declarative data connectors and programmable control flow.

Why it matters for production systems

RAG demos are easy; reliable agent workflows are not. LlamaIndex provides retries, metadata filters, and caching hooks so you don’t rebuild infra per project.

Stateful orchestration

Agents maintain memory across turns. The ChatMemoryBuffer buffers messages, while Context objects pass state between workflow steps. Without these, you write ad-hoc session stores.

Multi-model routing

You can swap the LLM per component. The Settings singleton configures defaults, but each agent or query engine accepts an explicit llm and embed_model. This avoids vendor lock-in.

from llama_index.core import Settings
from llama_index.llms.openai import OpenAI
from llama_index.embeddings.openai import OpenAIEmbedding

Settings.llm = OpenAI(model="gpt-4o-mini")
Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")

A concrete example: building a support agent

Assume a folder of policy PDFs and a requirement to answer user questions with citations. We combine a vector index, a web search tool, and a workflow that checks the KB first.

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.core.agent import ReActAgent
from llama_index.core.tools import FunctionTool

docs = SimpleDirectoryReader("policies/").load_data()
kb_index = VectorStoreIndex.from_documents(docs)
kb_engine = kb_index.as_query_engine(response_mode="compact")

def kb_query(q: str) -> str:
    return str(kb_engine.query(q))

kb_tool = FunctionTool.from_defaults(fn=kb_query, name="policy_search")
agent = ReActAgent.from_tools([kb_tool], llm=llm, verbose=True)

result = agent.chat("Can I return an item after 60 days?")

The agent retrieves policy text, reasons about the date, and responds. If the KB lacks info, you add a second tool. That extensibility is the practical answer to what is llamaindex for a team shipping internal tooling.

Common misconceptions

It’s just a RAG library

Early versions focused on indexing, but the current codebase includes agents, workflows, evaluation, and observability. Treating it as only a vector store frontend undersells the orchestration layer.

It locks you into OpenAI

The llm and embed_model interfaces are pluggable. Community integrations cover Anthropic, Mistral, local HuggingFace models, and OpenAI-compatible servers. You can run entirely on self-hosted vLLM.

Agents are magic

A ReAct loop is just prompt engineering plus tool schemas. If your tools are poorly defined, the agent fails silently. LlamaIndex gives you the scaffolding, not the intelligence.

Workflows replace agents

They complement each other. Use workflows for fixed business logic; use agents when the path is unknown. A support system might use a workflow to triage, then hand off to an agent for open-ended research.

Observability and evaluation

LlamaIndex emits events through a CallbackManager. You can log token usage, latency, and node scores to Langfuse or Phoenix. For evaluation, the llama_index.core.evaluation module provides answer relevance and faithfulness checks.

from llama_index.core.evaluation import FaithfulnessEvaluator

evaluator = FaithfulnessEvaluator(llm=llm)
eval_result = evaluator.evaluate_response(response=response)
print(eval_result.passing)

This closes the loop: build, serve, measure, tune.

Production considerations: model routing and fallback

When you deploy agent workflows, model uptime becomes a dependency. Pointing Settings.llm at a single provider means a 429 error breaks the flow. An OpenAI-compatible inference gateway such as n4n.ai addresses 240+ models behind one endpoint and applies automatic fallback when a provider is rate-limited, which lets you keep the LlamaIndex code unchanged while gaining resilience.

from llama_index.llms.openai import OpenAI

# Point to gateway instead of api.openai.com
Settings.llm = OpenAI(
    api_base="https://api.n4n.ai/v1",
    api_key="your-key",
    model="auto"  # gateway routes to available provider
)

The gateway forwards cache-control hints and meters per-token usage, so you get provider diversity without custom middleware. That’s a concrete way to harden what is llamaindex-based services without forking the framework.

Getting started

Install the core package and a provider:

pip install llama-index-core llama-index-llms-openai

Load data, build an index, and query. From there, graduate to agents and workflows as requirements demand. The framework’s documentation splits cleanly into data connectors, indexes, agents, and workflows—read the module you need, ignore the rest.

Key takeaways

  • LlamaIndex is a data and orchestration layer for LLM apps, not just a RAG helper.
  • Agents and workflows provide programmable control over model reasoning.
  • Tools are typed functions; good schemas make or break agent reliability.
  • Model routing belongs at the infrastructure edge; keep framework code provider-agnostic.

That’s the engineering-oriented answer to what is llamaindex and how it fits agent workflows.

Tagsllamaindexai-agentsagent-frameworksrag

Written by

n4n Team

The team building n4n — a single OpenAI-compatible API in front of 240+ models, with automatic fallback, load balancing and pay-per-token metering.

More from n4n Team →

All llamaindex agents & workflows posts →