## TL;DR

Two hundred pages of tax rules will never fit in context. Extract the text once, split it by topic, and retrieve only the sections relevant to each expense (meals, travel, mileage); the agent gets the rules it needs without the overflow.

## Error

```text
agent failed with context overflow reading 200 pages of tax rules
```

## Steps

1. Extract the tax rules to plain text once, outside the agent run. Expected: a single text file with the full rules.
2. Split by topic: meals and entertainment, travel, mileage, gifts, and so on. Expected: topical sections the agent can fetch independently.
3. Build a simple index over the sections (keyword search is enough for tax topics). Expected: topic queries return the right sections.
4. Per expense, retrieve the one or two sections matching the expense type before applying rules. Expected: the agent reasons over relevant rules only.
5. Rebuild the index when the tax rules update (typically yearly). Expected: the agent always uses the current year's rules.

## When to use

- Tax rule documents overflow the agent's context.
- The agent needs tax rules during expense audits.

## When not to use

- The rules fit in context (ingest them directly).
- The agent misapplies rules it can read (a reasoning problem, not context).

## Tool compatibility

- Custom audit agents; PDF text extraction plus retrieval.

## Variant phrasings

### Tax rules too large for context window

Same failure, plain wording.

### Context overflow on tax document

The model-side phrasing.

## Why it happens

Tax guidance is comprehensive by design; an audit needs the two pages about meals, not all two hundred. Retrieval separates the knowledge the agent needs from the document it came in.

## Provenance

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