Context Engineering, Compaction, Agent Skills & A2A Protocol
Managing long-horizon agent state: progressive SKILL.md disclosure, checkpoint compaction, and Agent-to-Agent (A2A) federation.
Core Conceptual Brief
In 2026-2027, prompt engineering evolved into Context Engineering—curating exactly which tools, memory slices, skills, and compacted history occupy the model window on each agent turn, alongside Google A2A + Anthropic MCP interoperability.
Theoretical & Empirical Architecture
Long-running coding and research agents fail most often from context rot, not raw model intelligence: dumping 80 MCP tool schemas and 100KB of stale JSON logs degrades tool accuracy and blows prefix caches. Context Engineering treats the context window as scarce L1 cache memory.
While MCP standardizes how an agent connects vertically to external tools and data resources, the Agent2Agent (A2A) protocol standardizes horizontal collaboration—how independent agents discover capabilities via Agent Cards, delegate long-running tasks, and exchange typed artifacts across organizational boundaries.
Under the Hood: Key Engineering Mechanics
1Context Compaction & Checkpointing
Before context utilization hits attention-degradation zones (often ~50-65% of max window), summarize resolved intermediate tool turns into a structured state snapshot (goal, constraints, decisions, open files) while keeping the latest raw diffs and errors verbatim.
2Agent Skills (Progressive Disclosure)
Instead of injecting 40 pages of specialized instructions at boot, package domain workflows as modular Skills (SKILL.md + scripts). Only short skill metadata sits in the base prompt; full instructions load lazily when the user task matches that skill.
3MCP (Agent-to-Tool) vs A2A (Agent-to-Agent)
Use MCP when one agent needs structured access to SQL, GitHub, Slack, or filesystems. Use A2A when orchestrating remote specialist agents (e.g. Procurement Agent calling a Vendor Legal Agent) with independent state machines, streaming task statuses, and RBAC auth.
Token-Budgeted Context Compaction Guard
def compact_agent_history(messages: list[dict], max_tokens: int, summarizer_fn) -> list[dict]:
"""Preserve pinned system prompt + latest N raw turns; compact older middle traces."""
system_msgs = [m for m in messages if m["role"] == "system"]
tail = messages[-6:] # Keep verbatim recent tool outputs for debugging precision
middle = messages[len(system_msgs):-6]
if estimate_tokens(messages) <= max_tokens or not middle:
return messages
summary_text = summarizer_fn(middle)
compacted_note = {"role": "assistant", "content": f"<compacted_state>{summary_text}</compacted_state>"}
return [*system_msgs, compacted_note, *tail]Production Guardrails & Takeaways
- Context Engineering curates the smallest high-signal token state for every turn while protecting prefix caches.
- Load specialized Agent Skills on demand rather than bloating initial system prompts.
- Pair MCP (vertical tool access) with A2A (horizontal multi-agent task delegation) and strict stop conditions.
Real Staff AI Systems Interview Question
Q: How do you prevent long-running multi-step agents from forgetting constraints or exceeding context limits?
Combine external persistent state checkpoints (e.g. LangGraph/Postgres thread state), token-budgeted middle-history compaction that summarizes completed steps while preserving pinned constraints and recent raw tool errors, and semantic top-K tool/skill loading.