Part 2: Isolation, Verification, and Security
Build a complete research session with planner, researcher, coder, validator, and auditor roles. Learn to enforce shared-state contracts, verify retrieval and citations, separate source fields from provenance, quarantine risky memory writes, protect team boundaries, roll back errors, and produce a checked incident report.
We'll cover the following...
In the last lesson, we built the project’s prefix file, retrieval file, and sandboxed runner, and each one passed the check that proved its original version. The project still has nothing that runs a whole session. The workers from Chapter 6 and the memory defenses from Chapter 7 exist, but only in their own lessons, on their own examples.
In this lesson, we’ll write the last two building files. agents.py runs five roles (a planner, a researcher, a coder, a validator, and an auditor) over the four-key shared state from Lesson 6.2, using the real retrieval and the real runner. memory.py decides which of the facts they produce may be saved for later sessions, and where. Then we’ll rerun the Chapter 6 and Chapter 7 checks against the assembled session.
Write the workers
The planner, researcher, and coder do the work. Each one is a function that reads and writes the shared state and returns a response in the handoff format from Lesson 6.2. Sharing only this state between workers is the Isolate move from Chapter 1. They now call the project files instead of hardcoded data:
Planner: We write the plan into
full_plan, overwriting it in place.Researcher: We run
retrieve()from Lesson 8.2 and record clues only for text that was actually loaded, plus the deploy-log change.Coder: We send the impact analysis to the sandboxed runner and record its two
RESULTnumbers, with the log path as their source.
Here are the three workers.
In the code above:
Lines 8–9: We list the two quotes the review needs and the note each one should come from.
Lines 12–14: We define
planner(), which sets the plan and returns a short response.Lines 17–24: We define ...