Practical EPUB Reader Walkthrough (Tree-of-Thought Over Evidence)¶
What this agent is¶
examples/real/epub_reader_agent.py is a practical Tree-of-Thought-like reader:
- it treats reading as evidence gathering
- it branches between multiple candidate next actions
- it finishes only when evidence is sufficient to answer the question
It uses:
EpubToolSet(chapter listing/search/reading)Decision.branch(...)for candidate actions- optional
DynamicTreeSearchfor selection
Core design choices¶
- Evidence is the central state, not “thought text”.
- Branching is explicit via
Decision.branch(...). - Bootstrapping is deterministic (list chapters / keyword probe).
- Prompt output is structured JSON to generate candidates reliably.
Method-by-method design¶
EpubToTState: evidence-first state¶
Key fields:
evidence: bounded snippets from toolsthoughts: bounded rationales for interpretabilitychapter_count: derived capability info (helps reduce random actions)
decide: bootstrap, then expand candidates¶
Step 0:
- return a
Decision.branch(...)with two deterministic candidates: - list chapters
- search for question keywords
Later steps:
- ask the model for 2-4 candidate “thoughts” as JSON
- convert each candidate into
Decision.act(Action(...), meta={"score": ...}) - return
Decision.branch(candidates=...)
reduce: transform tool output into reusable evidence¶
The reducer:
- extracts chapter catalog hints, search snippets, and chapter text fragments
- keeps evidence bounded (
[-20:]) to avoid growth
Design principle:
- “progress” in reading is evidence quality, not step count.
How to extend it into a stronger reader¶
- Add a verifier:
- score candidates by whether they increase evidence diversity (not just relevance)
- Add a tree recorder:
- store parent/child edges for each decision id to visualize search
- Add citation formatting:
- require final answer to include evidence ids/snippets