Integrate LEITL Protocol and Cece Cognition Framework into agent system

This commit integrates the LEITL (Live Everyone In The Loop) Protocol and
Cece Cognition Framework into the BlackRoad agent ecosystem, enabling
multi-agent collaboration and advanced reasoning capabilities.

**Changes:**

1. **Cognition Router Integration** (`backend/app/routers/cognition.py`):
   - Fixed import path for orchestration service
   - Exposes full Cece Cognition Framework via REST API
   - Endpoints for single agent execution and multi-agent workflows
   - Supports sequential, parallel, and recursive execution modes

2. **Main App Updates** (`backend/app/main.py`):
   - Added cognition router to imports
   - Registered `/api/cognition` endpoints
   - Added Cognition tag to OpenAPI docs

3. **BaseAgent LEITL Integration** (`agents/base/agent.py`):
   - Added optional LEITL protocol support to base agent class
   - New methods: `enable_leitl()`, `disable_leitl()`, `_leitl_broadcast()`, `_leitl_heartbeat()`
   - Automatic event broadcasting during agent execution lifecycle
   - Events: task.started, task.completed, task.failed
   - Heartbeat support for session keep-alive

4. **AgentRegistry LEITL Support** (`agents/base/registry.py`):
   - Added `enable_leitl_for_all()` - Enable LEITL for all registered agents
   - Added `disable_leitl_for_all()` - Disable LEITL for all agents
   - Added `get_leitl_status()` - Get LEITL status and session IDs
   - Bulk agent session management

**Integration Architecture:**

```
User Request → Cognition API (/api/cognition)
                    ↓
          Orchestration Engine
                    ↓
       ┌────────────┴──────────┐
       ↓                       ↓
  Cece Agent              Other Agents
  (15-step reasoning)     (specialized)
       ↓                       ↓
  LEITL Protocol (if enabled)
       ↓
  Redis PubSub + WebSocket
       ↓
  Other active sessions
```

**New Capabilities:**

1. **Single Agent Execution**: POST /api/cognition/execute
   - Execute Cece, Wasp, Clause, or Codex individually
   - Full reasoning trace and confidence scores

2. **Multi-Agent Workflows**: POST /api/cognition/workflows
   - Orchestrate multiple agents in complex workflows
   - Sequential, parallel, or recursive execution
   - Shared memory and context across agents

3. **LEITL Collaboration**:
   - All agents can now broadcast their activity in real-time
   - Multi-agent sessions can see each other's work
   - Live activity feed via WebSocket
   - Session management with heartbeats

4. **Agent Registry**:
   - Bulk enable/disable LEITL for all agents
   - Query LEITL status across the agent ecosystem
   - Centralized session management

**Testing:**

-  All Python files compile successfully
-  Orchestration engine imports correctly
-  BaseAgent with LEITL integration works
-  AgentRegistry with LEITL support works
-  Cece agent imports and executes
This commit is contained in:
Claude
2025-11-18 13:18:06 +00:00
parent cfba6d184d
commit 1109603b3f
4 changed files with 225 additions and 3 deletions

View File

@@ -321,3 +321,80 @@ class AgentRegistry:
'categories': self.list_categories(),
'stats': self.get_stats()
}
async def enable_leitl_for_all(
self,
leitl_protocol=None,
tags: Optional[List[str]] = None
) -> Dict[str, str]:
"""
Enable LEITL protocol for all registered agents
This allows all agents to participate in the Live Everyone In The Loop
multi-agent collaboration protocol.
Args:
leitl_protocol: LEITL protocol instance (optional, will be imported if not provided)
tags: Optional tags for sessions
Returns:
Dict mapping agent names to LEITL session IDs
"""
self.logger.info("🔗 Enabling LEITL for all agents...")
sessions = {}
for agent_name, agent in self._agents.items():
try:
session_id = await agent.enable_leitl(
leitl_protocol=leitl_protocol,
tags=tags
)
if session_id:
sessions[agent_name] = session_id
self.logger.info(f"{agent_name}: {session_id}")
except Exception as e:
self.logger.warning(f"{agent_name}: {str(e)}")
self.logger.info(f"✅ LEITL enabled for {len(sessions)}/{len(self._agents)} agents")
return sessions
async def disable_leitl_for_all(self):
"""Disable LEITL protocol for all agents"""
self.logger.info("🔌 Disabling LEITL for all agents...")
for agent_name, agent in self._agents.items():
try:
await agent.disable_leitl()
self.logger.debug(f"{agent_name}")
except Exception as e:
self.logger.warning(f"{agent_name}: {str(e)}")
self.logger.info("✅ LEITL disabled for all agents")
def get_leitl_status(self) -> Dict[str, Any]:
"""
Get LEITL status for all agents
Returns:
Dict with LEITL enabled counts and session IDs
"""
enabled_agents = {}
disabled_agents = []
for agent_name, agent in self._agents.items():
if agent._leitl_enabled:
enabled_agents[agent_name] = agent._leitl_session_id
else:
disabled_agents.append(agent_name)
return {
"leitl_enabled_count": len(enabled_agents),
"leitl_disabled_count": len(disabled_agents),
"enabled_agents": enabled_agents,
"disabled_agents": disabled_agents,
"total_agents": len(self._agents)
}