Architecture
NAE runs as a Python process inside the MIRA application, communicating with the renderer via a typed IPC bridge. On each query, NAE:- Checks the token budget and triggers compaction if needed
- Builds the context window (system prompt + history + documents + tool results)
- Decides whether to use a single agent or spawn sub-agents
- Calls the LLM API directly
- Streams the response back to the UI
- Updates episodic memory and the token ledger
Context management
Managing a long session’s context is the hardest problem in agentic AI. NAE handles it automatically across four layers:Token budget
NAE maintains a real-time token ledger accounting for every token committed to the context window:- System prompt
- Conversation history
- Injected documents
- Tool call results
- Reserved output zone
Automatic compaction
Two compaction strategies run in sequence as needed:- Sliding window — evicts the oldest turns from the context while preserving the most recent K turns
- Selective pruning — identifies and removes low-value content (verbose tool outputs, intermediate reasoning chains that have been superseded) without truncating the timeline