Architecture: - director_v2: always-on brain, produces DirectorPlan with tool_sequence - thinker_v2: pure executor, runs tools from DirectorPlan - interpreter_v1: factual result summarizer, no hallucination - v2_director_drives graph: Input -> Director -> Thinker -> Output Infrastructure: - Split into 3 pods: cog-frontend (nginx), cog-runtime (FastAPI), cog-mcp (SSE proxy) - MCP survives runtime restarts (separate pod, proxies via HTTP) - Async send pipeline: /api/send/check -> /api/send -> /api/result with progress - Zero-downtime rolling updates (maxUnavailable: 0) - Dynamic graph visualization (fetched from API, not hardcoded) Tests: 22 new mocked unit tests (director_v2: 7, thinker_v2: 8, interpreter_v1: 7) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
79 lines
2.7 KiB
Python
79 lines
2.7 KiB
Python
"""Message types flowing between nodes."""
|
|
|
|
from dataclasses import dataclass, field, asdict
|
|
|
|
|
|
@dataclass
|
|
class Envelope:
|
|
"""What flows between nodes."""
|
|
text: str
|
|
user_id: str = "anon"
|
|
session_id: str = ""
|
|
timestamp: str = ""
|
|
|
|
|
|
@dataclass
|
|
class InputAnalysis:
|
|
"""Structured classification from Input node."""
|
|
who: str = "unknown"
|
|
language: str = "en"
|
|
intent: str = "request" # question | request | social | action | feedback
|
|
topic: str = ""
|
|
tone: str = "casual" # casual | frustrated | playful | urgent
|
|
complexity: str = "simple" # trivial | simple | complex
|
|
context: str = ""
|
|
|
|
|
|
@dataclass
|
|
class Command:
|
|
"""Input node's structured perception of what was heard."""
|
|
analysis: InputAnalysis
|
|
source_text: str
|
|
metadata: dict = field(default_factory=dict)
|
|
|
|
@property
|
|
def instruction(self) -> str:
|
|
"""Backward-compatible summary string for logging/thinker."""
|
|
a = self.analysis
|
|
return f"{a.who} ({a.intent}, {a.tone}): {a.topic}"
|
|
|
|
|
|
@dataclass
|
|
class DirectorPlan:
|
|
"""Director v2's output — tells Thinker exactly what to execute."""
|
|
goal: str = ""
|
|
steps: list = field(default_factory=list) # ["query_db('SHOW TABLES')", ...]
|
|
present_as: str = "summary" # table | summary | machine
|
|
tool_sequence: list = field(default_factory=list) # [{"tool": "query_db", "args": {...}}, ...]
|
|
reasoning: str = "" # Director's internal reasoning (for audit)
|
|
response_hint: str = "" # How to phrase the response if no tools needed
|
|
|
|
@property
|
|
def has_tools(self) -> bool:
|
|
return bool(self.tool_sequence)
|
|
|
|
@property
|
|
def is_direct_response(self) -> bool:
|
|
return not self.tool_sequence and bool(self.response_hint)
|
|
|
|
|
|
@dataclass
|
|
class InterpretedResult:
|
|
"""Interpreter's factual summary of tool output."""
|
|
summary: str # Factual text summary
|
|
row_count: int = 0 # Number of data rows (for DB)
|
|
key_facts: list = field(default_factory=list) # ["693 customers", "avg 5.2 devices"]
|
|
confidence: str = "high" # high | medium | low
|
|
|
|
|
|
@dataclass
|
|
class ThoughtResult:
|
|
"""Thinker node's output — either a direct answer or tool results."""
|
|
response: str
|
|
tool_used: str = ""
|
|
tool_output: str = ""
|
|
actions: list = field(default_factory=list) # [{label, action, payload?}]
|
|
state_updates: dict = field(default_factory=dict) # {key: value} from set_state
|
|
display_items: list = field(default_factory=list) # [{type, label, value?, style?}] from emit_display
|
|
machine_ops: list = field(default_factory=list) # [{op, id, ...}] from machine tools
|