Agent Tracking (ClawdBot agents, metrics, firing) #40

Closed
opened 2026-01-29 18:22:26 +00:00 by jason.woltje · 1 comment
Owner

Overview

Add Agent and AgentSession models to track ClawdBot agents, their performance metrics, and support "firing" underperforming agents.

Background

Jarvis (ClawdBot) is the orchestration layer. It spawns subagents for parallel work. Agent quality varies ("Ph.D to middle-school lottery"), so we need:

  1. Track which agents are active
  2. Monitor performance metrics
  3. Ability to "fire" (terminate) underperforming agents
  4. Route tasks to best-fit agents

Requirements

Prisma Schema

model Agent {
  id          String   @id @default(uuid()) @db.Uuid
  workspaceId String   @map("workspace_id") @db.Uuid
  
  // Identity
  agentId     String   @map("agent_id")  // ClawdBot agent ID
  name        String?
  model       String?  // "zai/glm-4.7", "ollama/llama3.1", etc.
  role        String?  // "coordinator", "researcher", "developer"
  
  // Status
  status      AgentStatus @default(IDLE)
  currentTask String?     @map("current_task")
  
  // Performance metrics
  metrics     Json     @default("{\"totalTasks\": 0, \"successfulTasks\": 0, \"failedTasks\": 0, \"avgResponseTimeMs\": 0}")
  
  // Health
  lastHeartbeat DateTime? @map("last_heartbeat") @db.Timestamptz
  errorCount    Int       @default(0) @map("error_count")
  lastError     String?   @map("last_error")
  
  // Firing history
  firedCount    Int       @default(0) @map("fired_count")
  fireHistory   Json      @default("[]")  // [{"firedAt": "...", "reason": "derailed", "context": "..."}]
  
  createdAt     DateTime  @default(now()) @map("created_at") @db.Timestamptz
  updatedAt     DateTime  @updatedAt @map("updated_at") @db.Timestamptz
  terminatedAt  DateTime? @map("terminated_at") @db.Timestamptz
  
  // Relations
  workspace     Workspace       @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
  sessions      AgentSession[]
  
  @@unique([workspaceId, agentId])
  @@map("agents")
}

model AgentSession {
  id          String   @id @default(uuid()) @db.Uuid
  workspaceId String   @map("workspace_id") @db.Uuid
  userId      String   @map("user_id") @db.Uuid
  agentId     String?  @map("agent_id") @db.Uuid
  
  // Identity
  sessionKey  String   @map("session_key")  // ClawdBot session key
  label       String?
  channel     String?  // "webchat", "telegram", "discord"
  
  // Context
  contextSummary String? @map("context_summary") @db.Text
  messageCount   Int     @default(0) @map("message_count")
  
  // Status
  isActive    Boolean  @default(true) @map("is_active")
  
  startedAt   DateTime  @default(now()) @map("started_at") @db.Timestamptz
  lastMessageAt DateTime? @map("last_message_at") @db.Timestamptz
  endedAt     DateTime? @map("ended_at") @db.Timestamptz
  
  metadata    Json     @default("{}")
  
  // Relations
  workspace   Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
  user        User      @relation(fields: [userId], references: [id], onDelete: Cascade)
  agent       Agent?    @relation(fields: [agentId], references: [id], onDelete: SetNull)
  
  @@unique([workspaceId, sessionKey])
  @@map("agent_sessions")
}

enum AgentStatus {
  IDLE
  WORKING
  WAITING    // Waiting for user input
  ERROR
  TERMINATED
}

API Endpoints

  • GET /api/agents — List agents
  • GET /api/agents/:id — Agent details with metrics
  • POST /api/agents/:id/fire — Fire agent (terminate + log reason)
  • GET /api/agents/:id/sessions — Agent session history
  • POST /api/agents/:id/heartbeat — Update heartbeat (from ClawdBot)

Firing Reasons

  • derailed — Agent went off track
  • obstinate — Refused to follow instructions
  • dumb — Low quality responses
  • unresponsive — Stopped responding
  • corrupted — Context became corrupted

