Context-First Agent Design for Content Operations at Scale

Rostislav Melkumyan1 Jun 2026

Problem

Sanity's Content Agent audits, generates, edits and updates content in bulk. Some customers have hundreds of content types and tens of thousands of documents. The team first added a tool after every failure. The agent grew less consistent and often chose a similar but wrong tool. Dumping raw schemas and query results into the context made it slower, costlier and less accurate.

Example from the article: asked "how many blog posts has Sam written?", a weak agent searched the person type, found no matching blog posts and answered wrongly, because blog posts reference the author type, not person.

Solution in brief

Show the agent a compressed schema graph first and fetch detail on demand. Wrap large query results in "sets" (handles with summary metadata) and check them before expensive work. Code, not the model, validates and repairs queries.

Questions this case answers
  • How to let an LLM agent act on a result set too large for its context window while the user can still verify the slice it works on
  • How to make an agent choose the right entities and relationships in a large schema when raw schema dumps overwhelm it
  • How to stop an LLM agent from picking the wrong entity types and relationships when it queries a large structured content store?
  • How to let an agent work on thousands of documents without putting them into its context window?

Tools and methods

  • Compressed schema overview — types, key fields, reference counts instead of raw JSON
  • Sets — handle to a large result with summary stats and the query
  • Query parse-and-repair step — parses the query, adds required fields, returns errors
  • One main agent with a few broad tools — specialized subagents only where the gain is clear
  • Bundles — version documents holding bulk changes until approval
Continue reading — it's free

Google or a one-time email code. No password.