29 KiB
Work Remaining
This section describes what remains to be done to bring the current CleverAgents codebase up to the specification.
Last Updated: February 6, 2026
Current State Assessment
What's Implemented
Based on analysis of the current codebase:
- Plan Lifecycle Foundation - The 4-phase lifecycle (Action → Strategize → Execute → Apply), where Action serves as a reusable template stage, is partially implemented in
plan_lifecycle_service.py - Database Models - Models exist for projects, plans, contexts, changes, and actors
- LangGraph Integration - Graph-based workflow support exists but is not fully connected to the plan workflow
- Reactive System - A reactive system with stream routing is present
- Actor System - Actor models and services exist but lack full behavioral definitions
- Basic Context Analysis - Simple context loading and analysis capabilities
- Change Tracking - Basic
ChangeandChangeSetmodels exist
What's Missing
Critical gaps between the specification and current implementation:
- No Resource Abstraction - The unified resource layer for files, databases, APIs is entirely missing
- No Sandboxing - Execute phase writes directly to files without isolation
- No Decision Tree - No decision tracking, storage, or correction mechanism
- No Skills/MCP Integration - No skill registry, skill YAML parsing, tool adapters, or MCP protocol support
- Single-File Limitation - Hard-coded to generate exactly one file per plan
- Text-Based Code Generation - Still parsing LLM output instead of tool-based approach
- No Checkpointing - No rollback or checkpoint capabilities
- No Code Intelligence / ACMS - Missing ACMS implementation: UKO ontology analyzers, Context Assembly Pipeline (the 10-component pluggable pipeline for strategy orchestration, fragment fusion, and context finalization), CRP skill, context budget calculator, and backend indices (text, vector, graph). The full design is specified in the "Advanced Context Management System (ACMS)" section.
- No Context Tiers - No hot/warm/cold memory architecture, no warm-to-cold demotion, no temporal versioning of UKO nodes
- Limited Validation - Basic stub validation instead of semantic checks
Work Items by Priority
1) Implement Tool-Based Resource Modification (Critical Foundation)
Problem
The current system generates code as a single text blob that gets written to one file. The specification requires a modern tool-based approach where LLMs invoke discrete operations on resources.
Implementation Steps
-
Create Resource Abstraction Layer
# New modules needed: src/cleveragents/domain/models/resources.py src/cleveragents/domain/resources/handlers.py src/cleveragents/domain/resources/sandbox.py -
Implement Built-in Tools (via built-in skills)
# Core file operations (provided by built-in skill groups) read_file(path: str) -> str write_file(path: str, content: str) -> None edit_file(path: str, changes: list[Edit]) -> None delete_file(path: str) -> None move_file(src: str, dst: str) -> None create_directory(path: str) -> None list_files(pattern: str) -> list[str] search_files(pattern: str, content_pattern: str) -> list[Match] -
Connect Tools to ChangeSet
- Each tool invocation that modifies resources creates a
Changerecord - ChangeSet accumulates these changes during execution
- No more parsing LLM text output for code
- Each tool invocation that modifies resources creates a
Estimated Effort: 2-3 weeks
2) Implement Sandbox Infrastructure (Critical for Safety)
Problem
Execute phase currently writes directly to the project. The specification requires all changes happen in an isolated sandbox that can be reviewed before applying.
Implementation Steps
-
Define Sandbox Interface
class Sandbox(Protocol): def create() -> SandboxRef def read(path: str) -> Content def write(path: str, content: Content) -> Change def diff() -> DiffView def commit() -> None def rollback() -> None -
Implement Sandbox Strategies
GitWorktreeSandbox- For git repositories (preferred)FilesystemCopySandbox- For non-git projectsTransactionSandbox- For databasesNoOpSandbox- For non-sandboxable resources
-
Lazy Sandbox Creation
- Only create sandboxes when resources are accessed
- Each plan gets its own sandbox namespace
Estimated Effort: 2 weeks
3) Build Decision Tree System (Core Innovation)
Problem
No decision tracking exists. The specification's key innovation is recording every decision with full context, enabling correction without full re-execution.
Implementation Steps
-
Create Decision Models
-- New tables needed CREATE TABLE decisions ( decision_id TEXT PRIMARY KEY, -- ULID plan_id TEXT NOT NULL, parent_decision_id TEXT, decision_type TEXT NOT NULL, question TEXT NOT NULL, chosen_option TEXT NOT NULL, alternatives_considered TEXT, -- JSON array context_snapshot TEXT NOT NULL, -- JSON created_at TEXT NOT NULL ); -
Implement Decision Recording
- Every choice during Strategize creates a Decision record
- Capture complete context snapshot with each decision
- Track downstream dependencies
-
Build Correction Mechanism
- Mark decision as superseded - Recompute only affected subtree - Preserve unaffected workagents plan correct <decision_id> --mode=revert --guidance "<new decision>"
Estimated Effort: 3 weeks
4) Implement Advanced Context Management System (ACMS) (Scalability Enabler)
Problem
Current context is limited to a few hundred characters from a few files. Large codebases require intelligent, pluggable context discovery with multiple retrieval strategies, a universal knowledge representation, and demand-driven context assembly. The full ACMS design is specified in the "Advanced Context Management System (ACMS)" section of this document.
Implementation Steps
-
Universal Knowledge Ontology (UKO) Foundation
- Implement the four-layer UKO ontology hierarchy (Layer 0: universal foundation, Layer 1: domain specializations, Layer 2: paradigm/format specializations, Layer 3: technology-specific)
- Implement the DetailDepth / DetailLevelMap system with inheritance-based resolution (Layer 0 universal integer semantics, per-domain named level maps at Layer 1, paradigm refinements at Layer 2, language-specific insertions at Layer 3)
- Build source code analyzers for Python, TypeScript, Rust, Java (extract UKO nodes from source code via
uko-code:,uko-oo:,uko-func:,uko-py:, etc.) - Implement document analyzers for Markdown, reStructuredText, HTML (
uko-doc:) with semantic awareness (topic extraction, implicit cross-reference inference viauko-doc:discussesTopic, citation resolution) - Implement data schema analyzers for PostgreSQL, MySQL, SQLite (
uko-data:) with schema introspection, foreign key graph construction, view dependency analysis, and stored procedure parsing - Implement infrastructure analyzers for Docker Compose, Kubernetes (
uko-infra:) with service dependency graph construction and config reference resolution - Implement temporal versioning (
validFrom,validUntil,isCurrent,isRevisionOf) - Integrate eager indexing on resource add via the Resource Registry lifecycle hooks
-
Three-Index Backend Architecture
- Text Index: Tantivy/SQLite FTS for exact keyword matches
- Vector Index: FAISS/Qdrant for semantic embedding search
- Graph Store: RDF store for UKO relationship traversal
- Implement
ScopedBackendViewto auto-filter all queries to plan project resources
-
Context Request Protocol (CRP)
- Implement the
builtin/contextskill with tools:request_context,query_history,get_context_budget - Implement
ContextRequestandContextResponsedata structures - Integrate CRP with actor execution loop
- Implement the
-
Context Assembly Pipeline (10-component pluggable pipeline)
- Implement
ContextStrategybase class and strategy registration - Build six built-in strategies:
simple-keyword(0.3),semantic-embedding(0.6),breadth-depth-navigator(0.85),arce(0.95),temporal-archaeology(0.5),plan-decision-context(0.7) - Phase 1 — Strategy Orchestration: Implement
StrategySelectorProtocol/ConfidenceWeightedSelector,BudgetAllocatorProtocol/ProportionalBudgetAllocator,StrategyExecutorProtocol/ParallelStrategyExecutor(with circuit breaker) - Phase 2 — Fragment Fusion: Implement
FragmentDeduplicatorProtocol/ContentHashDeduplicator,DetailDepthResolverProtocol/MaxDepthResolver,FragmentScorerProtocol/WeightedCompositeScorer,BudgetPackerProtocol/GreedyKnapsackPacker,FragmentOrdererProtocol/RelevanceCoherenceOrderer - Phase 3 — Context Finalization: Implement
PreambleGeneratorProtocol/ProvenancePreambleGenerator,SkeletonCompressorProtocol/DepthReductionCompressor - Implement
ContextAssemblyPipelineorchestrator andPipelineConfigResolver(scope chain: plan > project > global > built-in)
- Implement
-
Context Budget Calculator & Refresh Manager
- Dynamic budget computation from model context window, response reserve, tool definitions, system prompt
- Skeleton compression and plan context inheritance
- Automatic re-assembly on budget change exceeding refresh threshold
-
Tiered Context System
- Hot: Current working set assembled by ACMS (in LLM context)
- Warm: Recent decisions and search results (warm retention window)
- Cold: Historical data, patterns, and archived UKO snapshots (queryable via retrieval)
Estimated Effort: 8-10 weeks
5) Complete Actor System with Behavioral Definitions
Problem
Actors exist but don't define behavior beyond model selection. The specification requires actors to be composable graphs with tools, memory, and context policies.
Implementation Steps
-
Extend Actor Configuration
actors: my_strategist: type: graph config: provider: anthropic model: claude-3-opus memory_policy: per_plan context_view: architect # High-level view skills: - local/file-ops # provides read_file - local/code-intelligence # provides search_code, analyze_dependencies routes: strategize: entry_point: analyze nodes: - name: analyze type: llm - name: plan type: llm -
Implement Tool Access Policies
- Strategy actors: read-only tools
- Execute actors: read/write within sandbox
- Apply actors: commit tools
-
Actor-Specific Context Views
- Strategist: Architecture, dependencies, patterns
- Executor: Implementation details, specific files
- Reviewer: Diffs, tests, risk analysis
Estimated Effort: 2 weeks
6) Resource System, Resource Types, and Resource Registry
Problem
Resources are currently defined inline within projects. The specification requires resources to be independently registered first-class entities with a type system, DAG relationships (physical/virtual), auto-discovery, and content-identity tracking. Tools need resource bindings to declare and resolve their resource dependencies.
Implementation Steps
-
Resource Type Registry and CLI
- Implement 24 built-in resource types: 15 physical (
git-checkout,git,git-remote,git-branch,git-tag,git-commit,git-tree,git-tree-entry,git-stash,git-submodule,fs-mount,fs-directory,fs-file,fs-symlink,fs-hardlink) and 9 virtual (file,directory,symlink,commit,branch,tag,remote,submodule,tree) - Implement resource type YAML parsing and validation for custom types
- Implement
agents resource type add [<span style="color: cyan;">--update</span>]/remove/list/showcommands - Implement dynamic CLI subcommand registration (custom types create new
agents resource addsubcommands)
- Implement 24 built-in resource types: 15 physical (
-
Resource Registry and CLI
- Implement
agents resource add <type>/remove/list/show/treecommands - Implement Resource Registry persistence in database
- Implement DAG parent/child relationships with type constraints and cycle detection
- Implement
agents resource link-child/unlink-childfor manual DAG management
- Implement
-
Auto-Discovery System
- Implement handler-driven child resource discovery (git-checkout discovers git + fs-directory worktree root; git discovers remotes, branches, tags, commits, stashes, submodules; git-commit discovers root git-tree; git-tree discovers tree entries + subtrees; fs-mount discovers root fs-directory; fs-directory discovers subdirectories, files, symlinks, hardlinks)
- Implement resource reuse during discovery (link existing resources instead of duplicating)
- Implement refresh mechanism for keeping discovered children up to date
-
Physical/Virtual Resource Model
- Implement content hashing for identity tracking
- Implement virtual resource linking (shared virtual parents for identical physical resources)
- Implement divergence detection (unlink when content changes)
-
Project-Resource Linking
- Replace
agents project add-resource/remove-resourcewithlink-resource/unlink-resource - Implement project-level overrides (read-only, alias)
- Migrate any existing inline resource data to Resource Registry
- Replace
-
Resource Handlers
- Implement
GitCheckoutHandlerwith auto-discovery, sandbox creation, checkpoint support - Implement
GitHandlerfor git repository structure discovery (remotes, branches, tags, commits, stashes, submodules) - Implement
GitObjectHandlerfor git-commit, git-tree, git-tree-entry (read-only access to git objects) - Implement
GitRefHandlerfor git-branch, git-tag, git-stash (read/write ref manipulation) - Implement
GitConfigHandlerfor git-remote, git-submodule (read-only config access) - Implement
FilesystemHandlerwith auto-discovery for fs-mount, fs-directory, fs-file, fs-symlink, fs-hardlink - Implement handler plugin system for custom resource types
- Implement
Estimated Effort: 5 weeks
7) MCP Integration, Tool System, Skill System, and Tool-Resource Bindings
Problem
No tool or skill abstraction exists. The specification defines tools as independently registered operations managed via agents tool CLI commands, and skills as namespaced collections of tools managed via agents skill CLI commands. Tools can be sourced from MCP servers, Agent Skills folders, built-ins, and custom code. Tools also need resource bindings to declare and resolve their dependencies on resources.
Implementation Steps
-
Tool Registry and CLI
- Implement tool YAML parsing and validation (including
resourcessection for resource slots) - Implement
agents tool add [<span style="color: cyan;">--update</span>]/remove/list/showcommands - Implement Tool Registry persistence in database
- Implement anonymous tool support (inline definitions without registration)
- Implement tool YAML parsing and validation (including
-
Skill Registry and CLI
- Implement skill YAML parsing and validation
- Implement
agents skill add [<span style="color: cyan;">--update</span>]/remove/list/show/toolscommands - Implement hierarchical skill composition (includes) with per-tool metadata overrides
- Implement Skill Registry persistence in database
- Implement named tool references (resolving from Tool Registry) and anonymous inline tools
-
Tool-Resource Binding System
- Implement resource slot parsing and validation in tool YAML
- Implement three binding modes: contextual, static, parameter
- Implement binding resolution at activation time (contextual/static) and invocation time (parameter)
- Implement resource type compatibility validation
- Implement built-in tool implicit resource bindings
- Inject bound resources into
ToolExecutionContext.resources
-
MCP Tool Adapter
class MCPToolAdapter: def wrap_mcp_tool(self, tool) -> Tool: # Add sandbox interception # Add change tracking # Add capability metadata # Add resource binding support -
Tool Capability Metadata
class ToolCapability: read_only: bool write_scope: list[str] # References resource slot names checkpointable: bool idempotent: bool side_effects: list[str] -
External MCP Server Support
# In tool or skill YAML configuration mcp_servers: - name: github command: "npx @anthropic/mcp-github" env: {GITHUB_TOKEN: "${GITHUB_TOKEN}"} -
Agent Skills Adapter
- Implement SKILL.md frontmatter parsing for discovery
- Implement progressive disclosure (metadata → instructions → resources)
- Implement sandboxed script execution
-
Metadata Override System
- Implement shallow-merge override logic for tool capability metadata
- Support overrides at skill-level (tool refs), include-level (tool_overrides), and actor graph node-level
- Built-in tool metadata is not overridable
Estimated Effort: 5 weeks
8) Implement Validation and Semantic Error Prevention
Problem
Current validation is a stub. The specification requires multi-layer semantic validation. Validations are now a specialized subtype of Tool — they extend the Tool class with a mode (required/informational) and a structured JSON return format (passed, message, data). They can be attached to resources directly, through projects, or through plans.
Implementation Steps
-
Decision-Time Validation
- Validate choices during Strategize
- Check alternatives for feasibility
- Record validation in decision metadata
-
Execution-Time Guards
# Actor references a skill containing validation tools skills: - local/semantic-validators # validate_api_compatibility, # check_invariants, verify_test_coverage -
Validation as Tool Subtype
# Register validations (tool subtypes) agents validation add --config ./validations/run-tests.yaml --required local/run-tests agents validation add --config ./validations/lint-check.yaml --required local/lint-check# Attach to resource (directly or scoped to a project) agents validation attach --project my-api my-api-repo local/run-tests agents validation attach my-api-repo local/lint-check -
Validation Class Inheritance
- Implement Validation as a class extending Tool
- Reuse Tool Registry, binding resolution, and execution flow
- Add only: mode field, return format enforcement, attachment scoping
-
Tool Wrapping
- Implement
wrapsfield resolution: validate wrapped Tool exists at registration time, store reference - Implement
transformfunction: sandboxed Python execution that converts wrapped Tool output to{ "passed", "message", "data" } - Implement property inheritance from wrapped Tool (
input_schema,resource_slots,timeout) with override semantics - Enforce read-only semantics on wrapped Tool invocation regardless of wrapped Tool's
writesflag - Emit registration-time warning when wrapping a Tool with
writes: true - Implement
argument_mappingfield: map Validation input arguments to wrapped Tool input arguments with support for renaming and fixed values - (Deferred) Wrapped Tool deduplication: when multiple Validations wrap the same Tool with identical forwarded arguments, invoke it once and fan out output to each
transform. Deferred due to complexity around argument equivalence and cache invalidation during fix-then-revalidate loops - Implement default transform (pass-through for output already containing
passedfield)
- Implement
Estimated Effort: 2 weeks
9) Connect LangGraph to Plan Lifecycle
Problem
The reactive/LangGraph infrastructure exists but isn't connected to the main plan workflow.
Implementation Steps
-
Create Unified Plan Graph
class PlanLifecycleGraph: def strategize_subgraph(self) -> StateGraph def execute_subgraph(self) -> StateGraph def apply_subgraph(self) -> StateGraph -
Wire Phase Transitions
usecommand triggers strategize graphexecutecommand triggers execute graphapplycommand triggers apply graph
-
Remove Linear Pipeline
- Replace tell/build/apply with graph execution
- Maintain backward compatibility at CLI level
Estimated Effort: 1 week
Implementation Roadmap
Phase 1: Foundation (8-10 weeks)
- Tool-based resource modification (critical foundation)
- Sandbox infrastructure
- Decision tree system
Phase 2: Core Systems (10-12 weeks)
- Advanced Context Management System (ACMS) — UKO, CRP, strategies, fusion, budget
- Actor system with behavioral definitions
- Resource system, resource types, and resource registry
- MCP integration, tool system, skill system, and tool-resource bindings
Phase 3: Validation and Integration (3 weeks)
- Validation and semantic error prevention
- Connect LangGraph to plan lifecycle
Phase 4: Production Hardening (4 weeks)
- Checkpointing and rollback
- Cost controls and rate limiting
- Security fixes (remove eval, fix async)
Total Estimated Timeline: 6-7 months
Key Success Metrics
- Multi-file generation: Can generate a REST API with routes/, models/, tests/
- Safe execution: All changes happen in sandbox, reviewed before apply
- Decision correction: Can correct a decision and recompute only affected work
- Scale to large codebases: ACMS with UKO, pluggable strategies, and fusion can work with 10K+ file projects efficiently
- Semantic safety: Catches breaking changes before they're applied
Migration Strategy
The implementation can proceed incrementally:
- Start with resource abstraction (enables everything else)
- Add sandboxing to existing execute phase
- Gradually replace text parsing with tool invocations
- Build decision tree alongside existing flow
- Enhance context as indexing comes online
This allows the system to remain functional during development while progressively adding the architectural improvements described in the specification.