Purpose
Define how openboa builds runtime context for one turn. Context must be:- predictable
- bounded
- replayable from local files
Scope
In scope:- turn-time context composition
- context size budgeting and trimming
- local persistence and recovery behavior
- same context path for Agent↔Human and Agent↔Agent
- required vector DB / external memory service
- long-term autonomous memory optimization
- cross-tenant shared memory federation
Context Sources (assembly order)
For each turn, runtime assembles context from these sources:-
Recent Chat Window
- latest messages from current chat
- includes both inbound and outbound events
-
Session Runtime State
- last checkpoint summary
- pending queue summary (if exists)
- last terminal status
-
Agent Working Memory Pointers
- short memory notes relevant to current chat
- workspace memory references only (local-first)
-
Tool/Skill Result Snippets
- recent tool outputs needed for continuity
- compacted summaries, not full raw dumps by default
-
Current Input Event
- current event payload (always included)
Context Budget Rules
Runtime uses bounded context windows. Required controls:maxContextTokensmaxRecentMessagesmaxToolSnippetTokens
- trim oldest chat items first
- compact tool outputs to summaries
- keep current input and latest checkpoint summary
- trimming must be deterministic
- runtime should emit a context-trim note in trace data
Context Snapshot (local)
Each turn may emit a compact context snapshot for replay/debug:.openboa/agents/<agentId>/context/<sessionId>.jsonl
Context Consistency Rules
-
Single path rule
- Agent↔Human and Agent↔Agent use the same context builder
-
No sender-type branch
- sender category does not change context logic
-
Deterministic replay
- same session log + same config => same context hash for same turn
-
Local-first fallback
- if optional connectors are unavailable, local context flow still works
Failure Handling
If context build fails:- classify as
context_build_error - emit terminal
failed - include
nextActionwith recovery step - append failure record to session/audit logs
Acceptance Criteria
- context is assembled from defined source order
- over-budget behavior is deterministic and traceable
- context snapshots are locally replayable
- no external store is required for core context path
- same context contract works for Agent↔Human and Agent↔Agent
Reference Notes (inline)
- OpenClaw runtime/session docs were referenced for practical local session + context handling patterns.
- openboa keeps its own context schema and local-first contracts.