LlamaIndex

LlamaIndex Agents

Agents that reason over your Data (RAG).

1. The ReAct Agent

The standard reasoning loop: Thought -> Action -> Observation.

from llama_index.core.agent import ReActAgent
from llama_index.llms.openai import OpenAI

llm = OpenAI(model="gpt-4")
agent = ReActAgent.from_tools(
    [my_tool_1, my_tool_2], 
    llm=llm, 
    verbose=True
)
agent.chat("Compare the revenue of Apple and Google.")

Technique: Turning Data into Tools

LlamaIndex's unique power: Wrapping a Vector Search as a Tool.

from llama_index.core.tools import QueryEngineTool, ToolMetadata

# Assume 'finance_engine' is a RAG pipeline over 1000 PDFs
finance_tool = QueryEngineTool(
    query_engine=finance_engine,
    metadata=ToolMetadata(
        name="finance_db",
        description="Detailed financial reports for 2024."
    )
)

agent = ReActAgent.from_tools([finance_tool], llm=llm)
# Now the agent can 'query' your PDFs to answer questions.

Technique: Event-Driven Workflows

New in v0.10. Similar to LangGraph.

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

class MyFlow(Workflow):
    @step
    async def step_one(self, ev: StartEvent) -> StopEvent:
        print("Processing...")
        return StopEvent(result="Done")

w = MyFlow(timeout=10, verbose=True)
await w.run()