Unified Agent Identity System — 6 attributes, 1 middleware, 4000 tokens

2026-03-30

agent-context-injectorheartbeatworkspacereferencesoulskillmemory

What We Built

A unified agent identity system that injects up to 6 context attributes into every completion — transparently, in one middleware pass, with a shared 4000-token budget.

Previously, memory injection and skill injection were separate middlewares with no awareness of each other. Now a single agentContextInjectorMiddleware loads SOUL (identity), MEMORY (governance + facts), SKILL (learned patterns), HEARTBEAT (health warnings), WORKSPACE (active files), and REFERENCE (design specs with progressive disclosure) in priority order.

The system is fully opt-in and additive: an agent with just an API key gets routing. Add a profile and it gets budget + trust. Add a SOUL.md and it gets identity. Each layer adds capability without requiring any other.

Why It Matters

Every AI agent platform fragments identity across multiple systems. CrewAI has role/goal/backstory but no memory. Letta has tiered memory but no workspace. Anthropic has progressive-disclosure skills but no health monitoring.

BrainstormRouter is the first routing layer that is also a full agent identity platform. Any agent that routes through BR gets all six attributes injected transparently — no SDK changes, no new API calls. The router becomes the agent platform.

How It Works

The consolidated middleware runs after auth/budget, before guardrails:

auth → rbac → budget → agentContextInjector → guardrails → completion

Inside the middleware, attributes load in priority order:

  1. SOUL (800 tokens, never truncated) — from SOUL.md workspace file or hr_record fallback
  2. MEMORY (1200 tokens) — governance rules + user facts + archival search
  3. SKILL (600 tokens) — domain knowledge + learned patterns
  4. HEARTBEAT (100 tokens, only when degraded) — one-line warning
  5. WORKSPACE (800 tokens) — active context files
  6. REFERENCE (200 metadata + 800 content) — progressive disclosure on keyword match

Token budget enforced across all attributes. Truncation in reverse priority.

The Numbers

  • 6 attributes unified into 1 middleware (was 2)
  • 4000 token budget with priority-based truncation
  • 0 additional latency for agents without context (all guards short-circuit)
  • 5 new MCP tools (96 total)
  • 13 telemetry headers for full observability

Competitive Edge

No other AI routing platform combines identity + memory + skills + health monitoring + workspace + reference materials in the routing layer itself. Portkey, OpenRouter, and LiteLLM are pure routers. Letta and CrewAI are agent frameworks without routing. BR is both — and the context injection is transparent to the calling agent.

Lockstep Checklist

  • [x] API Routes: No new REST routes (MCP-only tools). Completions routes unchanged.
  • [x] TS SDK: No new REST surface to wrap. MCP tools discoverable via agents.json.
  • [x] Python SDK: Same — MCP-only.
  • [x] MCP Schemas: 5 tools added to tool-manifest.ts, agents.json regenerated (96 tools).
  • [x] Master Record: Covered by this ship log entry.