返回 Skill 列表
extension
分类: 开发与工程无需 API Key

AgentObservability

实时可观测性仪表板,适用于多代理Claude Code会话。通过网络仪表板实时可视化代理交互、工具使用情况和会话流程。利用泳道可视化、事件过滤和实时图表跟踪并行运行的多个代理。当用户说'开始可观测性', '代理仪表板', '监控代理', '观察代理活动', '多代理监控', '跟踪子代理'或需要调试多代理工作流时使用。**主要特点:** - 🔴 通过WebSocket实现实时事件流 - 📊 显示并行执行的代理泳道 - 🔍 按代理、会话、事件类型进行事件过滤 - 📈 工具使用模式的实时图表 - 💾 基于文件系统(无需数据库)**灵感来自[@indydevdan](https://github.com/indydevdan)**在多代理可观测性方面的工作。**我们的方法:** 文件系统+内存流与indydevdan的SQLite数据库方法相对。

person作者: jakexiaohubgithub

Agent Observability Skill

When to Activate This Skill

  • User wants to monitor agent activity
  • Need to debug multi-agent workflows
  • Track parallel subagent execution
  • Visualize tool usage patterns
  • Analyze session flows in real-time

Prerequisites

  • Bun runtime installed
  • Claude Code with hooks configured
  • PAI_DIR environment variable set

Installation

See SETUP.md for complete installation instructions.

Quick Setup:

# 1. Set environment variable
export PAI_DIR="$HOME/.claude"  # Add to ~/.zshrc or ~/.bashrc

# 2. Configure hooks (merge into ~/.claude/settings.json)
cat settings.json.example

# 3. Create directory structure
mkdir -p ~/.claude/history/raw-outputs

# 4. Install dependencies
cd apps/server && bun install
cd ../client && bun install

Usage

Start the Observability Dashboard

Terminal 1 - Server:

cd ~/Projects/PAI/skills/agent-observability/apps/server
bun run dev

Terminal 2 - Client:

cd ~/Projects/PAI/skills/agent-observability/apps/client
bun run dev

Open browser: http://localhost:5173

Using Claude Code

Once the dashboard is running, any Claude Code activity will appear in real-time:

  1. Open Claude Code
  2. Use any tool (Read, Write, Bash, etc.)
  3. Launch subagents with Task tool
  4. Watch events appear in the dashboard

Event Types Captured

  • SessionStart - New Claude Code session begins
  • UserPromptSubmit - User sends a message
  • PreToolUse - Before a tool is executed
  • PostToolUse - After a tool completes
  • Stop - Main agent task completes
  • SubagentStop - Subagent task completes
  • SessionEnd - Session ends

Features

Real-Time Visualization

  • Agent Swim Lanes: See multiple agents (kai, designer, engineer, etc.) running in parallel
  • Event Timeline: Chronological view of all events
  • Tool Usage Charts: Visualize which tools are being used most
  • Session Tracking: Track individual sessions and their lifecycles

Filtering & Search

  • Filter by agent name (kai, designer, engineer, pentester, etc.)
  • Filter by event type (PreToolUse, PostToolUse, etc.)
  • Filter by session ID
  • Search event payloads

Data Storage

Events are stored in JSONL (JSON Lines) format:

~/.claude/history/raw-outputs/YYYY-MM/YYYY-MM-DD_all-events.jsonl

Each line is a complete JSON object:

{"source_app":"kai","session_id":"abc123","hook_event_type":"PreToolUse","payload":{...},"timestamp":1234567890,"timestamp_pst":"2025-01-28 14:30:00 PST"}

In-Memory Streaming

  • Server keeps last 1000 events in memory
  • Low memory footprint
  • Fast real-time updates via WebSocket
  • No database overhead

Architecture

┌─────────────────┐
│  Claude Code    │  Executes hooks on events
│   (with hooks)  │
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│ capture-all-    │  Appends events to JSONL
│ events.ts hook  │
└────────┬────────┘
         │
         ▼
┌─────────────────────────────────────┐
│ ~/.claude/history/raw-outputs/      │  Daily JSONL files
│ 2025-01/2025-01-28_all-events.jsonl │
└────────┬────────────────────────────┘
         │
         ▼
┌─────────────────┐
│ file-ingest.ts  │  Watches files, streams to memory
│  (Bun server)   │
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│  Vue 3 Client   │  Real-time dashboard visualization
│  (Vite + Tail)  │
└─────────────────┘

Configuration

Environment Variables

PAI_DIR: Path to your PAI directory (defaults to ~/.claude/)

export PAI_DIR="/Users/yourname/.claude"

Hooks Configuration

Add to ~/.claude/settings.json (see settings.json.example for full template):

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "*",
      "hooks": [{
        "type": "command",
        "command": "${PAI_DIR}/skills/agent-observability/hooks/capture-all-events.ts --event-type PreToolUse"
      }]
    }],
    // ... other hooks
  }
}

Troubleshooting

No events appearing

  1. Check PAI_DIR is set: echo $PAI_DIR
  2. Verify directory exists: ls ~/.claude/history/raw-outputs/
  3. Check hook is executable: ls -l hooks/capture-all-events.ts
  4. Look for today's events file: ls ~/.claude/history/raw-outputs/$(date +%Y-%m)/

Server won't start

  1. Check Bun is installed: bun --version
  2. Verify dependencies: cd apps/server && bun install
  3. Check port 3001 isn't in use: lsof -i :3001

Client won't connect

  1. Ensure server is running first
  2. Check WebSocket connection in browser console
  3. Verify no firewall blocking localhost:3001

Credits

Inspired by @indydevdan's pioneering work on multi-agent observability for Claude Code.

Our implementation differs by using filesystem-based event capture and in-memory streaming instead of SQLite database persistence. Both approaches have their merits! Check out indydevdan's work for a database-backed solution with full historical persistence.

Development

Running in Development

# Server (hot reload)
cd apps/server
bun --watch src/index.ts

# Client (Vite dev server)
cd apps/client
bun run dev

Building for Production

# Client build
cd apps/client
bun run build
bun run preview

Adding New Event Types

  1. Update capture-all-events.ts hook if needed
  2. Add hook configuration to settings.json
  3. Client will automatically display new event types

Documentation

License

Part of the PAI (Personal AI Infrastructure) project.

Contributing

Contributions welcome! Areas for improvement:

  • Historical data persistence options
  • Export functionality (CSV, JSON)
  • Alert/notification system
  • Advanced filtering and search
  • Session replay capability
  • Integration with other PAI skills