## TL;DR

The handbook is too large to fit in context, so the agent must stop trying to read it whole. Split the handbook into sections, retrieve only the sections relevant to each expense being audited, and the overflow disappears.

## Error

```text
agent failed to parse the policy handbook: pdf too large, context overflow
```

## Steps

1. Extract the handbook text from the PDF once, outside the agent run. Expected: a plain-text version of the handbook.
2. Split the text into sections by heading (meals, travel, mileage, and so on). Expected: a set of self-contained policy sections.
3. Index the sections for retrieval (keyword or embedding index). Expected: the agent can fetch sections by topic.
4. Per expense, retrieve only the sections matching the expense type before evaluating. Expected: the agent sees the relevant rules, not the whole book.
5. Cache the extracted and indexed handbook; rebuild the index only when the handbook version changes. Expected: the heavy work happens once.

## When to use

- A policy handbook overflows the agent's context window.
- The agent needs handbook rules during audits.

## When not to use

- The handbook fits in context (read it directly).
- The PDF text extraction itself fails (fix extraction first).

## Tool compatibility

- Custom audit agents; PDF text extraction plus retrieval.

## Variant phrasings

### Handbook too large for agent context

Same failure, plain wording.

### Context overflow on policy document

The model-side phrasing of the same limit.

## Why it happens

Handbooks are written for humans, not context windows: hundreds of pages where an audit needs three. Retrieval gives the agent the three pages that matter.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_7m8RrTlMzRuTP55cFkcYzQ
