Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: MY-AI CI

on:
push:
branches: [main, v6-cognitive-core, v7-recursive-agent-graph, fix/v10-ci-current-engine]
branches: [main, v6-cognitive-core, v7-recursive-agent-graph, fix/v10-ci-current-engine, v10-self-healing-runtime]
pull_request:
branches: [main]

Expand All @@ -14,6 +14,7 @@ env:
MYAI_KNOWLEDGE_DB_PATH: /tmp/my-ai-knowledge.sqlite3
MYAI_AGENT_MODE: auto
MYAI_CODE_INDEX_ENABLED: true
MYAI_SELF_HEALING_ENABLED: true

jobs:
test:
Expand Down Expand Up @@ -53,7 +54,7 @@ jobs:
run: mypy src

smoke:
name: Smoke / current package and architecture
name: Smoke / V10 current package and architecture
runs-on: ubuntu-latest
needs: test
steps:
Expand Down Expand Up @@ -89,10 +90,11 @@ jobs:
)

ai = AIEngine()
assert ai.version == "v10.0"
added = ai.add_document(Document(source="ci.txt", text="Paris is the capital of France."))
assert added == 1
result = ai.generate(ChatRequest(message="What is the capital of France?"))
assert result.version == "v9.1"
assert result.version == "v10.0"
assert result.text

