feat: implement DCOS source tree, tests, and build configuration

Complete implementation of the DCOS package including:
- 40+ Python source files across agents, communication, core, learning, memory, protocols, utils
- pyproject.toml build configuration
- 102 unit tests across all subsystems
- Fixed flake.nix (Python 3.12, proper dependencies, pyproject build)
- Fixed .woodpecker.yml (correct paths, removed silent-fail flags)
- Added .gitignore
- Cleared stale pytest cache
This commit is contained in:
Celes Renata
2026-08-02 03:29:55 -07:00
parent 38bb291a02
commit 57619860d5
157 changed files with 2742 additions and 10 deletions
+15
View File
@@ -0,0 +1,15 @@
"""
Core subsystem — scheduling, coordination, registry, and resource allocation.
"""
from .scheduler import TaskScheduler
from .coordinator import AgentCoordinator
from .registry import AgentRegistry
from .allocator import ResourceAllocator
__all__ = [
"TaskScheduler",
"AgentCoordinator",
"AgentRegistry",
"ResourceAllocator",
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+45
View File
@@ -0,0 +1,45 @@
"""
Resource allocator — manages compute and memory resource distribution among agents.
"""
from __future__ import annotations
from typing import Dict, List, Optional, Tuple
class ResourceAllocator:
"""Allocates system resources (compute, memory, bandwidth) among agents."""
def __init__(self) -> None:
self._total_cpu: float = 100.0
self._total_memory: float = 1024.0
self._allocations: Dict[str, Dict[str, float]] = {}
def allocate(self, agent_id: str, cpu: float, memory: float) -> bool:
if cpu <= 0 or memory <= 0:
return False
remaining_cpu = self._total_cpu - sum(
a.get("cpu", 0) for a in self._allocations.values()
)
remaining_memory = self._total_memory - sum(
a.get("memory", 0) for a in self._allocations.values()
)
if cpu > remaining_cpu or memory > remaining_memory:
return False
self._allocations[agent_id] = {"cpu": cpu, "memory": memory}
return True
def release(self, agent_id: str) -> bool:
return agent_id in self._allocations and bool(
self._allocations.pop(agent_id, None)
)
def get_allocation(self, agent_id: str) -> Dict[str, float]:
return self._allocations.get(agent_id, {"cpu": 0.0, "memory": 0.0})
def utilization(self) -> Dict[str, float]:
total_cpu = sum(a.get("cpu", 0) for a in self._allocations.values())
total_mem = sum(a.get("memory", 0) for a in self._allocations.values())
return {
"cpu": total_cpu / self._total_cpu,
"memory": total_mem / self._total_memory,
}
+38
View File
@@ -0,0 +1,38 @@
"""
Agent coordinator — orchestrates multi-agent workflows and collaboration.
"""
from __future__ import annotations
from typing import Any, Dict, List, Optional
from datetime import datetime
class AgentCoordinator:
"""Coordinates multiple agents to work on complex tasks collaboratively."""
def __init__(self) -> None:
self._workflows: Dict[str, List[str]] = {} # workflow_id -> [agent_ids]
self._active: Dict[str, Dict[str, Any]] = {}
def create_workflow(self, workflow_id: str, agent_ids: List[str]) -> None:
self._workflows[workflow_id] = agent_ids
self._active[workflow_id] = {
"status": "created",
"created_at": datetime.now().isoformat(),
}
def assign_task(self, workflow_id: str, agent_id: str, task: Any) -> bool:
workflow = self._workflows.get(workflow_id)
if workflow and agent_id in workflow:
self._active.setdefault(workflow_id, {})["current_task"] = str(task)
return True
return False
def get_workflow_status(self, workflow_id: str) -> Optional[Dict[str, Any]]:
return self._active.get(workflow_id)
def complete_workflow(self, workflow_id: str) -> bool:
if workflow_id in self._active:
self._active[workflow_id]["status"] = "completed"
return True
return False
+48
View File
@@ -0,0 +1,48 @@
"""
Agent registry — maintains a directory of all active agents and their capabilities.
"""
from __future__ import annotations
from typing import Any, Dict, List, Optional
from dataclasses import dataclass, field
@dataclass
class AgentRecord:
agent_id: str
name: str
role: str
capabilities: List[str] = field(default_factory=list)
status: str = "active"
address: str = ""
class AgentRegistry:
"""Directory of all agents in the system with their metadata."""
def __init__(self) -> None:
self._agents: Dict[str, AgentRecord] = {}
def register(self, record: AgentRecord) -> None:
self._agents[record.agent_id] = record
def unregister(self, agent_id: str) -> Optional[AgentRecord]:
return self._agents.pop(agent_id, None)
def get(self, agent_id: str) -> Optional[AgentRecord]:
return self._agents.get(agent_id)
def find_by_role(self, role: str) -> List[AgentRecord]:
return [a for a in self._agents.values() if a.role == role]
def find_by_capability(self, capability: str) -> List[AgentRecord]:
return [
a for a in self._agents.values()
if capability in a.capabilities
]
def list_active(self) -> List[AgentRecord]:
return [a for a in self._agents.values() if a.status == "active"]
def count(self) -> int:
return len(self._agents)
+81
View File
@@ -0,0 +1,81 @@
"""
Task scheduler — manages task queuing, prioritization, and execution ordering.
"""
from __future__ import annotations
from typing import Any, Dict, List, Optional
from dataclasses import dataclass, field
from datetime import datetime
from enum import Enum
from uuid import uuid4
class TaskStatus(Enum):
PENDING = "pending"
RUNNING = "running"
COMPLETED = "completed"
FAILED = "failed"
@dataclass
class Task:
id: str = field(default_factory=lambda: uuid4().hex)
name: str = ""
agent_id: str = ""
status: TaskStatus = TaskStatus.PENDING
priority: int = 0
created_at: datetime = field(default_factory=datetime.now)
depends_on: List[str] = field(default_factory=list)
class TaskScheduler:
"""Schedules and dispatches tasks to agents."""
def __init__(self) -> None:
self._queue: List[Task] = []
self._running: List[Task] = []
self._completed: List[Task] = []
def enqueue(self, task: Task) -> None:
self._queue.append(task)
self._queue.sort(key=lambda t: t.priority, reverse=True)
def dequeue(self) -> Optional[Task]:
if not self._queue:
return None
# Find first task whose dependencies are met
for task in self._queue:
deps_met = all(
dep in [c.id for c in self._completed]
for dep in task.depends_on
)
if deps_met:
self._queue.remove(task)
task.status = TaskStatus.RUNNING
self._running.append(task)
return task
return None
def complete(self, task_id: str) -> bool:
for task in self._running:
if task.id == task_id:
self._running.remove(task)
task.status = TaskStatus.COMPLETED
self._completed.append(task)
return True
return False
def fail(self, task_id: str) -> bool:
for task in self._running:
if task.id == task_id:
self._running.remove(task)
task.status = TaskStatus.FAILED
self._completed.append(task)
return True
return False
def pending_count(self) -> int:
return len(self._queue)
def running_count(self) -> int:
return len(self._running)