> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agno.com/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.

<Steps>
  <Step title="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)
    ```
  </Step>

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno openai pypdf sqlalchemy psycopg pgvector
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    <Snippet file="set-openai-key.mdx" />
  </Step>

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

  <Step title="Run the script">
    ```bash theme={null}
    python agentic_chunking.py
    ```
  </Step>
</Steps>

## 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,
)
```

<Info>
  `custom_prompt` is inserted into Agno's chunking instructions. For the chunker to make progress, the model must return a positive integer.
</Info>

<Tip>
  Set `max_chunk_size` explicitly when using a custom prompt so the model receives the intended limit.
</Tip>

## Agentic Chunking Params

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

## Developer Resources

* [Chunking strategies examples](/examples/knowledge/building-blocks/chunking-strategies)
* [Chunking overview](/knowledge/concepts/chunking/overview)
