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

# Lite Package (BYO-LLM)

> Lightweight agent framework without heavy dependencies

The `praisonaiagents.lite` subpackage provides a minimal agent framework that lets you bring your own LLM client — no `litellm` dependency and minimal memory.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
from praisonaiagents.lite import LiteAgent, create_openai_llm_fn

agent = Agent(name="assistant", instructions="You are a helpful assistant.")

llm_fn = create_openai_llm_fn(model="gpt-4o-mini")
agent = LiteAgent(
    name="MyAgent",
    llm_fn=llm_fn,
    instructions="You are a helpful assistant.",
)
agent.chat("Hello!")
```

The user sends a chat message; LiteAgent calls your LLM function with minimal framework overhead.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    Agent[🤖 LiteAgent] --> Tool[🔌 BYO LLM]
    Tool --> Result[💬 Response]

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef tool fill:#189AB4,stroke:#7C90A0,color:#fff
    class Agent agent
    class Tool tool
    class Result agent
```

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Feature as Lite Package (BYO-LLM)

    User->>Agent: Request
    Agent->>Feature: Process request
    Feature-->>Agent: Result    Agent-->>User: Response
```

## Quick Start

<Steps>
  <Step title="Create a lite agent">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents.lite import LiteAgent, create_openai_llm_fn

    llm_fn = create_openai_llm_fn(model="gpt-4o-mini")
    agent = LiteAgent(
        name="MyAgent",
        llm_fn=llm_fn,
        instructions="You are a helpful assistant.",
    )
    response = agent.chat("Hello!")
    print(response)
    ```
  </Step>

  <Step title="Add tools">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents.lite import tool

    @tool
    def add_numbers(a: int, b: int) -> int:
        """Add two numbers together."""
        return a + b

    agent = LiteAgent(name="ToolAgent", llm_fn=llm_fn, tools=[add_numbers])
    ```
  </Step>
</Steps>

## Components

### LiteAgent

The main agent class with thread-safe chat history:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents.lite import LiteAgent

agent = LiteAgent(
    name="MyAgent",
    llm_fn=my_llm_function,
    instructions="System instructions",
    tools=[my_tool]  # Optional tools
)

# Chat
response = agent.chat("Hello")

# Access chat history (thread-safe)
print(agent.chat_history)

# Clear history
agent.clear_history()
```

### Custom LLM Functions

Bring your own LLM by providing a function that takes messages and returns a string:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def my_custom_llm(messages):
    """
    Args:
        messages: List of dicts with 'role' and 'content'
    Returns:
        str: The assistant's response
    """
    # Your LLM implementation here
    return "Response from my LLM"

agent = LiteAgent(name="Agent", llm_fn=my_custom_llm)
```

### Built-in LLM Adapters

#### OpenAI Adapter

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents.lite import create_openai_llm_fn

# Requires OPENAI_API_KEY environment variable
llm_fn = create_openai_llm_fn(
    model="gpt-4o-mini",
    temperature=0.7,
    max_tokens=1000
)
```

#### Anthropic Adapter

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents.lite import create_anthropic_llm_fn

# Requires ANTHROPIC_API_KEY environment variable
llm_fn = create_anthropic_llm_fn(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1000
)
```

### Tools

Define tools using the `@tool` decorator:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents.lite import LiteAgent, tool

@tool
def add_numbers(a: int, b: int) -> int:
    """Add two numbers together."""
    return a + b

@tool
def get_weather(city: str) -> str:
    """Get the weather for a city."""
    return f"Weather in {city}: Sunny, 72°F"

agent = LiteAgent(
    name="ToolAgent",
    llm_fn=llm_fn,
    tools=[add_numbers, get_weather]
)

# Execute tools directly
result = agent.execute_tool("add_numbers", a=5, b=3)
print(result.output)  # 8
print(result.success)  # True
```

### LiteTask

For structured task execution:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents.lite import LiteAgent, LiteTask

agent = LiteAgent(name="Worker", llm_fn=llm_fn)

task = LiteTask(
    description="Summarize the following text",
    agent=agent,
    expected_output="A brief summary"
)

result = task.execute(context="Long text to summarize...")
print(result)
```

## Thread Safety

LiteAgent uses locks for thread-safe operations:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import threading
from praisonaiagents.lite import LiteAgent

agent = LiteAgent(name="ThreadSafe", llm_fn=llm_fn)

def worker(prompt):
    response = agent.chat(prompt)
    print(f"Response: {response}")

# Safe to use from multiple threads
threads = [
    threading.Thread(target=worker, args=(f"Question {i}",))
    for i in range(5)
]

for t in threads:
    t.start()
for t in threads:
    t.join()
```

## Memory Efficiency

The lite package uses significantly less memory than the full package:

| Package                | Memory Usage |
| ---------------------- | ------------ |
| praisonaiagents (full) | \~93MB       |
| praisonaiagents.lite   | \~5MB        |

## When to Use Lite

Use the lite package when:

* You want minimal dependencies
* You have your own LLM client
* Memory usage is critical
* You need fast startup time
* You're building a custom integration

Use the full package when:

* You need multi-provider support via litellm
* You want automatic model routing
* You need advanced features (memory, knowledge, etc.)

## Best Practices

<AccordionGroup>
  <Accordion title="Use lite when you own the LLM client">
    The lite subpackage suits custom integrations that call OpenAI or Anthropic directly.
  </Accordion>

  <Accordion title="Install full package for multi-provider routing">
    Switch to the full SDK when you need litellm, memory, knowledge, or automatic model routing.
  </Accordion>

  <Accordion title="Benchmark startup in your environment">
    Measure import time and memory on your deployment target — lite shines on edge and serverless.
  </Accordion>

  <Accordion title="Pin versions in production">
    Lite and full packages share core protocols — pin both SDK and wrapper versions together.
  </Accordion>
</AccordionGroup>

## Related

<CardGroup cols={2}>
  <Card title="Lazy Imports" icon="bolt" href="/docs/features/lazy-imports">
    Fast startup and minimal memory
  </Card>

  <Card title="Lite Package CLI" icon="terminal" href="/docs/cli/lite">
    CLI commands for the lite subpackage
  </Card>
</CardGroup>