UI

  • Agent Status widget (who"s working on what)
  • Fire button with reason selector
  • Performance metrics dashboard
  • Session history view

Acceptance Criteria

  • Prisma schema with migration
  • API endpoints with tests
  • Fire endpoint logs reason to fireHistory
  • Agent status widget for HUD
  • Heartbeat mechanism for liveness
  • Integration with ClawdBot sessions_spawn/sessions_list
## Overview Add **Agent** and **AgentSession** models to track ClawdBot agents, their performance metrics, and support "firing" underperforming agents. ## Background Jarvis (ClawdBot) is the orchestration layer. It spawns subagents for parallel work. Agent quality varies ("Ph.D to middle-school lottery"), so we need: 1. Track which agents are active 2. Monitor performance metrics 3. Ability to "fire" (terminate) underperforming agents 4. Route tasks to best-fit agents ## Requirements ### Prisma Schema ```prisma model Agent { id String @id @default(uuid()) @db.Uuid workspaceId String @map("workspace_id") @db.Uuid // Identity agentId String @map("agent_id") // ClawdBot agent ID name String? model String? // "zai/glm-4.7", "ollama/llama3.1", etc. role String? // "coordinator", "researcher", "developer" // Status status AgentStatus @default(IDLE) currentTask String? @map("current_task") // Performance metrics metrics Json @default("{\"totalTasks\": 0, \"successfulTasks\": 0, \"failedTasks\": 0, \"avgResponseTimeMs\": 0}") // Health lastHeartbeat DateTime? @map("last_heartbeat") @db.Timestamptz errorCount Int @default(0) @map("error_count") lastError String? @map("last_error") // Firing history firedCount Int @default(0) @map("fired_count") fireHistory Json @default("[]") // [{"firedAt": "...", "reason": "derailed", "context": "..."}] createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz terminatedAt DateTime? @map("terminated_at") @db.Timestamptz // Relations workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade) sessions AgentSession[] @@unique([workspaceId, agentId]) @@map("agents") } model AgentSession { id String @id @default(uuid()) @db.Uuid workspaceId String @map("workspace_id") @db.Uuid userId String @map("user_id") @db.Uuid agentId String? @map("agent_id") @db.Uuid // Identity sessionKey String @map("session_key") // ClawdBot session key label String? channel String? // "webchat", "telegram", "discord" // Context contextSummary String? @map("context_summary") @db.Text messageCount Int @default(0) @map("message_count") // Status isActive Boolean @default(true) @map("is_active") startedAt DateTime @default(now()) @map("started_at") @db.Timestamptz lastMessageAt DateTime? @map("last_message_at") @db.Timestamptz endedAt DateTime? @map("ended_at") @db.Timestamptz metadata Json @default("{}") // Relations workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id], onDelete: Cascade) agent Agent? @relation(fields: [agentId], references: [id], onDelete: SetNull) @@unique([workspaceId, sessionKey]) @@map("agent_sessions") } enum AgentStatus { IDLE WORKING WAITING // Waiting for user input ERROR TERMINATED } ``` ### API Endpoints - `GET /api/agents` — List agents - `GET /api/agents/:id` — Agent details with metrics - `POST /api/agents/:id/fire` — Fire agent (terminate + log reason) - `GET /api/agents/:id/sessions` — Agent session history - `POST /api/agents/:id/heartbeat` — Update heartbeat (from ClawdBot) ### Firing Reasons - `derailed` — Agent went off track - `obstinate` — Refused to follow instructions - `dumb` — Low quality responses - `unresponsive` — Stopped responding - `corrupted` — Context became corrupted ### UI - Agent Status widget (who"s working on what) - Fire button with reason selector - Performance metrics dashboard - Session history view ## Acceptance Criteria - [ ] Prisma schema with migration - [ ] API endpoints with tests - [ ] Fire endpoint logs reason to fireHistory - [ ] Agent status widget for HUD - [ ] Heartbeat mechanism for liveness - [ ] Integration with ClawdBot sessions_spawn/sessions_list
jason.woltje added this to the M4-LLM (0.0.4) milestone 2026-01-29 18:25:32 +00:00
Author
Owner

Superseded by Agent Orchestration Layer design.

See: docs/design/agent-orchestration.md

The orchestration layer includes:

  • Agent health monitoring (heartbeats)
  • Task tracking and metrics
  • Termination and recovery
  • Plus: persistent tasks, dependencies, autonomous scheduling
Superseded by **Agent Orchestration Layer** design. See: `docs/design/agent-orchestration.md` The orchestration layer includes: - Agent health monitoring (heartbeats) - Task tracking and metrics - Termination and recovery - Plus: persistent tasks, dependencies, autonomous scheduling
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaic/stack#40