The loop is 30 lines. The transcript is the hard part.
What building a local agent runtime from scratch taught me. The agent loop is trivial; keeping the model's view of the world true under cancellation, concurrency, compaction and human approval is not.