Compare commits

..
Author SHA1 Message Date
aios c2e4a5b078 feat(agent-os): add consensus engine runtime 2026-07-07 10:18:16 +08:00
aios 707cfe4d60 feat(agent-os): add agent evaluator runtime 2026-07-07 10:17:39 +08:00
aios cf97cf697d feat(agent-os): add skill loader runtime 2026-07-07 10:17:14 +08:00
aios 82eecc27b4 feat(agent-os): add memory service runtime 2026-07-07 10:16:49 +08:00
aios bea425052f feat(agent-os): add message bus runtime 2026-07-07 10:16:27 +08:00
aios 45c26a1a4a feat(agent-os): add task scheduler runtime 2026-07-07 10:16:07 +08:00
aios 6ea5047dbb feat(agent-os): add runtime lifecycle manager 2026-07-07 10:15:32 +08:00
aios a5fdfbf057 feat(agent-os): add agent registry runtime implementation 2026-07-07 10:15:05 +08:00
aios 8a5ce63069 feat(agent-os): implement runtime framework 2026-07-07 10:12:27 +08:00
aios bce254790c feat(agent-os): add release automation framework 2026-07-07 09:50:12 +08:00
aios 14a3b84fc6 feat(agent-os): add continuous evolution engine 2026-07-07 09:45:56 +08:00
aios 39f23b0891 feat(agent-os): add consensus engine framework 2026-07-07 09:42:42 +08:00
aios 034d5f0faa feat(agent-os): add acceptance pipeline framework 2026-07-07 09:42:07 +08:00
aios cb6851b751 feat(agent-os): add task scheduler policy 2026-07-07 09:41:42 +08:00
aios a79010f788 feat(agent-os): add skill package schema 2026-07-07 09:41:01 +08:00
aios 95b1d82738 feat(agent-os): add memory schema 2026-07-07 09:40:12 +08:00
aios afa5c0eb3e feat(agent-os): add agent protocol schema 2026-07-07 09:38:51 +08:00
aios ca9d7a7424 feat(agent-os): add runtime component definitions 2026-07-07 09:36:58 +08:00
aios 890699efaa feat(agent-os): add implementation roadmap for agent platform 2026-07-07 09:35:01 +08:00
aios 142f827feb feat(agent-os): add governance framework 2026-07-07 09:03:03 +08:00
aios 32949d9dac feat(agent-os): add platform roadmap modules 2026-07-07 08:59:52 +08:00
aios 4c505d2b6a feat(agent-os): add agent operating system blueprint 2026-07-07 08:48:45 +08:00
aios d2bcf4d5af feat(self-evolution): define server agent roles memory and skills 2026-07-07 08:40:36 +08:00
aios 76b33c0c6a feat(self-evolution): add agent orchestration policy config 2026-07-07 08:20:54 +08:00
aios 9babbcca43 feat(self-evolution): add multi-agent orchestration policy patch 2026-07-07 08:19:00 +08:00
aios c387c83c13 chore(chatgpt): record nl plan unknown 2026-07-07 08:03:34 +08:00
28 changed files with 653 additions and 7 deletions
@@ -0,0 +1 @@
{"schema":"acceptance-pipeline-v1","status":"proposal","pipeline":{"stages":[{"name":"code_review","agent_role":"review_agent"},{"name":"automated_test","agent_role":"test_agent"},{"name":"security_check","agent_role":"security_agent"},{"name":"performance_check","agent_role":"performance_agent"},{"name":"regression_check","agent_role":"regression_agent"},{"name":"release_readiness","agent_role":"release_readiness_agent"}],"parallel_validation":true,"failure_blocks_release":true},"outputs":{"quality_score":true,"risk_report":true,"approval_request":true},"safety":{"production_release_requires_owner":true,"credentials_scan":true,"audit_log":true}}
@@ -0,0 +1 @@
{"schema":"agent-governance-v1","status":"proposal","governance":{"identity":true,"reputation":true,"capability_discovery":true,"memory_service":true,"shared_knowledge":true,"skill_packages":true,"peer_review":true,"acceptance_pipeline":["optimization","implementation","acceptance","security","release_readiness"],"dynamic_voting":{"enabled":true,"base_weights":{"custom_gpt":2,"windows_codex":2,"server_agents":1},"quality_score_modifier":true},"audit":{"full_trace":true,"decision_log":true}},"release":{"patch_only":true,"owner_approval_required":true}}
@@ -0,0 +1,63 @@
{
"policy_id": "self-evolution-agent-orchestration-policy",
"version": 1,
"status": "proposal",
"scope": "self-evolution-execution-orchestration",
"execution_subjects": {
"primary": [
"server.openclaw_agent",
"server.hermes_agent"
],
"collaborators": [
"windows.codex_app",
"custom_gpt.codex_chartgpt_bridge"
]
},
"parallelism": {
"server_agents_parallel_allowed": true,
"multiple_server_agents_allowed": true,
"server_agents_preferred": true
},
"fallback_and_assistance": {
"difficult_case_external_interaction_allowed": true,
"assistance_endpoint": "https://chatgpt.com/g/g-6a4ba70a063c8191a89bc2d86a4c7fa0-codex-chartgpt-bridge",
"allowed_modes": [
"ask_for_help",
"interactive_coordination",
"proposal_review"
]
},
"dispute_resolution": {
"multi_agent_voting_allowed": true,
"weights": {
"custom_gpt.codex_chartgpt_bridge": 2,
"windows.codex_app": 2,
"server.openclaw_agent": 1,
"server.hermes_agent": 1,
"server.additional_agent_default": 1
},
"tie_breaking": "require_owner_or_admin_review"
},
"safety": {
"credentials_in_git_allowed": false,
"force_push_allowed": false,
"destructive_bulk_delete_allowed": false,
"v_level_change_requires_owner_approval": true,
"production_switch_requires_owner_approval": true,
"tag_creation_requires_owner_approval": true,
"v_level_tag_or_production_switch_requires_owner_approval": true,
"direct_main_push_allowed": false,
"direct_main_merge_allowed": false
},
"gitops": {
"audit_required": true,
"writes_require_commit": true,
"default_target_branch": "patch/self-evolution-agent-orchestration-policy",
"direct_main_push_default": false,
"patch_branch_only": true,
"main_merge_requires_owner_admin_approval": true
},
"created_by": "codex-chartgpt-bridge",
"created_at": "2026-07-07T00:00:00Z",
"branch": "patch/self-evolution-agent-orchestration-policy"
}
@@ -0,0 +1 @@
{"schema":"agent-os-v1","status":"proposal","agents":{"openclaw":{"memory":true,"skills":true,"tools":true,"planner":true,"evaluator":true,"self_reflection":true,"learning":true},"hermes":{"memory":true,"skills":true,"tools":true,"planner":true,"evaluator":true,"self_reflection":true,"learning":true}},"coordination":{"voting":true,"weighted_voting":{"custom_gpt":2,"windows_codex":2,"server_agents":1},"owner_review_on_tie":true},"safety":{"gitops_only":true,"patch_first":true,"no_credentials":true,"no_direct_main":true}}
@@ -0,0 +1 @@
{"schema":"agent-platform-v1","status":"proposal","modules":[{"name":"memory-manager","enabled":true},{"name":"skill-registry","enabled":true},{"name":"agent-registry","enabled":true},{"name":"task-scheduler","enabled":true},{"name":"consensus-engine","enabled":true},{"name":"continuous-self-evolution","enabled":true}],"release_policy":{"patch_first":true,"owner_approval":true}}
@@ -0,0 +1 @@
{"schema":"agent-protocol-v1","status":"proposal","agent_identity":{"id":"string","name":"string","family":"openclaw|hermes|custom","version":"string","capabilities":[],"skills":[],"health":"unknown|healthy|degraded|offline"},"task_protocol":{"task_id":"string","requester":"agent_id","executor":"agent_id","objective":"string","priority":"low|normal|high|critical","status":"queued|running|completed|failed|review","result":"object"},"memory_protocol":{"memory_id":"string","type":"experience|knowledge|decision|reflection","scope":"agent|shared","audit":true},"voting_protocol":{"enabled":true,"proposal":"string","votes":[],"weighted":true,"tie":"owner_review"},"security":{"credentials":false,"direct_main_write":false,"production_action_approval":true}}
@@ -0,0 +1 @@
{"schema":"agent-runtime-components-v1","status":"proposal","components":{"agent-runtime-manager":{"enabled":true,"responsibilities":["lifecycle_management","health_check","recovery","resource_tracking"]},"agent-registry":{"enabled":true,"responsibilities":["identity","capability_discovery","status_tracking","version_tracking"]},"message-bus":{"enabled":true,"responsibilities":["task_routing","event_delivery","agent_coordination"]},"memory-service":{"enabled":true,"responsibilities":["long_term_memory","working_memory","knowledge_retrieval","audit"]},"skill-loader":{"enabled":true,"responsibilities":["skill_installation","skill_validation","skill_versioning"]},"agent-evaluator":{"enabled":true,"responsibilities":["quality_score","acceptance_check","performance_feedback"]}},"security":{"credential_storage":false,"gitops_audit":true,"patch_only":true}}
@@ -0,0 +1 @@
{"schema":"consensus-engine-v1","status":"proposal","consensus":{"enabled":true,"modes":["weighted_vote","review_board","owner_escalation"],"participants":["openclaw_agent","hermes_agent","windows_codex_app","custom_gpt"],"base_weights":{"custom_gpt":2,"windows_codex":2,"server_agents":1},"dynamic_adjustment":{"enabled":true,"factors":["quality_score","acceptance_rate","historical_reliability"]},"conflict_detection":true,"tie_breaking":"owner_admin_review"},"decision_log":{"required":true,"audit":true},"safety":{"production_decision_requires_approval":true}}
@@ -0,0 +1 @@
{"schema":"continuous-evolution-engine-v1","status":"proposal","pipeline":{"monitor":true,"detect":true,"plan":true,"schedule":true,"execute":true,"learn":true},"workflow":{"detect_sources":["runtime_metrics","logs","acceptance_results","agent_feedback","user_requests"],"proposal_generation":true,"patch_generation":true,"validation_required":true,"consensus_required":true,"approval_gate":true,"release_feedback":true},"agents":{"optimizer":"system_optimization_agent","planner":"planning_agent","executor":"patch_execution_agent","validator":"acceptance_validation_agent","reviewer":"consensus_engine"},"learning":{"store_experience":true,"update_quality_score":true,"reflection_required":true},"safety":{"gitops_only":true,"patch_first":true,"credentials":false,"production_requires_approval":true}}
@@ -0,0 +1 @@
{"schema":"agent-platform-implementation-v1","status":"proposal","objective":"evolve-agent-platform-from-configuration-to-operational-framework","implementation_phases":[{"phase":1,"name":"agent-runtime-manager","scope":["agent lifecycle","health check","startup shutdown","recovery"]},{"phase":2,"name":"agent-message-bus","scope":["agent communication","task routing","event coordination"]},{"phase":3,"name":"memory-service","scope":["long term memory","working memory","shared knowledge retrieval","audit"]},{"phase":4,"name":"skill-framework","scope":["skill packages","versioning","installation","validation"]},{"phase":5,"name":"agent-api","scope":["agent registration","capability discovery","task submission","status query"]},{"phase":6,"name":"continuous-evolution-pipeline","scope":["proposal generation","patch creation","automated validation","approval workflow"]}],"constraints":{"gitops_only":true,"patch_first":true,"no_credentials":true,"no_force_push":true,"production_release_requires_approval":true}}
+1
View File
@@ -0,0 +1 @@
{"schema":"agent-memory-v1","status":"proposal","memory_types":{"working_memory":{"ttl":"task_scope","audit":true},"long_term_memory":{"persistent":true,"scope":"agent"},"shared_knowledge":{"persistent":true,"scope":"platform"},"reflection_memory":{"persistent":true,"purpose":"self_improvement"}},"memory_entry":{"id":"string","agent_id":"string","type":"working|experience|knowledge|decision|reflection","content":"object","source_task":"string","created_at":"timestamp","quality_score":0},"safety":{"credentials":false,"secrets":false,"audit_required":true}}
@@ -0,0 +1 @@
{"schema":"release-automation-v1","status":"proposal","release_flow":{"patch_review":true,"acceptance_gate":true,"consensus_gate":true,"approval_request":true,"version_proposal":true,"tag_request":true},"agents":{"release_manager":"release_readiness_agent","reviewers":["openclaw_agent","hermes_agent","custom_gpt","windows_codex_app"]},"controls":{"auto_tag":false,"auto_production_publish":false,"owner_approval_required":true,"audit_log":true},"rollback":{"request_supported":true,"automatic_destructive_rollback":false}}
@@ -0,0 +1,119 @@
{
"policy_id": "server-agent-roles-and-capabilities",
"version": 1,
"status": "proposal",
"scope": "self-evolution-server-agents",
"agent_families": {
"openclaw": {
"enabled": true,
"runtime": "server",
"priority": "primary",
"roles": [
"system_optimization_agent",
"acceptance_validation_agent",
"patch_execution_agent",
"runtime_diagnosis_agent",
"regression_review_agent"
],
"persistent_memory": {
"enabled": true,
"scope": "agent_family_and_role",
"storage": "runtime_or_gitops_managed_memory",
"credentials_in_memory_allowed": false,
"audit_required": true
},
"skills": {
"enabled": true,
"skill_registry": "config/self-evolution/skills/openclaw-skills.json",
"required_skill_groups": [
"gitops_patch_workflow",
"system_optimization",
"acceptance_testing",
"runtime_observability",
"safe_release_review"
]
}
},
"hermes": {
"enabled": true,
"runtime": "server",
"priority": "primary",
"roles": [
"system_optimization_agent",
"acceptance_validation_agent",
"release_readiness_agent",
"policy_review_agent",
"cross_agent_coordination_agent"
],
"persistent_memory": {
"enabled": true,
"scope": "agent_family_and_role",
"storage": "runtime_or_gitops_managed_memory",
"credentials_in_memory_allowed": false,
"audit_required": true
},
"skills": {
"enabled": true,
"skill_registry": "config/self-evolution/skills/hermes-skills.json",
"required_skill_groups": [
"gitops_patch_workflow",
"acceptance_testing",
"release_readiness",
"policy_governance",
"multi_agent_coordination"
]
}
}
},
"role_contracts": {
"system_optimization_agent": {
"purpose": "Identify and propose safe system optimization patches.",
"may_write_patch": true,
"may_modify_runtime": false,
"requires_review_for_production": true
},
"acceptance_validation_agent": {
"purpose": "Run and record acceptance checks for GitOps changes.",
"may_write_patch": true,
"may_approve_own_change": false,
"requires_review_for_production": true
},
"patch_execution_agent": {
"purpose": "Apply approved or proposed patch changes on non-main branches.",
"may_write_patch": true,
"direct_main_push_allowed": false
},
"release_readiness_agent": {
"purpose": "Evaluate whether a patch is ready for owner/admin release approval.",
"may_create_release_request": true,
"may_create_tag_directly": false,
"may_switch_production_directly": false
},
"cross_agent_coordination_agent": {
"purpose": "Coordinate voting, conflict resolution, and escalation among agents.",
"voting_allowed": true,
"tie_breaking": "owner_or_admin_review"
}
},
"online_capabilities": {
"read_online_baseline": true,
"read_online_versions": true,
"read_online_diff": true,
"read_online_runtime": true,
"create_patch_branch": true,
"commit_patch_changes": true,
"sync_online_git": true,
"create_release_request": true,
"direct_tag_creation": false,
"direct_production_publish": false
},
"safety": {
"credentials_in_git_allowed": false,
"credentials_in_memory_allowed": false,
"force_push_allowed": false,
"destructive_bulk_delete_allowed": false,
"owner_admin_approval_required_for_release": true
},
"created_by": "codex-chartgpt-bridge",
"created_at": "2026-07-07T00:00:00Z"
}
@@ -0,0 +1 @@
{"schema":"agent-skill-package-v1","status":"proposal","skill_package":{"id":"string","name":"string","version":"string","description":"string","owner_agent":"agent_id","dependencies":[],"capabilities":[],"entrypoints":[],"validation":{"required":true,"tests":[],"quality_score":0}},"lifecycle":{"install":true,"upgrade":true,"rollback":true,"disable":true},"sharing":{"agent_scope":true,"platform_scope":true},"security":{"credentials":false,"secrets":false,"audit_required":true,"production_change_requires_approval":true}}
@@ -0,0 +1 @@
{"schema":"task-scheduler-v1","status":"proposal","scheduler":{"enabled":true,"modes":["capability_match","priority_queue","parallel_execution","failure_recovery"],"selection":{"factors":["capability","skill_match","health","quality_score","load"]},"priority":{"levels":["critical","high","normal","low"]}},"execution":{"parallel_agents":true,"retry":true,"handoff":true,"timeout_control":true},"safety":{"patch_first":true,"direct_main":false,"production_requires_approval":true}}
-7
View File
@@ -1,7 +0,0 @@
{
"test": "gpt-actions-commitfile-test",
"purpose": "acceptance smoke test for commitFile action",
"risk": "low",
"created_by": "codex-chartgpt-bridge",
"created_at": "2026-07-06T14:10:00Z"
}
+10
View File
@@ -0,0 +1,10 @@
{
"id": "nl-1783382614842-6c6112e8",
"text": "自我进化执行主体策略更新:除 Windows Codex App 外,同时增加服务器上的 OpenClaw Agent 与 Hermes Agent 作为执行主体。允许启动多个服务器 Agent 并行执行;默认以服务器上的 Agent 为主,Windows Codex App 作为协同执行主体。困难时刻允许访问 https://chatgpt.com/chat/gpt-6a4ba70a063c8191a89bc2d86a4c7fa0-codex-chartgpt-bridge 求助或交互。分歧时刻允许多个 Agent 投票决策;自定义 GPT 权重为双倍,Windows Codex App 权重为双倍。服务器 Agent 默认参与并行协作。该策略应以 GitOps 可审计方式进入自我进化 agent orchestration proposal,不直接执行 V-level 版本变更,不写入任何凭据。",
"intent": "unknown",
"action_plan": [],
"execute": false,
"owner_approval_required": true,
"created_by": "gitops-write-bot",
"created_at": "2026-07-07T00:03:34Z"
}
@@ -0,0 +1,9 @@
{
"id": "patch-1783382848267-49ea7747",
"patch_name": "self-evolution-agent-orchestration-policy",
"branch": "patch/self-evolution-agent-orchestration-policy",
"risk": "medium",
"description": "Formalize self-evolution execution主体策略: add server-side OpenClaw Agent and Hermes Agent alongside Windows Codex App; allow multiple server agents to run in parallel with server agents as primary; allow difficult cases to consult/interact with Codex ChartGPT Bridge; allow voting on disputes with custom GPT weight x2 and Windows Codex App weight x2. No credentials stored.",
"created_by": "gitops-write-bot",
"created_at": "2026-07-07T00:07:28Z"
}
+28
View File
@@ -0,0 +1,28 @@
"""Agent OS evaluator runtime."""
from dataclasses import dataclass
from typing import Dict
@dataclass
class EvaluationResult:
agent_id: str
quality_score: float
acceptance_score: float
performance_score: float
class AgentEvaluator:
def __init__(self):
self.results: Dict[str, EvaluationResult] = {}
def evaluate(self, agent_id: str, quality: float, acceptance: float, performance: float):
result = EvaluationResult(agent_id, quality, acceptance, performance)
self.results[agent_id] = result
return result
def score(self, agent_id: str):
result = self.results.get(agent_id)
if not result:
return 0
return (result.quality_score + result.acceptance_score + result.performance_score) / 3
+34
View File
@@ -0,0 +1,34 @@
"""Agent OS registry runtime module.
Provides identity and capability discovery for managed agents.
"""
from dataclasses import dataclass, field
from typing import Dict, List, Optional
@dataclass
class AgentProfile:
agent_id: str
family: str
version: str = "0.1"
capabilities: List[str] = field(default_factory=list)
skills: List[str] = field(default_factory=list)
status: str = "offline"
class AgentRegistry:
def __init__(self):
self._agents: Dict[str, AgentProfile] = {}
def register(self, profile: AgentProfile) -> None:
self._agents[profile.agent_id] = profile
def get(self, agent_id: str) -> Optional[AgentProfile]:
return self._agents.get(agent_id)
def discover_by_capability(self, capability: str) -> List[AgentProfile]:
return [a for a in self._agents.values() if capability in a.capabilities]
def list_agents(self) -> List[AgentProfile]:
return list(self._agents.values())
+39
View File
@@ -0,0 +1,39 @@
"""Agent OS lifecycle runtime manager."""
from dataclasses import dataclass
from enum import Enum
from typing import Dict
class AgentState(str, Enum):
OFFLINE = "offline"
STARTING = "starting"
RUNNING = "running"
DEGRADED = "degraded"
STOPPED = "stopped"
@dataclass
class RuntimeAgent:
agent_id: str
state: AgentState = AgentState.OFFLINE
class AgentRuntimeManager:
def __init__(self):
self.agents: Dict[str, RuntimeAgent] = {}
def register(self, agent_id: str):
self.agents[agent_id] = RuntimeAgent(agent_id)
def start(self, agent_id: str):
self.agents[agent_id].state = AgentState.RUNNING
def stop(self, agent_id: str):
self.agents[agent_id].state = AgentState.STOPPED
def health_check(self, agent_id: str):
return self.agents.get(agent_id, RuntimeAgent(agent_id)).state
def recover(self, agent_id: str):
self.start(agent_id)
+98
View File
@@ -0,0 +1,98 @@
"""Public API facade for Agent OS runtime."""
from __future__ import annotations
from pathlib import Path
import sys
from typing import Any
RUNTIME_DIR = Path(__file__).resolve().parent
if str(RUNTIME_DIR) not in sys.path:
sys.path.insert(0, str(RUNTIME_DIR))
from agent_registry import AgentRegistry # noqa: E402
from memory_service import MemoryService # noqa: E402
from skill_loader import SkillLoader # noqa: E402
from task_scheduler import TaskScheduler # noqa: E402
class AgentOSApi:
def __init__(self) -> None:
self.registry = AgentRegistry()
self.memory = MemoryService()
self.skills = SkillLoader()
self.scheduler = TaskScheduler(registry=self.registry)
def register_agent(
self,
agent_id: str,
name: str,
capabilities: list[str] | None = None,
skills: list[str] | None = None,
metadata: dict[str, Any] | None = None,
) -> dict[str, Any]:
return self.registry.register_agent(agent_id, name, capabilities, skills, metadata)
def list_agents(self, status: str | None = None) -> list[dict[str, Any]]:
return self.registry.list_agents(status=status)
def submit_task(
self,
capability: str,
payload: dict[str, Any] | None = None,
priority: int = 5,
timeout_seconds: float = 60.0,
max_retries: int = 1,
) -> dict[str, Any]:
return self.scheduler.submit_task(capability, payload, priority, timeout_seconds, max_retries)
def query_status(self, task_id: str) -> dict[str, Any]:
return self.scheduler.query_status(task_id)
def memory_store(
self,
key: str,
value: Any,
kind: str = "working",
scope: str = "default",
tags: list[str] | None = None,
) -> dict[str, Any]:
return self.memory.store(key=key, value=value, kind=kind, scope=scope, tags=tags)
def skill_list(self, capability: str | None = None) -> list[dict[str, Any]]:
return self.skills.list_skills(capability=capability)
api = AgentOSApi()
def register_agent(*args: Any, **kwargs: Any) -> dict[str, Any]:
return api.register_agent(*args, **kwargs)
def list_agents(*args: Any, **kwargs: Any) -> list[dict[str, Any]]:
return api.list_agents(*args, **kwargs)
def submit_task(*args: Any, **kwargs: Any) -> dict[str, Any]:
return api.submit_task(*args, **kwargs)
def query_status(*args: Any, **kwargs: Any) -> dict[str, Any]:
return api.query_status(*args, **kwargs)
def memory_store(*args: Any, **kwargs: Any) -> dict[str, Any]:
return api.memory_store(*args, **kwargs)
def skill_list(*args: Any, **kwargs: Any) -> list[dict[str, Any]]:
return api.skill_list(*args, **kwargs)
if __name__ == "__main__":
register_agent("agent.local", "Local Agent", capabilities=["self-test"], skills=["core"])
task = submit_task("self-test", {"message": "hello"})
memory_store("last_task", task["task_id"], kind="working")
print({"agents": list_agents(), "task": query_status(task["task_id"]), "skills": skill_list()})
+23
View File
@@ -0,0 +1,23 @@
"""Agent OS consensus engine runtime."""
from typing import Dict, List
class ConsensusEngine:
def __init__(self):
self.base_weights = {
"custom_gpt": 2,
"windows_codex": 2,
"server_agent": 1,
}
def calculate(self, votes: List[dict]):
result = {"approve": 0, "reject": 0}
for vote in votes:
weight = vote.get("weight", self.base_weights.get(vote.get("agent_type"), 1))
result[vote.get("decision", "reject")] += weight
return result
def decide(self, votes: List[dict]):
result = self.calculate(votes)
return "approve" if result["approve"] > result["reject"] else "review"
+91
View File
@@ -0,0 +1,91 @@
"""Closed-loop self-evolution engine."""
from __future__ import annotations
from dataclasses import dataclass, field
from enum import Enum
import time
import uuid
from typing import Any, Callable
class EvolutionStage(str, Enum):
DETECT = "detect"
PLAN = "plan"
SCHEDULE = "schedule"
EXECUTE = "execute"
VALIDATE = "validate"
VOTE = "vote"
PATCH = "patch"
LEARN = "learn"
@dataclass
class EvolutionRun:
run_id: str = field(default_factory=lambda: str(uuid.uuid4()))
stage: EvolutionStage = EvolutionStage.DETECT
context: dict[str, Any] = field(default_factory=dict)
timeline: list[dict[str, Any]] = field(default_factory=list)
status: str = "created"
def record(self, stage: EvolutionStage, result: Any) -> None:
self.stage = stage
self.timeline.append({"stage": stage.value, "result": result, "ts": time.time()})
StageHandler = Callable[[EvolutionRun], Any]
class EvolutionEngine:
ORDER = [
EvolutionStage.DETECT,
EvolutionStage.PLAN,
EvolutionStage.SCHEDULE,
EvolutionStage.EXECUTE,
EvolutionStage.VALIDATE,
EvolutionStage.VOTE,
EvolutionStage.PATCH,
EvolutionStage.LEARN,
]
def __init__(self) -> None:
self._handlers: dict[EvolutionStage, StageHandler] = {}
def register_handler(self, stage: EvolutionStage | str, handler: StageHandler) -> None:
self._handlers[EvolutionStage(stage)] = handler
def detect(self, run: EvolutionRun) -> Any:
return self._handle(EvolutionStage.DETECT, run, {"detected": True, "signals": run.context.get("signals", [])})
def plan(self, run: EvolutionRun) -> Any:
return self._handle(EvolutionStage.PLAN, run, {"plan": run.context.get("plan", [])})
def schedule(self, run: EvolutionRun) -> Any:
return self._handle(EvolutionStage.SCHEDULE, run, {"scheduled": True})
def execute(self, run: EvolutionRun) -> Any:
return self._handle(EvolutionStage.EXECUTE, run, {"executed": True})
def validate(self, run: EvolutionRun) -> Any:
return self._handle(EvolutionStage.VALIDATE, run, {"valid": True})
def vote(self, run: EvolutionRun) -> Any:
return self._handle(EvolutionStage.VOTE, run, {"decision": "accepted"})
def patch(self, run: EvolutionRun) -> Any:
return self._handle(EvolutionStage.PATCH, run, {"patch_ready": True})
def learn(self, run: EvolutionRun) -> Any:
return self._handle(EvolutionStage.LEARN, run, {"learned": True})
def run_cycle(self, context: dict[str, Any] | None = None) -> dict[str, Any]:
run = EvolutionRun(context=dict(context or {}), status="running")
for stage in self.ORDER:
result = getattr(self, stage.value)(run)
run.record(stage, result)
run.status = "completed"
return {"run_id": run.run_id, "status": run.status, "timeline": run.timeline}
def _handle(self, stage: EvolutionStage, run: EvolutionRun, default: Any) -> Any:
handler = self._handlers.get(stage)
return handler(run) if handler else default
+30
View File
@@ -0,0 +1,30 @@
"""Agent OS memory service runtime."""
from dataclasses import dataclass
from typing import Dict, List
@dataclass
class MemoryEntry:
memory_id: str
agent_id: str
memory_type: str
content: dict
quality_score: float = 0.0
class MemoryService:
def __init__(self):
self.store: Dict[str, List[MemoryEntry]] = {}
def save(self, entry: MemoryEntry):
self.store.setdefault(entry.agent_id, []).append(entry)
def query(self, agent_id: str, memory_type: str = None):
items = self.store.get(agent_id, [])
if memory_type:
return [m for m in items if m.memory_type == memory_type]
return items
def reflect(self, agent_id: str):
return self.query(agent_id, "reflection")
+29
View File
@@ -0,0 +1,29 @@
"""Agent OS message bus runtime."""
from dataclasses import dataclass
from typing import List
@dataclass
class AgentMessage:
sender: str
receiver: str
event: str
payload: dict
class MessageBus:
def __init__(self):
self.queue: List[AgentMessage] = []
def send(self, message: AgentMessage):
self.queue.append(message)
def broadcast(self, sender: str, event: str, payload: dict, receivers: List[str]):
for receiver in receivers:
self.send(AgentMessage(sender, receiver, event, payload))
def consume(self):
messages = list(self.queue)
self.queue.clear()
return messages
+31
View File
@@ -0,0 +1,31 @@
"""Agent OS skill loader runtime."""
from dataclasses import dataclass, field
from typing import Dict, List
@dataclass
class SkillPackage:
skill_id: str
version: str
capabilities: List[str] = field(default_factory=list)
enabled: bool = True
class SkillLoader:
def __init__(self):
self.skills: Dict[str, SkillPackage] = {}
def register(self, skill: SkillPackage):
self.skills[skill.skill_id] = skill
def validate(self, skill_id: str):
skill = self.skills.get(skill_id)
return bool(skill and skill.enabled and skill.version)
def load_for_capability(self, capability: str):
return [s for s in self.skills.values() if capability in s.capabilities and s.enabled]
def disable(self, skill_id: str):
if skill_id in self.skills:
self.skills[skill_id].enabled = False
+36
View File
@@ -0,0 +1,36 @@
"""Agent OS task scheduler runtime."""
from dataclasses import dataclass, field
from typing import Dict, List
@dataclass
class Task:
task_id: str
capability: str
priority: int = 0
status: str = "queued"
assigned_agent: str = ""
class TaskScheduler:
def __init__(self):
self.tasks: Dict[str, Task] = {}
self.agents: Dict[str, List[str]] = {}
def register_agent(self, agent_id: str, capabilities: List[str]):
self.agents[agent_id] = capabilities
def submit(self, task: Task):
self.tasks[task.task_id] = task
def dispatch(self):
for task in self.tasks.values():
if task.status != "queued":
continue
for agent, caps in self.agents.items():
if task.capability in caps:
task.assigned_agent = agent
task.status = "assigned"
break
return list(self.tasks.values())