NEXUS Technical Architecture
A comprehensive technical specification of NEXUS โ the Next-Level Autonomous Agent Operating System. This document details the architecture, components, and implementation patterns that enable sophisticated multi-agent reasoning with 83.6% task success rate.
๐ Executive Overview
NEXUS represents a paradigm shift in autonomous agent architecture. By combining Monte Carlo Tree Search (MCTS) reasoning with specialized multi-persona agents, NEXUS achieves unprecedented task completion rates while maintaining full auditability and human oversight.
The Problem
Current LLM agents suffer from three critical limitations: sequential reasoning without exploration, no learning from failed attempts, and inability to simulate outcomes before execution.
The Solution
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ NEXUS ARCHITECTURE โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ โ โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ โ โ PLANNER โ โ SIMULATOR โ โ CRITIC โ โ โ โ Agent โโโโโบโ Agent โโโโโบโ Agent โ โ โ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โ โ โ โ โ โ โ โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ โโโโโโโโโโโผโโโโโโโโโโ โ โ โ TECTONIC CORE โ โ โ โ (MCTS Engine) โ โ โ โโโโโโโโโโโฌโโโโโโโโโโ โ โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ โ โ โโโโโโโผโโโโโโ โโโโโโโโผโโโโโโโ โโโโโโโโผโโโโโโโ โ โ โ SENTINEL โ โ ORCHESTRATORโ โ WEB WORLD โ โ โ โ MCP โ โ (CoR) โ โ MODELS โ โ โ โโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Key Metrics
| Metric | NEXUS | Baseline ReAct | Improvement |
|---|---|---|---|
| Task Success Rate | 83.6% | 67.2% | +24.4% |
| Error Recovery | 91.2% | 45.0% | +102.7% |
| Avg. Steps to Complete | 12.4 | 18.7 | -33.7% |
| Catastrophic Failures | 2.1% | 15.8% | -86.7% |
๐ง TECTONIC Core
Tree-based Exploration and Critical Thinking Orchestration for Navigating Intelligent Choices โ the reasoning graph engine at the heart of NEXUS. Built on Monte Carlo Tree Search principles adapted for LLM agents.
Architecture
โโโโโโโโโโโโโโโ
โ ROOT โ
โ (Initial) โ
โโโโโโโโฌโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโผโโโโโโโ โโโโโโโโผโโโโโโโ โโโโโโโโผโโโโโโโ
โ Action A โ โ Action B โ โ Action C โ
โ Q=0.72 โ โ Q=0.85 โ โ Q=0.45 โ
โ N=15 โ โ N=42 โ โ N=8 โ
โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโโโโโโโโ
โ โ
โโโโโโโโดโโโโโโโ โโโโโโโโดโโโโโโโ
โ โ โ โ
โโโโผโโโโ โโโโโผโโโ โโโโผโโโโ โโโโโผโโโ
โ A.1 โ โ A.2 โ โ B.1 โ โ B.2 โ
โQ=0.68โ โQ=0.91โ โQ=0.88โ โQ=0.79โ
โโโโโโโโ โโโโโโโโ โโโโโโโโ โโโโโโโโ
UCB1 Selection Formula
TECTONIC uses Upper Confidence Bound (UCB1) to balance exploration vs exploitation:
UCB1 = Q(s,a) / N(s,a) + C ร โ(ln(N(s)) / N(s,a))
Where:
Q(s,a) = Total reward from action a in state s
N(s,a) = Visit count for action a in state s
N(s) = Total visits to state s
C = Exploration constant (default: โ2 โ 1.414)
Core Interface
public interface ITectonicEngine
{
/// <summary>Runs MCTS search from current state</summary>
Task<SearchResult> SearchAsync(
WorldState initialState,
SearchConfig config,
CancellationToken ct = default);
/// <summary>Executes best action and returns new state</summary>
Task<ExecutionResult> ExecuteBestActionAsync(
SearchResult search,
CancellationToken ct = default);
}
Search Loop
public async Task<SearchResult> SearchAsync(
WorldState initialState,
SearchConfig config,
CancellationToken ct)
{
var root = new TreeNode(initialState);
for (int i = 0; i < config.MaxIterations; i++)
{
// 1. SELECT - Find promising leaf using UCB1
var leaf = SelectLeaf(root);
// 2. EXPAND - Generate new actions via Planner
var actions = await _planner.ProposeActionsAsync(
leaf.State, ct);
ExpandNode(leaf, actions);
// 3. SIMULATE - Predict outcomes via Simulator
var outcomes = await _simulator.PredictOutcomesAsync(
leaf.State, actions, ct);
// 4. EVALUATE - Score outcomes via Critic
var scores = await _critic.EvaluateAsync(
outcomes, ct);
// 5. BACKPROPAGATE - Update tree statistics
Backpropagate(leaf, scores);
}
return new SearchResult(root, GetBestPath(root));
}
Key Features
๐ Parallel Simulation
Run multiple MCTS iterations concurrently with virtual loss to prevent thread collision
๐ Progressive Widening
Dynamically limit branching factor based on visit counts to focus on promising paths
๐ง RAVE Enhancement
Rapid Action Value Estimation shares statistics across sibling nodes for faster convergence
๐พ Transposition Table
Cache and reuse evaluations for identical states across different tree paths
๐ Planner Agent
The Planner Agent generates diverse action candidates at each decision point. It explores the action space creatively while staying grounded in what's actually achievable given the current world state.
Role in SPIRAL
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ PLANNER AGENT โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ โ โ Input: Output: โ โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โข Current State โ โ ProposedAction[] โ โ โ โ โข Goal โ โโโถ โ โโ Action A (explore) โ โ โ โ โข History โ โ โโ Action B (exploit) โ โ โ โ โข Constraints โ โ โโ Action C (fallback) โ โ โ โโโโโโโโโโโโโโโโโโโ โ โโ Action D (creative) โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ Diversity Mechanisms: โ โ โข Temperature sampling (T=0.7 to T=1.2) โ โ โข Categorical prompting (safe/risky/creative) โ โ โข Historical deduplication โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Core Interface
public interface IPlannerAgent
{
/// <summary>
/// Generates diverse action candidates for the current state.
/// Returns 3-5 actions balancing exploration and exploitation.
/// </summary>
Task<IReadOnlyList<ProposedAction>> ProposeActionsAsync(
WorldState currentState,
CancellationToken ct = default);
/// <summary>
/// Refines actions based on Critic feedback.
/// </summary>
Task<ProposedAction> RefineActionAsync(
ProposedAction original,
CriticFeedback feedback,
CancellationToken ct = default);
}
ProposedAction Model
public record ProposedAction(
string Id,
string Description,
ActionType Type,
string ToolName,
Dictionary<string, object> Parameters,
float Confidence,
string Rationale,
ActionCategory Category
);
public enum ActionCategory
{
Safe, // Low risk, incremental progress
Risky, // Higher risk, potential breakthrough
Creative, // Novel approach, unexplored
Fallback // Recovery action if others fail
}
Diversity Generation
public async Task<IReadOnlyList<ProposedAction>> ProposeActionsAsync(
WorldState state,
CancellationToken ct)
{
var actions = new List<ProposedAction>();
// Generate diverse candidates with different temperatures
var tasks = new[]
{
GenerateWithCategory(ActionCategory.Safe, 0.3f, state, ct),
GenerateWithCategory(ActionCategory.Risky, 0.9f, state, ct),
GenerateWithCategory(ActionCategory.Creative, 1.2f, state, ct),
GenerateWithCategory(ActionCategory.Fallback, 0.5f, state, ct)
};
var results = await Task.WhenAll(tasks);
actions.AddRange(results.Where(a => a != null)!);
// Deduplicate similar actions
return DeduplicateActions(actions);
}
Key Features
๐ฏ Goal Decomposition
Breaks complex goals into actionable sub-tasks with clear success criteria
๐ Multi-Temperature
Samples at different temperatures to ensure both safe and creative options
๐ก๏ธ Constraint Awareness
Respects resource limits, permissions, and safety boundaries
๐ History Learning
Avoids repeating failed approaches from the conversation history
๐ฎ Simulator Agent
The Simulator Agent predicts outcomes of proposed actions without executing them. This "mental simulation" capability allows NEXUS to evaluate consequences before committing to real-world changes.
Simulation Strategies
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ SIMULATOR AGENT โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ โ โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ โ โ LLM-Based โ โ Rule-Based โ โ Web World Model โ โ โ โ Prediction โ โ Inference โ โ Sandbox Execution โ โ โ โโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโโโโโค โ โ โ โข Creative โ โ โข Fast โ โ โข Accurate โ โ โ โ โข Flexible โ โ โข Reliable โ โ โข Real execution โ โ โ โ โข Uncertain โ โ โข Limited โ โ โข Isolated โ โ โ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโโโโโฌโโโโโโโโโโโ โ โ โ โ โ โ โ โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโ โ โ โผ โ โ โโโโโโโโโโโโโโโโโโโ โ โ โ SimulatedOutcomeโ โ โ โ โข NewState โ โ โ โ โข Confidence โ โ โ โ โข SideEffects โ โ โ โโโโโโโโโโโโโโโโโโโ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Core Interface
public interface ISimulatorAgent
{
/// <summary>
/// Predicts outcomes of actions without executing them.
/// Uses hybrid approach: LLM + rules + sandbox.
/// </summary>
Task<IReadOnlyList<SimulatedOutcome>> PredictOutcomesAsync(
WorldState currentState,
IReadOnlyList<ProposedAction> actions,
CancellationToken ct = default);
/// <summary>
/// Runs action in isolated sandbox for accurate prediction.
/// </summary>
Task<SimulatedOutcome> SandboxExecuteAsync(
ProposedAction action,
IWorldModel sandbox,
CancellationToken ct = default);
}
SimulatedOutcome Model
public record SimulatedOutcome(
string ActionId,
WorldState PredictedState,
float SuccessProbability,
float Confidence,
List<SideEffect> SideEffects,
SimulationMethod Method,
TimeSpan EstimatedDuration,
string Reasoning
);
public record SideEffect(
string Description,
SideEffectType Type, // Reversible, Irreversible, Unknown
float Probability,
string[] AffectedResources
);
Hybrid Prediction Strategy
public async Task<SimulatedOutcome> PredictSingleAsync(
WorldState state,
ProposedAction action,
CancellationToken ct)
{
// Strategy 1: Check rule-based predictions first (fast)
if (_ruleEngine.CanPredict(action.Type))
{
return _ruleEngine.Predict(state, action);
}
// Strategy 2: Use sandbox if available (accurate)
if (_worldModelFactory.CanCreateSandbox(action.Type))
{
await using var sandbox = await _worldModelFactory
.CreateSandboxAsync(state, ct);
return await SandboxExecuteAsync(action, sandbox, ct);
}
// Strategy 3: Fall back to LLM prediction (flexible)
return await _llmPredictor.PredictAsync(state, action, ct);
}
Key Features
๐ Safe Exploration
Test dangerous operations in isolation before real execution
โก Confidence Scoring
Each prediction includes confidence level to guide decision-making
๐ Side Effect Detection
Identifies unintended consequences before they occur
๐ Multi-Strategy
Combines rules, LLM, and sandbox for best accuracy/speed tradeoff
โ๏ธ Critic Agent
The Critic Agent evaluates simulated outcomes and provides feedback for MCTS backpropagation. It implements self-reflection capabilities, scoring actions across multiple dimensions.
Evaluation Flow
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ CRITIC AGENT โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ โ โ SimulatedOutcome โโโถ Multi-Dimensional Scoring โ โ โ โ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ โ โ โ Progress โ Safety โ Efficiency โ Reversib. โ โ โ โ (0.35) โ (0.30) โ (0.20) โ (0.15) โ โ โ โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโค โ โ โ 0.85 โ 0.92 โ 0.71 โ 0.88 โ โ โ โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ โ โ โ โ โ โผ โ โ Weighted Score: 0.847 โ โ โ โ โ โผ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ Feedback & Suggestions โ โ โ โ โข "Consider adding rollback mechanism" โ โ โ โ โข "File operation could fail on permissions" โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Core Interface
public interface ICriticAgent
{
/// <summary>
/// Evaluates simulated outcomes and returns scores for MCTS.
/// Higher scores indicate better actions.
/// </summary>
Task<IReadOnlyList<CriticEvaluation>> EvaluateAsync(
IReadOnlyList<SimulatedOutcome> outcomes,
CancellationToken ct = default);
/// <summary>
/// Provides detailed feedback for action refinement.
/// </summary>
Task<CriticFeedback> GetFeedbackAsync(
SimulatedOutcome outcome,
CancellationToken ct = default);
}
Multi-Dimensional Scoring
public async Task<CriticEvaluation> EvaluateSingleAsync(
SimulatedOutcome outcome,
CancellationToken ct)
{
// Score across multiple dimensions
var dimensions = new Dictionary<string, (float score, float weight)>
{
["progress"] = (ScoreProgress(outcome), 0.35f),
["safety"] = (ScoreSafety(outcome), 0.30f),
["efficiency"] = (ScoreEfficiency(outcome), 0.20f),
["reversibility"] = (ScoreReversibility(outcome), 0.15f)
};
// Calculate weighted score
var weightedScore = dimensions.Sum(d => d.Value.score * d.Value.weight);
// Generate improvement suggestions via LLM
var suggestions = await GenerateSuggestionsAsync(outcome, dimensions, ct);
return new CriticEvaluation(
outcome.ActionId,
weightedScore,
dimensions.ToDictionary(d => d.Key, d => d.Value.score),
suggestions,
DetermineVerdict(weightedScore)
);
}
Evaluation Model
public record CriticEvaluation(
string ActionId,
float OverallScore, // 0.0 to 1.0
Dictionary<string, float> DimensionScores,
List<string> Suggestions,
Verdict Verdict
);
public enum Verdict
{
StrongApprove, // Score >= 0.85
Approve, // Score >= 0.70
Neutral, // Score >= 0.50
Caution, // Score >= 0.30
Reject // Score < 0.30
}
Key Features
๐ฏ Multi-Dimensional
Scores progress, safety, efficiency, and reversibility independently
๐ก Self-Reflection
LLM-powered analysis identifies risks and improvements
โฌ๏ธ Backpropagation
Scores flow back through MCTS tree to improve future selections
๐ง Refinement Loop
Feedback enables Planner to improve rejected actions
๐ก๏ธ SENTINEL MCP
System Entrypoint for Network Tasks, Intelligent Node Execution Layer โ the Ubuntu MCP server that provides NEXUS with full infrastructure control through the Model Context Protocol.
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ SENTINEL MCP โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ MCP Protocol Layer โ โ โ โ (JSON-RPC 2.0 over stdio/HTTP) โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ โโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโดโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโ โ โ โ SSH โ Docker โ File โ Network โ System โ โ โ โ Tools โ Tools โ Tools โ Tools โ Tools โ โ โ โโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโค โ โ โssh_exec โcontainerโread_file โhttp_get โget_info โ โ โ โssh_copy โ _run โwrite_file โcurl โps_list โ โ โ โtunnel โ logs โlist_dir โdns_queryโkill_procโ โ โ โkeygen โ build โchmod โport_scanโcron_add โ โ โ โโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโ โ โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ Security Layer โ โ โ โ โข Permission checks โข Audit logging โข Rate limiting โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Core Interface
public interface ISentinelMcp
{
/// <summary>Lists all available MCP tools</summary>
Task<IReadOnlyList<ToolDefinition>> ListToolsAsync(
CancellationToken ct = default);
/// <summary>Executes a tool with given parameters</summary>
Task<ToolResult> ExecuteToolAsync(
string toolName,
Dictionary<string, object> parameters,
CancellationToken ct = default);
/// <summary>Checks if tool execution is permitted</summary>
Task<bool> CanExecuteAsync(
string toolName,
SecurityContext context,
CancellationToken ct = default);
}
Tool Categories
| Category | Tools | Risk Level | Requires Approval |
|---|---|---|---|
| SSH | ssh_execute, ssh_copy, ssh_tunnel, ssh_keygen | High | Yes |
| Docker | container_run, container_stop, docker_build, get_logs | High | Yes |
| File | read_file, write_file, list_dir, chmod, delete | Medium | Write ops only |
| Network | http_get, curl, dns_query, port_scan | Low | No |
| System | get_system_info, list_processes, kill_process, add_cron | High | Destructive only |
Tool Execution
public async Task<ToolResult> ExecuteToolAsync(
string toolName,
Dictionary<string, object> parameters,
CancellationToken ct)
{
// 1. Validate tool exists
var tool = _tools.GetOrDefault(toolName)
?? throw new ToolNotFoundException(toolName);
// 2. Security check
if (!await _security.AuthorizeAsync(tool, _context, ct))
throw new UnauthorizedToolAccessException(toolName);
// 3. Validate parameters
var validated = tool.Schema.Validate(parameters);
// 4. Execute with timeout
using var cts = CancellationTokenSource
.CreateLinkedTokenSource(ct);
cts.CancelAfter(tool.Timeout);
var result = await tool.ExecuteAsync(validated, cts.Token);
// 5. Audit log
await _audit.LogAsync(new ToolExecutionLog
{
Tool = toolName,
Parameters = parameters,
Result = result,
Timestamp = DateTime.UtcNow
});
return result;
}
Key Features
๐ Security First
Every tool call passes through permission checks and audit logging
๐ก MCP Protocol
Standard JSON-RPC 2.0 interface compatible with any MCP client
๐ณ Docker Native
Full container lifecycle management for isolated execution
๐ Remote Access
SSH tunneling and remote execution across infrastructure
๐ Web World Models
Web World Models provide persistent, typed sandbox environments where agents can safely execute actions, maintain state, and create checkpoints. Built on web technology as a universal substrate.
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ WEB WORLD MODELS โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ World Model Instance โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ
โ โ State: { โ โ
โ โ files: Map<path, content>, โ โ
โ โ processes: Process[], โ โ
โ โ network: NetworkState, โ โ
โ โ env: Map<key, value> โ โ
โ โ } โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโผโโโโโโ โโโโโโโโผโโโโโโโ โโโโโโโผโโโโโโ โ
โ โ Checkpointโ โ Execute โ โ Rollback โ โ
โ โ Save โ โ Action โ โ Restore โ โ
โ โโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โ
โ Checkpoints: [cp_001] โโโถ [cp_002] โโโถ [cp_003] โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Core Interface
public interface IWorldModel : IAsyncDisposable
{
/// <summary>Current state of the world</summary>
WorldState CurrentState { get; }
/// <summary>Unique identifier for this world instance</summary>
string WorldId { get; }
/// <summary>Executes action and returns new state</summary>
Task<WorldState> ExecuteAsync(
ProposedAction action,
CancellationToken ct = default);
/// <summary>Creates a checkpoint of current state</summary>
Task<string> CheckpointAsync(
string? label = null,
CancellationToken ct = default);
/// <summary>Restores state from a checkpoint</summary>
Task RestoreAsync(
string checkpointId,
CancellationToken ct = default);
/// <summary>Forks world into independent copy</summary>
Task<IWorldModel> ForkAsync(
CancellationToken ct = default);
}
Typed World State
public record WorldState
{
public required string WorldId { get; init; }
public required WorldType Type { get; init; }
public required DateTime Timestamp { get; init; }
// File system state
public ImmutableDictionary<string, FileEntry> Files { get; init; }
// Process state
public ImmutableList<ProcessInfo> Processes { get; init; }
// Network state
public NetworkState Network { get; init; }
// Environment variables
public ImmutableDictionary<string, string> Environment { get; init; }
// Custom typed state per world type
public ImmutableDictionary<string, JsonElement> Custom { get; init; }
}
public enum WorldType
{
Docker, // Containerized environment
Browser, // Headless browser sandbox
FileSystem, // Virtual file system
Database, // Database sandbox
Composite // Multiple types combined
}
Checkpoint System
public async Task<string> CheckpointAsync(
string? label,
CancellationToken ct)
{
var checkpointId = $"cp_{Guid.NewGuid():N}";
// Commit container state to image
await _docker.Containers.CommitContainerChangesAsync(
new CommitContainerChangesParameters
{
ContainerID = _containerId,
RepositoryName = $"nexus-checkpoint/{WorldId}",
Tag = checkpointId
}, ct);
// Store metadata
_checkpoints[checkpointId] = new CheckpointMeta
{
Id = checkpointId,
Label = label,
State = CurrentState,
CreatedAt = DateTime.UtcNow,
ParentId = _currentCheckpoint
};
_currentCheckpoint = checkpointId;
return checkpointId;
}
Key Features
๐ Time Travel
Save and restore state at any point with checkpoint branching
๐ณ Fork & Explore
Clone worlds for parallel exploration of different paths
๐ฆ Typed State
Strongly-typed world state with immutable data structures
๐ Isolation
Full sandbox isolation prevents state leakage between worlds
โก Orchestrator
The Orchestrator implements the Chain of Responsibility pattern to coordinate workflow execution. Requests flow through a series of handlers that process sequentially until one can handle the request.
Chain of Responsibility
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ ORCHESTRATOR โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ โ โ Request โโโถ โโโโโโโโโโโโโโโ โ โ โ Validation โ โโโถ Invalid? โโโถ Error Response โ โ โ Handler โ โ โ โโโโโโโโฌโโโโโโโ โ โ โ Valid โ โ โผ โ โ โโโโโโโโโโโโโโโ โ โ โ Logging โ โโโถ Log request details โ โ โ Handler โ โ โ โโโโโโโโฌโโโโโโโ โ โ โ โ โ โผ โ โ โโโโโโโโโโโโโโโ โ โ โ Caching โ โโโถ Cached? โโโถ Return cached โ โ โ Handler โ โ โ โโโโโโโโฌโโโโโโโ โ โ โ Not cached โ โ โผ โ โ โโโโโโโโโโโโโโโ โ โ โ Execution โ โโโถ Process request โ โ โ Handler โ โ โ โโโโโโโโฌโโโโโโโ โ โ โ โ โ โผ โ โ Response โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Core Abstractions
public interface IRequestHandler<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
/// <summary>Order in the chain (lower = earlier)</summary>
int Order { get; }
/// <summary>Whether this handler can process the request</summary>
bool CanHandle(TRequest request);
/// <summary>Process request and optionally call next handler</summary>
Task<TResponse> HandleAsync(
TRequest request,
Func<TRequest, Task<TResponse>> next,
CancellationToken ct = default);
}
public interface IOrchestrator
{
Task<TResponse> ExecuteAsync<TRequest, TResponse>(
TRequest request,
CancellationToken ct = default)
where TRequest : IRequest<TResponse>;
}
Orchestrator Implementation
public class Orchestrator : IOrchestrator
{
private readonly IServiceProvider _services;
private readonly ILogger<Orchestrator> _logger;
public async Task<TResponse> ExecuteAsync<TRequest, TResponse>(
TRequest request,
CancellationToken ct)
where TRequest : IRequest<TResponse>
{
// Get all handlers, ordered by priority
var handlers = _services
.GetServices<IRequestHandler<TRequest, TResponse>>()
.OrderBy(h => h.Order)
.ToList();
// Build the chain
Func<TRequest, Task<TResponse>> chain = _ =>
Task.FromException<TResponse>(
new NoHandlerException(typeof(TRequest)));
// Reverse iterate to build from end to start
foreach (var handler in handlers.AsEnumerable().Reverse())
{
var next = chain;
chain = req => handler.HandleAsync(req, next, ct);
}
return await chain(request);
}
}
Handler Examples
public class ValidationHandler<TRequest, TResponse>
: IRequestHandler<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
private readonly IValidator<TRequest> _validator;
public int Order => 100; // Run early
public bool CanHandle(TRequest request) => true;
public async Task<TResponse> HandleAsync(
TRequest request,
Func<TRequest, Task<TResponse>> next,
CancellationToken ct)
{
var result = await _validator.ValidateAsync(request, ct);
if (!result.IsValid)
throw new ValidationException(result.Errors);
return await next(request);
}
}
Built-in Handlers
| Handler | Order | Purpose |
|---|---|---|
| ValidationHandler | 100 | Validates request against schema |
| LoggingHandler | 200 | Logs request/response with timing |
| CachingHandler | 300 | Returns cached responses when available |
| RetryHandler | 400 | Retries failed requests with backoff |
| TimeoutHandler | 500 | Enforces execution time limits |
| ExecutionHandler | 1000 | Actually processes the request |
Key Features
๐ Extensible Chain
Add custom handlers at any point in the pipeline via DI
โฑ๏ธ Timeout Control
Configurable timeouts prevent runaway operations
๐ Retry Logic
Automatic retries with exponential backoff for transient failures
๐ Observability
Built-in logging, metrics, and distributed tracing support
๐ CQRS Pattern
NEXUS implements Command Query Responsibility Segregation to separate read and write operations, enabling optimized data access, better scalability, and cleaner architecture.
The Pattern
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ NEXUS Client โ
โโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Commands โ โ Queries โ
โ (Write Model) โ โ (Read Model) โ
โโโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโค
โ โข Create Task โ โ โข Get Task โ
โ โข Execute Actionโ โ โข List Tasks โ
โ โข Update State โ โ โข Search Historyโ
โโโโโโโโโโฌโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โCommand Handlers โ โ Query Handlers โ
โโโโโโโโโโฌโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Write Store โ โโโโโโโโโถ โ Read Store โ
โ (PostgreSQL) โ Events โ (Elasticsearch) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
Commands & Queries
// Commands (Write operations)
public interface ICommand<TResult> { }
public record ExecuteActionCommand(
string TaskId,
ProposedAction Action,
string RequestedBy
) : ICommand<ActionResult>;
public record CreateTaskCommand(
string Description,
TaskPriority Priority,
Dictionary<string, object> Parameters
) : ICommand<TaskCreatedResult>;
// Queries (Read operations)
public interface IQuery<TResult> { }
public record GetTaskQuery(
string TaskId
) : IQuery<TaskDetails>;
public record SearchHistoryQuery(
string? TaskId,
DateTime? FromDate,
DateTime? ToDate,
int Page = 1,
int PageSize = 20
) : IQuery<PagedResult<HistoryEntry>>;
Mediator Pattern
public interface IMediator
{
/// <summary>Sends a command for execution</summary>
Task<TResult> SendAsync<TResult>(
ICommand<TResult> command,
CancellationToken ct = default);
/// <summary>Executes a query and returns results</summary>
Task<TResult> QueryAsync<TResult>(
IQuery<TResult> query,
CancellationToken ct = default);
}
Event Sourcing Integration
// Event generated by command
public record ActionExecutedEvent(
Guid ExecutionId,
string TaskId,
ActionType ActionType,
bool Success,
DateTime Timestamp
) : IDomainEvent;
// Event handler updates read model
public class ActionExecutedEventHandler : IEventHandler<ActionExecutedEvent>
{
private readonly IReadStore _readStore;
public async Task HandleAsync(ActionExecutedEvent @event, CancellationToken ct)
{
// Update denormalized read model
await _readStore.UpsertAsync(new HistoryEntry
{
Id = @event.ExecutionId.ToString(),
TaskId = @event.TaskId,
ActionType = @event.ActionType.ToString(),
Success = @event.Success,
Timestamp = @event.Timestamp
}, ct);
}
}
Benefits for NEXUS
| Benefit | Impact |
|---|---|
| Read Performance | 10x faster queries via denormalized read models |
| Write Consistency | ACID transactions on write store |
| Scalability | Scale reads and writes independently |
| Audit Trail | Complete command history via event sourcing |
| Flexibility | Different storage optimized per use case |
Key Features
๐ Command Handlers
Dedicated handlers for write operations with validation and business logic
๐ Query Handlers
Optimized read handlers against denormalized data stores
๐จ Event Bus
Commands emit events that sync read models asynchronously
๐๏ธ Dual Storage
PostgreSQL for writes, Elasticsearch for fast queries
Interested in NEXUS?
Whether you're an investor, researcher, or engineer โ we'd love to discuss how NEXUS can transform autonomous agent capabilities.
๐ง Contact Us