> ## 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.

# Context Management

> Manage conversation context size

Context management controls how much history the agent remembers.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Context Window"
        M1[Old] --> M2[...]
        M2 --> M3[Recent]
        M3 --> C[📦 Context]
        M1 -.-> X[✂️ Trimmed]
    end
    
    classDef old fill:#94A3B8,stroke:#7C90A0,color:#fff
    classDef recent fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef context fill:#10B981,stroke:#7C90A0,color:#fff
    
    class M1 old
    class M2,M3 recent
    class C context
```

## Quick Start

<Steps>
  <Step title="Create Agent with Context Limits">
    ```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    use praisonai::{Agent, MemoryConfig};

    let agent = Agent::new()
        .name("Assistant")
        .instructions("You are a helpful assistant")
        .memory_config(MemoryConfig::new().max_messages(50))  // Keep last 50 messages
        .build()?;

    // Agent will automatically trim old messages
    let response = agent.chat("Hello!").await?;
    ```
  </Step>

  <Step title="Configure Memory Strategy">
    ```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    use praisonai::{Agent, MemoryConfig};

    let config = MemoryConfig::new()
        .max_messages(100)
        .use_short_term(true);

    let agent = Agent::new()
        .name("Assistant")
        .memory_config(config)
        .build()?;
    ```
  </Step>
</Steps>

***

## Context Strategies

| Strategy       | Description             |
| -------------- | ----------------------- |
| Sliding window | Keep last N messages    |
| Summarization  | Compress old messages   |
| Selective      | Keep important messages |

***

## Related

<CardGroup cols={2}>
  <Card title="Memory" icon="brain" href="/docs/rust/memory">
    Memory system
  </Card>

  <Card title="Sessions" icon="user" href="/docs/rust/sessions">
    Session persistence
  </Card>
</CardGroup>
