Coding agent context engineering with Opik traces

Explore memory files, skill loading, LSP feedback and context compaction, with an Opik trace showing a coding agent’s reference lookup.

Player not loading? Watch on YouTube

This tutorial explains how the speaker manages context in an educational coding assistant built from scratch. He argues that stale files and tool outputs can cause agent mistakes, and focuses on changes to the harness rather than switching models. The lesson belongs to the open source course Building a Coding Agent From Scratch.

The memory design separates manual AGENTS.md instructions from automatically extracted MEMORY.md entries. Before quit or clear discards a conversation, the harness appends a dated, one-sentence summary. The example caps memory at 200 lines or 25 KB and compresses it when needed. The speaker acknowledges that summarizing existing summaries does not always work well.

Skills use three levels of loading: names and descriptions stay in context, a tool loads SKILL.md when requested, and read tools retrieve supporting files as needed. The LSP section uses ty for definitions, references, hover information and diagnostics. It also explains how write and edit calls can return diagnostics automatically. An Opik trace illustrates a reference lookup.

Compaction triggers at 80% context usage in this implementation, replacing older messages with a summary while retaining a recent tail. Micro compaction starts at 60% and replaces older tool outputs with placeholders, leaving the tail intact. These thresholds describe the demonstrated harness; the lesson does not establish them as universal settings.