> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Agentic Chunking

> Split documents with AgenticChunking, which uses a model to find natural breakpoints.

`AgenticChunking` asks a model to choose each split position within `max_chunk_size` characters. It uses the size limit when the model call fails or the response cannot be parsed as an integer. Positions above the limit are clamped.

**1. Create a Python file**

```python agentic_chunking.py theme={null}
from agno.agent import Agent
from agno.knowledge.chunking.agentic import AgenticChunking
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.reader.pdf_reader import PDFReader
from agno.vectordb.pgvector import PgVector

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

knowledge = Knowledge(
    vector_db=PgVector(table_name="recipes_agentic_chunking", db_url=db_url),
)

knowledge.insert(
    url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
    reader=PDFReader(
        name="Agentic Chunking Reader",
        chunking_strategy=AgenticChunking(),
    ),
)

agent = Agent(
    knowledge=knowledge,
    search_knowledge=True,
)

agent.print_response("How do I make Thai curry?", markdown=True)
```

<Snippet file="create-venv-step.mdx" />

**2. Install dependencies**

```bash theme={null}
uv pip install -U agno openai pypdf sqlalchemy psycopg pgvector
```

**3. Export your OpenAI API key**

<Snippet file="set-openai-key.mdx" />

<Snippet file="run-pgvector-step.mdx" />

**4. Run the script**

```bash theme={null}
python agentic_chunking.py
```

## Custom Prompts

```python theme={null}
from agno.knowledge.chunking.agentic import AgenticChunking

AgenticChunking(
    custom_prompt="Split at major section boundaries. Keep complete clauses together.",
    max_chunk_size=3000,
)
```

> [!NOTE]
>
> `custom_prompt` is inserted into Agno's chunking instructions. For the chunker to make progress, the model must return a positive integer.

> [!TIP]
>
> Set `max_chunk_size` explicitly when using a custom prompt so the model receives the intended limit.

## Agentic Chunking Params

<Snippet file="chunking-agentic.mdx" />

## Developer Resources

* [Chunking strategies examples](https://agno-v2.mintlify.site/examples/knowledge/building-blocks/chunking-strategies.md)
* [Chunking overview](https://agno-v2.mintlify.site/knowledge/concepts/chunking/overview.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.