Skip to content

davidzech27/thread

Repository files navigation

Thread - AI Agent System with Real-time Visualization

A full-stack application that combines an intelligent AI agent backend with a real-time visualization frontend. Watch as AI agents spawn, execute tasks, and collaborate to solve complex problems.

🌟 Features

  • Real-time Agent Visualization: See your AI agents work in a beautiful tree structure
  • Multi-Agent System: Agents can spawn sub-agents to explore parallel solutions
  • Human-in-the-Loop: Agents can ask for clarification when needed
  • Python Tool Integration: Agents can execute Python code with fork/wait capabilities
  • WebSocket Communication: Instant updates as agents work
  • Streaming Responses: See agent thoughts as they're generated

πŸ—οΈ Architecture

Backend (Bun + TypeScript)

  • WebSocket server on port 3001
  • Sophisticated agent system with:
    • Clarification checks
    • Blocking questions when needed
    • Async subquestion generation
    • Python execution environment
    • Fork/wait for parallel agent execution

Frontend (SolidJS + React Flow)

  • Real-time visualization of agent tree
  • Interactive node system
  • User input handling
  • Connection status monitoring

πŸš€ Quick Start

Prerequisites

  • Bun (for backend)
  • Node.js (for frontend)
  • Anthropic API key

Setup

  1. Clone and navigate to the project

    cd thread
  2. Configure backend

    cd backend
    cp .env.example .env  # If you have one
    # Edit .env and add your ANTHROPIC_API_KEY
  3. Install dependencies

    # Backend
    cd backend
    bun install
    
    # Frontend
    cd ../frontend
    npm install

Running

Option 1: Automated (Recommended)

Linux/Mac:

chmod +x start.sh
./start.sh

Windows:

start.bat

Option 2: Manual

Terminal 1 - Backend:

cd backend
bun run dev

Terminal 2 - Frontend:

cd frontend
npm run dev

πŸ“– Usage

  1. Open your browser to the frontend URL (usually http://localhost:5173)
  2. Check that the connection indicator shows "Connected" (green dot)
  3. Enter a prompt in the master node textbox
  4. Watch as agents spawn and work on your request
  5. If an agent needs input, it will show an orange border with a question
  6. Type your response and press Enter
  7. The final answer will be highlighted with a special badge

🎨 Visual Guide

Node Status Colors

  • πŸ”΅ Blue - Running: Agent is actively working
  • 🟒 Green - Completed: Agent finished successfully
  • πŸ”΄ Red - Error: Something went wrong
  • 🟠 Orange - Awaiting User: Agent needs your input
  • βšͺ Gray - Idle: Agent hasn't started yet

Special Indicators

  • Thick green border + badge - Final answer from master agent
  • Orange highlight - Agent is waiting for user response
  • Animated edges - Active data flow

πŸ”§ Configuration

Backend Environment Variables

AI_MODEL=claude-3-5-haiku-20241022
ANTHROPIC_API_KEY=your_key_here

Ports

  • Backend WebSocket: 3001
  • Frontend Dev Server: Default Vite port (usually 5173)

πŸ“‘ Communication Protocol

See INTEGRATION.md for detailed WebSocket message specifications.

Key Message Types

Frontend β†’ Backend:

  • start-agent - Begin new agent with prompt
  • user-response - Answer to agent's question
  • user-intervention - Modify/delete agent

Backend β†’ Frontend:

  • agent-state - Agent status update
  • text-delta - Streaming text chunk
  • user-query - Agent asking for input
  • agent-completed - All work finished

πŸ› οΈ Development

Project Structure

thread/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ index.ts        # WebSocket server
β”‚   β”‚   β”œβ”€β”€ ai.ts           # Agent system
β”‚   β”‚   β”œβ”€β”€ agent.ts        # Simple agent
β”‚   β”‚   └── python.ts       # Python execution
β”‚   β”œβ”€β”€ package.json
β”‚   └── tsconfig.json
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.tsx         # Main app + WebSocket client
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ AgentNode.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ MasterNode.tsx
β”‚   β”‚   β”‚   └── ReactFlowWrapper.tsx
β”‚   β”‚   └── types/
β”‚   β”‚       └── Node.ts
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.ts
β”œβ”€β”€ INTEGRATION.md          # Technical integration docs
└── README.md               # This file

Key Technologies

  • Backend: Bun, TypeScript, Anthropic AI SDK, Zod
  • Frontend: SolidJS, React Flow, TypeScript
  • Communication: WebSocket (native Bun WebSocket)

πŸ› Troubleshooting

"WebSocket not connected"

  • Ensure backend is running on port 3001
  • Check for firewall/antivirus blocking WebSocket
  • Verify .env has valid API key

Agents not appearing

  • Open browser DevTools console
  • Check for WebSocket messages
  • Verify backend logs show agent creation

Text not streaming

  • Confirm text-delta messages include agentId
  • Check backend is properly forwarding chunks
  • Verify frontend is handling messages

🀝 Contributing

This is a demonstration project showcasing real-time AI agent visualization. Feel free to:

  • Report issues
  • Suggest features
  • Submit pull requests
  • Fork and experiment

πŸ“ License

See LICENSE file for details.

πŸ™ Acknowledgments

πŸ“š Further Reading


Built with ❀️ for exploring AI agent systems

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors