Pick a depth. Each prompt opens in your AI pre-loaded with the lesson. Click a row to preview the prompt.
A powerful technique: when a task has a self-contained sub-problem, spawn a sub-agent with a fresh, clean context window scoped just to that sub-problem, and return only the result to the parent. This keeps the parent's context from accumulating the sub-problem's scratch work, and gives the sub-agent the full window for its focused task. It's like calling a function with its own stack frame. Knowing when to spawn a fresh context (isolatable sub-task) vs. continue in the current one (tightly coupled) is central to scaling agent context.
The demo spawns a sub-agent with a clean context for an isolatable task (analyzing one document), returning only the conclusion. The parent never sees the sub-agent's intermediate reasoning, keeping its window clean.
# --- Pick your provider (set the matching API key env var) ---
# Anthropic: from anthropic import Anthropic; client = Anthropic() # ANTHROPIC_API_KEY
# OpenAI: from openai import OpenAI; client = OpenAI() # OPENAI_API_KEY
# Gemini: from google import genai; client = genai.Client() # GEMINI_API_KEY
from anthropic import Anthropic
client = Anthropic()
def sub_agent(task: str, scoped_input: str) -> str:
# Fresh, isolated context window — none of the parent's history
r = client.messages.create(model="claude-sonnet-4-6", max_tokens=200,
system=f"You handle one task: {task}. Return only the conclusion.",
messages=[{"role": "user", "content": scoped_input}])
return r.content[0].text # only this comes back to the parent
# Parent delegates an isolatable analysis; its own window stays clean:
conclusion = sub_agent("Assess legal risk in this clause",
scoped_input="Clause 7: ...the vendor may terminate without notice...")
print("parent receives only:", conclusion)python3 main.py