decision = AdaptiveModelRouter().choose(
Expand Down
100 changes: 27 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,43 @@
# MY-AI

## V9 — Cognitive Mesh + Self-Evolving Repository Intelligence
## V10 — Cognitive Mesh + Self-Healing Runtime

MY-AI V9 extends V8's causal repository twin into a unified cognitive mesh for repository reasoning, targeted debugging, runtime evidence and evidence-gated self-evolution.
MY-AI V10 extends V9.1 with a bounded self-healing runtime on top of the cognitive mesh. The system keeps the repository/program/causal graphs, persistent runtime traces, recursive multi-model workers, capability ledger, and evidence-gated evolution while adding failure signatures, bounded reproduction, repair episodes, controlled fault injection, and stable-code health metadata.

### V9 architecture
### V10 architecture

```text
request / failure
-> cognitive routing
-> unified program graph
-> structure
-> calls
-> data-flow references
-> control-flow regions
-> structure / calls / data-flow / control-flow
-> causal repository twin
-> dependency impact
-> source slices
-> dependency impact / source slices
-> runtime trace graph
-> exception/state events
-> causal links
-> recursive multi-model workers
-> independent judge
-> targeted validation
-> evolution memory
-> strategy scores
-> reusable lessons
-> promotion gating
-> state / exception / causal links
-> failure signature memory
-> bounded reproduction
-> recursive repair workers + independent judge
-> sandbox / validation boundary
-> fault-injection self-tests
-> stable-code health map
-> verified strategy / capability ledger
```

### Unified Program Graph
### Self-healing principles

`ProgramGraph` adds a repository-level intermediate representation over the persistent code index. Instead of treating files as isolated text blobs, V9 keeps compact nodes/edges for declarations, calls, data-flow references and control-flow regions. `program_slice()` returns only the local graph neighborhood and matching source ranges needed for a task.
1. Detect before repairing.
2. Reproduce before trusting a hypothesis whenever possible.
3. Use the smallest causally relevant context; preserve verified code.
4. Keep retries and repair attempts bounded.
5. Never auto-promote code from the repair runtime; promotion remains validation-gated.
6. Convert verified repair experience into reusable memory and regression evidence.

This follows the current repository-agent direction represented by RPG and RPG-Encoder, which use persistent repository graphs to unify structure, semantics and dependencies and evolve the representation incrementally rather than repeatedly re-reading an entire codebase. RPG-Encoder reports large maintenance-overhead reductions and strong repository localization results on SWE-bench evaluations.
### Runtime controls

### Runtime Trace Graph

`RuntimeTraceGraph` stores compact exception/state events and causal links in `data/runtime_trace.jsonl`. The graph survives restarts, so future diagnosis can reuse runtime evidence instead of rediscovering the same sequence of events.

### Self-evolution loop

`EvolutionMemory` records task strategy, correctness, latency, token use and lessons. `EvolutionBenchmark` ranks strategies and only promotes a candidate when it is successful and materially better than the baseline. This is deliberately evidence-gated: memory can guide future strategy selection, but it cannot replace execution evidence.

Recent 2026 research on self-evolving coding agents emphasizes executable feedback, repository context and coding trajectories as the core evidence sources for safe improvement. EvoCodeBench explicitly evaluates correctness together with efficiency and improvement over repeated attempts.

### V9 public engine

```python
from myai import AIEngine

ai = AIEngine() # V9 by default
```

Legacy V7.1 and V8 engines remain importable for compatibility.

### Targeted repair context

```python
diagnosis = ai.diagnose_failure(traceback_text)
repair_context = ai.repair_context_v9(traceback_text)
program_slice = ai.program_slice("refresh_token")
```

The repair specialist receives the failure hypothesis, graph slice, relevant source ranges, nearby runtime events and the best historically validated strategy. Unrelated files are not required for the repair context.

### Local setup

```bash
./scripts/setup.sh
source .venv/bin/activate
cp .env.example .env
pytest
```

Runtime dependencies are listed in `requirements.txt`; development/CI dependencies are in `requirements-dev.txt`.

### Persistent state

- `data/knowledge.sqlite3` — semantic knowledge
- `data/code_index.json` — freshness-aware code index
- `data/repair_memory.jsonl` — validated repair experience
- `data/runtime_trace.jsonl` — runtime events and causal links
- `data/evolution_memory.jsonl` — strategy/evolution records

### Research grounding

V9 deliberately combines repository graphs, fine-grained program slices, executable runtime evidence and self-evolving memory rather than relying on any one technique. Current research shows memory remains task-dependent, so V9 keeps multiple evidence channels and validates promotion through actual outcomes instead of assuming that stored memory is universally reliable.
- `MYAI_SELF_HEALING_ENABLED=true`
- `MYAI_SELF_HEALING_MAX_REPAIR_ATTEMPTS=2`
- `MYAI_SELF_HEALING_REPRODUCTION_TIMEOUT_SECONDS=30`
- `MYAI_FAILURE_SIGNATURE_PATH=data/failure_signatures.jsonl`
- `MYAI_REPAIR_EPISODE_PATH=data/repair_episodes.jsonl`
- `MYAI_CODE_HEALTH_PATH=data/code_health.json`
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"

[project]
name = "my-ai"
version = "0.9.0"
description = "MY-AI V9: cognitive mesh, unified program graph, runtime traces, self-evolving strategy memory"
version = "0.10.0"
description = "MY-AI V10: cognitive mesh, causal repository intelligence, bounded self-healing runtime, fault testing, and evidence-driven evolution"
readme = "README.md"
requires-python = ">=3.11,<3.14"
dependencies = [
Expand Down
38 changes: 26 additions & 12 deletions src/myai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""MY-AI V9.1 public package."""
"""MY-AI V10 public package with self-healing runtime controls."""

from .agent_graph import ExecutionBudget, RecursiveAgentGraph, TaskNode, WorkArtifact
from .agent_runtime import AgentRuntimeResult, MultiModelAgentRuntime
Expand All @@ -11,6 +11,7 @@
from .context_contract import CognitiveContext, build_cognitive_context
from .engine import AIEngine as LegacyAIEngine
from .evolution import EvolutionBenchmark, EvolutionMemory, EvolutionRecord, StrategyScore
from .fault_lab import FaultCase, FaultInjectionLab, FaultResult
from .graph_v9 import ProgramEdge, ProgramGraph, ProgramNode, ProgramSlice
from .knowledge import (
Document,
Expand All @@ -35,13 +36,17 @@
RepairMemory,
RepairMemoryRecord,
)
from .self_healing_runtime import FailureSignature, FailureSignatureStore, RepairEpisode, SelfHealingRuntime
from .stability import CodeHealth, CodeHealthStore
from .v8_engine import V8AIEngine
from .v9_engine import V9AIEngine
from .v10_engine import V10AIEngine

AIEngine = V9AIEngine
AIEngine = V10AIEngine

__all__ = [
"AIEngine",
"V10AIEngine",
"V9AIEngine",
"V8AIEngine",
"LegacyAIEngine",
Expand All @@ -57,6 +62,8 @@
"ChatMessage",
"ChatRequest",
"ChatResponse",
"CodeHealth",
"CodeHealthStore",
"CognitiveComputeController",
"CognitiveComputePolicy",
"CognitiveContext",
Expand All @@ -65,11 +72,22 @@
"CodeFile",
"CodeIntelligenceIndex",
"CodeSymbol",
"CausalDiagnosis",
"CausalErrorEngine",
"CausalRepositoryTwin",
"Document",
"ExecutionBudget",
"EvolutionBenchmark",
"EvolutionMemory",
"EvolutionRecord",
"FailureEvent",
"FailureFrame",
"FailureSignature",
"FailureSignatureStore",
"FaultCase",
"FaultInjectionLab",
"FaultResult",
"ImpactSlice",
"InMemoryKnowledgeStore",
"MemoryItem",
"MemoryKind",
Expand All @@ -83,27 +101,23 @@
"ProgramNode",
"ProgramSlice",
"RecursiveAgentGraph",
"RepairEpisode",
"RepairMemory",
"RepairMemoryRecord",
"RetrievedChunk",
"RoutingDecision",
"RoutingRequest",
"RuntimeTraceGraph",
"SQLiteVectorStore",
"StrategyScore",
"SelfHealingRuntime",
"TaskNode",
"TieredModelPool",
"TraceCausalLink",
"TraceEvent",
"RuntimeTraceGraph",
"WorkArtifact",
"CausalRepositoryTwin",
"ImpactSlice",
"TwinEdge",
"TwinNode",
"CausalDiagnosis",
"CausalErrorEngine",
"FailureEvent",
"FailureFrame",
"RepairMemory",
"RepairMemoryRecord",
"WorkArtifact",
"benchmark_cases",
"build_cognitive_context",
"build_model_report",
Expand Down
27 changes: 23 additions & 4 deletions src/myai/capability_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
from .cognitive_state import Belief, CognitiveState, MemoryItem, MemoryKind
from .context_contract import build_cognitive_context
from .evolution import EvolutionBenchmark, EvolutionMemory, EvolutionRecord
from .fault_lab import FaultInjectionLab
from .memory_lifecycle import MemoryLifecycleManager
from .model_router import AdaptiveModelRouter, RoutingRequest
from .repository_twin import CausalRepositoryTwin
from .runtime_trace import RuntimeTraceGraph, TraceEvent
from .self_healing_runtime import FailureSignatureStore, SelfHealingRuntime
from .stability import CodeHealth, CodeHealthStore


@dataclass(frozen=True)
Expand Down Expand Up @@ -92,11 +95,27 @@ def judge(node: TaskNode, artifact: WorkArtifact, children):
trace.link("benchmark-cause", "benchmark-error", "caused")
neighborhood = trace.neighborhood("benchmark-error")
affected = twin.affected_files("src/myai/engine.py")
record(
"causal-trace-diagnosis",
bool(neighborhood) and any(event.kind == "exception" for event in neighborhood) and bool(affected),
f"trace_events={len(neighborhood)};affected_files={len(affected)}",
record("causal-trace-diagnosis", bool(neighborhood) and any(event.kind == "exception" for event in neighborhood) and bool(affected), f"trace_events={len(neighborhood)};affected_files={len(affected)}")

signatures = FailureSignatureStore("/tmp/myai-v10-failure-signatures.jsonl")
healing = SelfHealingRuntime(episode_path="/tmp/myai-v10-repair-episodes.jsonl", signature_store=signatures)
signature = healing.signature("TypeError", "database timeout 123", "AIEngine.generate")
episode = healing.verified_repair(
signature=signature,
reproduce=lambda: (True, "synthetic reproduction"),
validate=lambda: True,
lesson="verified bounded recovery",
)
record("self-healing-runtime", episode.status == "verified" and bool(signatures.similar(signature)), f"status={episode.status};attempts={episode.attempts}")

state_map = {"healthy": True}
fault = FaultInjectionLab()
fault_result = fault.run(fault.simple_toggle(state_map, "healthy"), detector=lambda: not state_map["healthy"])
record("fault-injection-recovery", fault_result.detected and fault_result.recovered and fault_result.verified, f"detected={fault_result.detected};recovered={fault_result.recovered};verified={fault_result.verified}")

health_store = CodeHealthStore("/tmp/myai-v10-code-health.json")
health_store.upsert(CodeHealth("stable_symbol", 0.99, 0.99, 0.0, 0.01, 0.05, "2026-08-25T00:00:00+00:00"))
record("stable-code-inspection", health_store.inspection_mode("stable_symbol") == "reuse", f"mode={health_store.inspection_mode('stable_symbol')}")

state.observe("observation-a")
for index_value in range(20):
Expand Down
20 changes: 13 additions & 7 deletions src/myai/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ class Settings(BaseSettings):
environment: str = "development"
log_level: str = "INFO"
model_provider: str = "local"
model_name: str = "placeholder-v9"
model_name: str = "placeholder-v10"
model_base_url: str = "http://localhost:11434"
model_api_key: str = ""
model_timeout_seconds: float = 60.0
fast_model_provider: str = "local"
fast_model_name: str = "placeholder-v9-fast"
fast_model_name: str = "placeholder-v10-fast"
fast_model_base_url: str = "http://localhost:11434"
fast_model_api_key: str = ""
balanced_model_provider: str = "local"
balanced_model_name: str = "placeholder-v9-balanced"
balanced_model_name: str = "placeholder-v10-balanced"
balanced_model_base_url: str = "http://localhost:11434"
balanced_model_api_key: str = ""
frontier_model_provider: str = "local"
frontier_model_name: str = "placeholder-v9-frontier"
frontier_model_name: str = "placeholder-v10-frontier"
frontier_model_base_url: str = "http://localhost:11434"
frontier_model_api_key: str = ""
memory_max_messages: int = 20
Expand Down Expand Up @@ -49,11 +49,17 @@ class Settings(BaseSettings):
runtime_trace_path: str = "data/runtime_trace.jsonl"
evolution_memory_path: str = "data/evolution_memory.jsonl"
capability_ledger_path: str = "data/capability_ledger.json"
failure_signature_path: str = "data/failure_signatures.jsonl"
repair_episode_path: str = "data/repair_episodes.jsonl"
code_health_path: str = "data/code_health.json"
evolution_min_promotion_delta: float = 0.05
self_healing_enabled: bool = True
self_healing_max_repair_attempts: int = 2
self_healing_reproduction_timeout_seconds: float = 30.0
system_prompt: str = (
"You are MY-AI V9.1. Operate as an evidence-first cognitive mesh. "
"Use the unified program graph, runtime traces, repository memory, and structured specialist artifacts. "
"Never invent sources, tool usage, verification, or repository facts. "
"You are MY-AI V10.0. Operate as an evidence-first cognitive mesh with a bounded self-healing runtime. "
"Use the unified program graph, runtime traces, repository memory, failure signatures, stable-code health, "
"and structured specialist artifacts. Never invent sources, tool usage, verification, or repository facts. "
"Prefer the smallest sufficient context and preserve already-verified work. "
"When strategies disagree, surface uncertainty and request stronger evidence rather than averaging guesses."
)
Expand Down
Loading