Multi-Agent Systems
Why specialized agents? How do they work together? What makes them intelligent?
What is an Agent?
An agent is a software program that:
- Perceives its environment (reads sensors, monitors events)
- Reasons about what to do (analyzes threats, optimizes energy)
- Acts to achieve goals (locks doors, adjusts HVAC, sends alerts)
- Learns from results (improves threat detection, refines optimization)
Think of an agent as a specialized expert that continuously monitors and acts within a specific domain.
Why Multiple Agents?
The Single-Agent Problem
Imagine one "super agent" handling everything:
❌ ONE AGENT FOR EVERYTHING:
- Security monitoring
- Energy optimization
- HVAC control
- Lighting management
- Access control
- Fire safety
- Grid coordination
Result: Too complex, can't specialize, slow decisions
The Multi-Agent Solution
Specialized agents, each an expert:
✅ SPECIALIZED AGENTS:
🛡️ Security Agent
Expert in: Threat detection, camera coordination, door control
⚡ Energy Agent
Expert in: HVAC optimization, demand response, cost reduction
🎯 Building Orchestrator
Expert in: Coordination, conflict resolution, priority management
Result: Each agent is simple, focused, and excellent at its specialty.
CitadelMesh Agents
🛡️ Security Agent
Domain: Physical security, access control, threat detection
What it perceives:
- Camera feeds (Avigilon analytics)
- Door sensors (open/closed, forced entry)
- Access logs (badge scans, failed attempts)
- Occupancy data (people count, locations)
How it reasons:
State Machine: MONITOR → ANALYZE → DECIDE → ACT → MONITOR
Analysis Example:
- Person detected: YES
- Authorized badge: NO
- Time: 11:30 PM (after hours)
- Location: Server room (high value)
→ Threat Score: 85/100 (HIGH)
Decision: Lock perimeter, activate cameras, alert security
What it acts on:
- Lock/unlock doors
- Camera positioning and recording
- Security alerts (email, SMS, dashboard)
- Lighting control (for visibility)
What it learns:
- False positive patterns
- Common authorized after-hours activity
- Threat detection accuracy improvement
⚡ Energy Agent
Domain: Energy efficiency, cost optimization, comfort
What it perceives:
- Power consumption (real-time meters)
- HVAC status (temperatures, setpoints)
- Electricity rates (time-of-use pricing)
- Weather forecasts
- Occupancy schedules
How it reasons:
Mathematical Optimization (scipy):
Minimize: energy_cost + discomfort_penalty
Subject to:
- Temperature: 68°F ≤ T ≤ 76°F
- Occupancy comfort maintained
- Demand limits not exceeded
- Grid constraints respected
Result: Optimal HVAC setpoints
What it acts on:
- HVAC setpoint adjustments
- Demand response participation
- Load shedding (non-critical systems)
- Lighting dimming
What it learns:
- Building thermal dynamics
- Occupancy patterns
- Optimal setpoint schedules
- Demand response profitability
🎯 Building Orchestrator
Domain: Multi-agent coordination, conflict resolution
What it perceives:
- All agent actions and states
- System conflicts
- Priority requirements
- Resource contention
How it reasons:
Priority Hierarchy:
1. Life Safety: 100 (fire, evacuation)
2. Security: 80 (threats, intrusion)
3. Comfort: 50 (occupant well-being)
4. Cost: 30 (energy, efficiency)
Conflict Resolution:
Security wants: "Lock all doors"
Energy wants: "Reduce HVAC"
→ Security priority (80) > Cost (30)
→ Security wins, energy adapts
What it acts on:
- Conflict arbitration
- Resource allocation
- Emergency protocol coordination
- Human escalation
What it learns:
- Conflict patterns
- Successful coordination strategies
- When to escalate to humans
How Agents Coordinate
Example: Security Breach During Peak Energy
Event: Unauthorized access detected at 3 PM
Without Coordination (Traditional)
Security System: Locks all doors
❌ HVAC still cooling locked-down areas (waste)
❌ Energy system unaware of security state
❌ Manual coordination required
With Multi-Agent Coordination (CitadelMesh)
1. 📹 Camera: "Unauthorized person detected"
2. 🛡️ Security Agent:
- Analyzes threat (HIGH)
- Decides: Lock perimeter
- Requests policy check
3. 🔒 OPA Policy: ALLOWED ✅
4. 🎯 Orchestrator: "Coordinate response"
- Notifies Energy Agent
- Sets priority: SECURITY_FIRST
5. ⚡ Energy Agent:
- Receives coordination event
- Reduces HVAC in locked zones
- Maintains critical systems
- Defers energy optimization
6. ⚙️ Result (2 seconds):
✅ Doors locked
✅ HVAC reduced in affected zones
✅ Energy saved in non-critical areas
✅ $2.40 additional cost (acceptable)
Agent Communication
Event-Driven Architecture
Agents communicate through events on a message bus (NATS):
CloudEvent Format:
{
"specversion": "1.0",
"type": "security.threat.detected",
"source": "security-agent",
"id": "threat-12345",
"time": "2025-10-04T15:30:00Z",
"data": {
"threat_level": "high",
"location": "server-room",
"confidence": 0.95
}
}
Benefits:
- ✅ Asynchronous (agents don't wait for each other)
- ✅ Decoupled (agents don't need to know about each other)
- ✅ Observable (all events logged and traced)
- ✅ Replay-able (can reconstruct what happened)
Coordination Patterns
1. Request-Response
Security Agent asks Orchestrator to resolve conflict:
Security → Orchestrator: "Can I lock door-lobby?"
Orchestrator → Energy: "Security needs door-lobby"
Energy → Orchestrator: "OK, I'll adapt HVAC"
Orchestrator → Security: "Approved ✅"
2. Publish-Subscribe
Security publishes event, Energy subscribes:
Security → Event Bus: "Security breach in progress"
Energy (subscribed) → "Received, suspending optimization"
Orchestrator (subscribed) → "Coordinating emergency response"
3. Command-Response
Orchestrator commands agents during emergency:
Fire Alarm → Orchestrator: "EMERGENCY"
Orchestrator → Security: "UNLOCK all exits NOW"
Orchestrator → Energy: "HVAC smoke evacuation NOW"
Both agents execute immediately
What Makes Agents Intelligent?
1. State Machines (LangGraph)
Agents use state machines to make decisions:
Security Agent States:
MONITOR
↓ (threat detected)
ANALYZE
↓ (assess severity)
DECIDE
↓ (choose action)
ACT
↓ (execute + observe)
MONITOR (loop back)
Why state machines?
- ✅ Predictable behavior
- ✅ Easy to test
- ✅ Clear decision flow
- ✅ Observable state transitions
2. Policy-Guided Decisions
Every action validated by OPA policies:
# Agent wants to act
agent.decide("lock_door", door="server-room")
↓
# Policy check
opa.evaluate(
action="lock_door",
agent_id="security-agent",
resource="door.server-room"
)
↓
# Policy logic
allow {
input.agent_id == "security-agent"
authorized_agent(input.agent_id)
is_lockable_door(input.resource)
not emergency_exit(input.resource)
}
↓
# Result: Allow or Deny
3. Learning from Data
Agents improve over time:
Security Agent:
- Learns false positive patterns
- Improves threat detection accuracy
- Adapts to normal vs. anomalous behavior
Energy Agent:
- Learns building thermal response
- Optimizes based on historical patterns
- Predicts occupancy trends
4. Context Awareness
Agents understand their environment:
Energy Agent Context:
- Current time: 3 PM (peak rates)
- Outside temp: 95°F (hot)
- Occupancy: 150 people (full)
- Grid status: Demand response active
- Security status: Normal
Decision: Participate in demand response
+ Increase setpoint 4°F
+ Still maintain comfort
+ Earn $31 incentive
Benefits of Multi-Agent Architecture
1. Modularity
Each agent is independent. Can develop, test, deploy separately.
2. Scalability
Add new agents without affecting existing ones (HVAC agent, Lighting agent, etc.).
3. Resilience
If one agent fails, others continue operating.
4. Specialization
Each agent is excellent at its domain (not mediocre at everything).
5. Explainability
Agent decisions are traceable through state machines and policies.
6. Safety
Orchestrator prevents conflicts, policies prevent unsafe actions.
Learn More
- See agents in action → Quick Tour
- Understand safety → Zero-Trust Safety
- Follow the build journey → The Chronicles
- See the architecture → Agent Topology
Multi-agent systems: Specialized intelligence working together, safely coordinated.