> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orq.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LlamaIndex Agents integration

> Connect LlamaIndex Agents to Orq.ai's AI Router for complete observability, built-in reliability, and access to 300+ LLMs across 20+ providers.

<CardGroup cols={1}>
  <Card title="AI Router" icon="arrow-right-arrow-left" href="#ai-router">
    Route your LLM calls through the AI Router with a single base URL change. Zero vendor lock-in: always run on the best model at the lowest cost for your use case.
  </Card>
</CardGroup>

## AI Router

### Overview

LlamaIndex Agents is an agentic framework built on top of LlamaIndex that enables LLMs to reason, use tools, and execute multi-step workflows. By connecting LlamaIndex Agents to Orq.ai's AI Router, you get production-ready agents with enterprise-grade capabilities without changing your existing code.

### Key Benefits

Orq.ai's AI Router enhances your LlamaIndex Agents with:

<CardGroup cols={2}>
  <Card title="Complete Observability" icon="chart-line">
    Track every agent step, tool use, and reasoning trace with detailed analytics
  </Card>

  <Card title="Built-in Reliability" icon="shield-check">
    Automatic fallbacks, retries, and load balancing for production resilience
  </Card>

  <Card title="Cost Optimization" icon="chart-pie">
    Real-time cost tracking and spend management across all your AI operations
  </Card>

  <Card title="Multi-Provider Access" icon="cubes">
    Access 300+ LLMs and 20+ providers through a single, unified integration
  </Card>
</CardGroup>

### Prerequisites

Before integrating LlamaIndex Agents with Orq.ai, ensure you have:

* An Orq.ai account and [API Key](/docs/administer/api-keys)
* Python 3.8 or higher
* LlamaIndex installed in your project

<Info>
  To setup your API key, see [API keys & Endpoints](/docs/administer/api-keys).
</Info>

### Installation

Install LlamaIndex and required dependencies:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
pip install llama-index llama-index-llms-openai-like
```

### Configuration

Configure LlamaIndex Agents to use Orq.ai's AI Router with the `OpenAILike` class:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from llama_index.llms.openai_like import OpenAILike
import os

# Configure OpenAI-compatible LLM with Orq.ai AI Router
llm = OpenAILike(
    model="gpt-4o",
    api_key=os.getenv("ORQ_API_KEY"),
    api_base="https://api.orq.ai/v3/router",
    is_chat_model=True,
)
```

> **api\_base**: `https://api.orq.ai/v3/router`

### Basic Agent Example

Here's a complete example using `ReActAgent` with a simple tool:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import asyncio
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.tools import FunctionTool
from llama_index.llms.openai_like import OpenAILike
import os

# Configure LLM with Orq.ai AI Router
llm = OpenAILike(
    model="gpt-4o",
    api_key=os.getenv("ORQ_API_KEY"),
    api_base="https://api.orq.ai/v3/router",
    is_chat_model=True,
)

# Define a tool
def get_weather(location: str) -> str:
    """Get the current weather for a location."""
    return f"The weather in {location} is sunny and 72°F"

# Create agent
agent = ReActAgent(
    tools=[FunctionTool.from_defaults(get_weather)],
    llm=llm,
)

async def main():
    response = await agent.run("What's the weather in San Francisco?")
    print(response)

asyncio.run(main())
```

### Agent with Multiple Tools

Build agents with multiple tools for complex reasoning:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import asyncio
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.tools import FunctionTool
from llama_index.llms.openai_like import OpenAILike
import os

llm = OpenAILike(
    model="gpt-4o",
    api_key=os.getenv("ORQ_API_KEY"),
    api_base="https://api.orq.ai/v3/router",
    is_chat_model=True,
)

def add(a: int, b: int) -> int:
    """Add two integers."""
    return a + b

def multiply(a: int, b: int) -> int:
    """Multiply two integers."""
    return a * b

def get_company_info(company: str) -> str:
    """Get basic information about a company."""
    companies = {
        "openai": "OpenAI is an AI research company founded in 2015.",
        "anthropic": "Anthropic is an AI safety company founded in 2021.",
    }
    return companies.get(company.lower(), f"No information found for {company}")

agent = ReActAgent(
    tools=[
        FunctionTool.from_defaults(add),
        FunctionTool.from_defaults(multiply),
        FunctionTool.from_defaults(get_company_info),
    ],
    llm=llm,
    system_prompt="You are a helpful assistant with access to math and company information tools.",
)

async def main():
    response = await agent.run("What is 15 * 4, and tell me about Anthropic?")
    print(response)

asyncio.run(main())
```

### Model Selection

With Orq.ai, you can use any supported model from 20+ providers:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import asyncio
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.tools import FunctionTool
from llama_index.llms.openai_like import OpenAILike
import os

def get_time(timezone: str) -> str:
    """Get the current time in a timezone."""
    return f"The current time in {timezone} is 14:30"

# Use Claude
claude_llm = OpenAILike(
    model="claude-sonnet-4-5-20250929",
    api_key=os.getenv("ORQ_API_KEY"),
    api_base="https://api.orq.ai/v3/router",
    is_chat_model=True,
)

# Use Gemini
gemini_llm = OpenAILike(
    model="gemini-2.5-flash",
    api_key=os.getenv("ORQ_API_KEY"),
    api_base="https://api.orq.ai/v3/router",
    is_chat_model=True,
)

agent = ReActAgent(
    tools=[FunctionTool.from_defaults(get_time)],
    llm=claude_llm,
)

async def main():
    response = await agent.run("What time is it in Tokyo?")
    print(response)

asyncio.run(main())
```

## Evaluations & Experiments

Once your agents are running, use **Evaluatorq** to score outputs across a dataset and **Experiments** to compare configurations side-by-side.

<CardGroup cols={2}>
  <Card title="Run Evaluations with Evaluatorq" icon="flask" href="/docs/evaluators/build#evaluatorq">
    Run parallel evaluations across your agents and compare results.
  </Card>

  <Card title="Run Experiments via the API" icon="flask-vial" href="/docs/experiments/api">
    Compare agent configurations and view results in the AI Studio.
  </Card>
</CardGroup>
