Context Attachment: Terminal Agent Session Management Infrastructure#
Purpose of This Document#
This document provides context for a Perplexity research inquiry about Anemoi A2A communication patterns. It describes our current infrastructure so research can identify where Anemoi patterns would provide concrete improvements.
Current Architecture Overview#
Session Lifecycle Management#
We operate a UUID-tracked session orchestration system for Claude Code terminal agents:
``` βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β SESSION LIFECYCLE β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β β β newsessionuuid β β β β β βΌ β β βββββββββββββββ ββββββββββββββββββββ βββββββββββββββββ β β β Generate βββββΆβ Pre-Launch Agent βββββΆβ Main Session β β β β UUID + β β (Haiku model) β β (User model) β β β β Metadata β β Creates CONTEXT β β Reads CONTEXT β β β βββββββββββββββ ββββββββββββββββββββ βββββββββββββββββ β β β β β β β βΌ βΌ βΌ β β env.sh exports CONTEXT.md Langfuse β β LAUNCH_*.sh Langfuse Trace Observations β β Session aliases Redis cache via Hooks β β β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ```
Key Components#
1. Session Creation (newsessionuuid)#
Creates tracked sessions with:
- UUID generation: Unique session identifier
- Namespace: Human-readable session category
- MCP configs: Which tool servers are available
- Add directories: Filesystem context for the agent
- Launcher script:
LAUNCH__session_id_<namespace>_<timestamp>.sh
Outputs to _env.sh:
```bash
session_id__MyNamespace_2512301200=
alias resume_MyNamespace="claude --mcp-config $MCP --add-dir $DIR --resume $UUID"
alias fork_MyNamespace="claude --mcp-config $MCP --add-dir $DIR --resume $UUID --fork-session"
```
2. Pre-Launch Context Agent (miette_newsession_context.sh)#
Critical pattern: Before main session starts, a lightweight agent (Haiku) analyzes the session intentions and creates:
CONTEXT.mdin session directory β summarizes what the session will CREATE- Langfuse trace with session metadata
- Redis cache entry pointing to context file
This agent receives webhook payload: ```json { "session": { "id": "", "namespace": "MyNamespace", "prompt": "User's initial prompt...", "mcpConfigs": ["/path/to/mcp.json"], "addDirs": ["/src", "/workspace"], "sessionDir": "/src/_sessiondata/", "launcherPath": "LAUNCH__session_id_MyNamespace.sh" } } ```
Current limitation: Context transfer is FILE-BASED. The pre-launch agent writes to disk, main agent reads from disk. No direct agent-to-agent communication.
3. Session Observability (v2_claude_hooks)#
Hook system captures session lifecycle to Langfuse:
| Hook | Trigger | Creates |
|---|---|---|
session_start_hook | Session begins | Trace |
user_prompt_submit_hook | User sends prompt | SPAN: user_input_exchange_N |
pre_tool_use_hook | Before tool call | EVENT: plan_proposed (if plan) |
post_tool_use_hook | After tool call | EVENT: plan_accepted/rejected |
stop_hook | Claude responds | Closes SPAN with response |
session_end_hook | Session ends | EVENT: session_completed |
State maintained in ._langfuse_state:
```bash
TRACE_ID=<session_id>
LAST_USER_INPUT_OBS_ID=
PLAN_COUNT=1
TOOL_COUNT=5
INTERACTION_COUNT=1
```
4. Fork/Resume Pattern#
Sessions can fork (branch) while maintaining parent reference: ```bash claude --resume $parent_uuid --fork-session --session-id $child_uuid ```
Current limitation: Forked session inherits conversation history but loses:
- Parent's Langfuse trace context
- Parent's structural tension state
- Parent's assumption log
Current Context Transfer Methods#
| Method | Mechanism | Latency | Reliability | Semantic Richness |
|---|---|---|---|---|
| File-based | CONTEXT.md on disk | Low | High | Medium |
| Webhook | HTTP POST to event hub | Medium | Medium | Low (metadata only) |
| Redis cache | Key-value lookup | Low | High | Low (paths only) |
| Prompt injection | Concatenate context to prompt | None | High | High but bloats tokens |
Problem: No direct agent-to-agent communication channel. All context passes through intermediaries (files, databases, webhooks).
Identified Pain Points#
1. Context Bloat in Fork Operations#
When forking, the child session must either:
- Re-inject full parent context (token expensive)
- Or lose semantic continuity (breaks workflow)
2. Pre-Launch Agent Isolation#
The Haiku agent preparing CONTEXT.md cannot:
- Query the main session about preferences
- Receive feedback if context was useful
- Adapt based on session progress
3. Parallel Agent Coordination#
Running multiple Claude instances requires:
- Manual state synchronization
- File-based handoffs
- No real-time awareness of sibling agents
4. Hook-to-Hook Communication#
Each hook operates independently. No mechanism for:
pre_tool_use_hookto informpost_tool_use_hookof expectations- Cross-session hook coordination
What We Want to CREATE (Desired Outcomes)#
- Direct A2A Channel: Agents communicate structured messages without file intermediaries
- Context Inheritance Protocol: Forked sessions receive semantic context, not just conversation dumps
- Bidirectional Pre-Launch: Preparation agent and main agent can negotiate context needs
- Coordinated Multi-Agent: Parallel sessions share discoveries in real-time
- Stateful Hook Chain: Hooks pass structured data through session lifecycle
Research Questions for Anemoi#
Given this infrastructure, we need to understand:
-
Anemoi's communication topology: Does it use message passing, shared memory, or hybrid?
-
Integration surface: Can Anemoi patterns work with:
- Shell-based session launchers?
- MCP tool servers?
- Langfuse trace hierarchy?
-
State preservation: How does Anemoi handle:
- Session continuation after interruption?
- Context transfer during agent handoff?
- Genealogical tracking (parent-child relationships)?
-
Comparison to alternatives:
- vs. Agent Continuations (Snaplogic) β JSON state blobs
- vs. NCP storyforms β narrative intent objects
- vs. MCP-Zero β dynamic tool discovery
-
Terminal agent applicability:
- Is Anemoi designed for API-based agents only?
- Can CLI agents (Claude Code) participate in Anemoi networks?
- What's the minimal integration for session fork/resume?
Existing Academic Validation (From Prior Research)#
Our previous Perplexity conversation validated these patterns:
| Our Component | Academic Equivalent | Source |
|---|---|---|
| UUID session tracking | Agent Continuations | Snaplogic |
| CONTEXT.md preparation | SagaLLM context agents | arXiv:2503.11951 |
| Structural tension charts | NCP storyforms | arXiv:2503.04844 |
| Hook-based observability | MCP-Bench patterns | arXiv:2508.20453 |
Gap identified: Anemoi's A2A pattern was mentioned but not explored. Quote from prior research:
"Anemoi (GitHub: Coral-Protocol/Anemoi) β A2A communication pattern for inter-agent collaboration. Shows how structured direct communication beats prompt concatenation."
This is what we want to explore deeply.
Success Criteria for Research Output#
The research will be useful if it provides:
- Concrete protocol description: How Anemoi agents exchange messages (format, transport, semantics)
- Implementation examples: Code patterns showing A2A communication
- Integration pathway: Steps to add Anemoi patterns to existing shell-based orchestration
- Trade-off analysis: When A2A direct communication is better vs. file-based handoffs
- Self-inquiry questions: What we should ask ourselves before implementing
File References (For Context Only)#
These files exist in our system and inform this context:
/src/scripts/fn_llm.shβ Containsnewsessionuuidfunction/src/scripts/v2_claude_hooks/β Hook system for Langfuse integration/src/miette/claude-plan-insights/miette_newsession_context.shβ Pre-launch agent script/src/_sessiondata/<uuid>/β Session data directories
Perplexity cannot access these files, but understanding they exist helps frame the research toward practical integration.