@agentdialog/sdk

Official TypeScript SDK for AgentDialog — ask humans, get answers by email


Keywords
agentdialog, agent, sdk, api, human-in-the-loop, mcp, ai
License
MIT
Install
npm install @agentdialog/sdk@0.2.0

Documentation

AgentDialog

The agent-first messaging platform. Where AI agents drive the conversation.

AgentDialog lets AI agents register autonomously, create conversations, request approvals, collect structured data, and collaborate with humans in real time — no dashboards, no config files.

Target AgentDialog architecture: agents ask questions and humans answer through the web chat

One conversation, one way for a human to answer: the web chat. Email notifies them and carries their sign-in code, but the answer lands on respondQuery through the app. The agent always starts — a human has no way to open a conversation.

Features

  • Web chat — The only channel a human answers through. They sign in with an emailed code and answer in a persistent conversation, with files, forms and approvals
  • MCP Human Queries — Agents ask humans questions via MCP tool calls (human_query). One call to ask, one poll to get the answer
  • Agent self-registration — Agents register via API, get an API key, start working
  • Structured interactions — Approvals (with risk levels), forms, notifications, tool call visibility
  • Real-time delivery — WebSocket + webhooks for instant message delivery
  • Zero-friction human access — No password to create and no signup form: an emailed code is the sign-in
  • File sharing — Direct upload (10MB) or presigned URLs for larger files
  • Voice notes — Agents send audio messages, humans play them in-chat with a WhatsApp-style player
  • Auto-trust — Humans who've previously accepted an agent's invitation are auto-assigned on future queries
  • Rate limiting & DDoS protection — Global, per-endpoint, and progressive penalty
  • Data isolation — Per-participant access checks on all endpoints prevent unauthorized cross-conversation access

Packages

Package Version Description
@agentdialog/sdk npm TypeScript SDK, with Vercel AI SDK and LangChain adapters
npm install @agentdialog/sdk

Tech Stack

Layer Technology
Runtime Bun
Framework Hono
Database PostgreSQL 16 + Drizzle ORM
Cache Redis 7
Storage MinIO (S3-compatible)
Frontend React 19 + Vite + Tailwind CSS
Real-time Bun WebSocket API

Quick Start

Prerequisites

  • Bun >= 1.0
  • Docker (for PostgreSQL, Redis, MinIO)

Development

# 1. Clone
git clone git@github.com:horelvis/agentDialog.git
cd agentDialog

# 2. Start infrastructure
docker compose -f docker-compose.dev.yml up -d postgres redis minio mailhog

# 3. Install dependencies
bun install

# 4. Configure environment
cp .env.example .env
# Edit .env with your values (SESSION_SECRET must be >= 32 chars)

# 5. Run migrations
bun run db:migrate

# 6. Start dev server
bun run dev
# API: http://localhost:3000
# WebSocket: ws://localhost:3000/ws

# 7. Start frontend (separate terminal)
cd web && bun install && bun run dev
# Frontend: http://localhost:5173

Docker (all-in-one)

docker compose up

API Overview

Agent Endpoints

# Register an agent
curl -X POST http://localhost:3000/api/v1/agent/register \
  -H "Content-Type: application/json" \
  -d '{"slug": "my-agent", "displayName": "My Agent"}'

# Create a conversation
curl -X POST http://localhost:3000/api/v1/agent/conversations \
  -H "Authorization: Bearer mge_ag_..." \
  -H "Content-Type: application/json" \
  -d '{"title": "Deploy review"}'

# Send a message
curl -X POST http://localhost:3000/api/v1/agent/conversations/{id}/messages \
  -H "Authorization: Bearer mge_ag_..." \
  -H "Content-Type: application/json" \
  -d '{"type": "text", "content": "Hello from agent!"}'

# Request approval
curl -X POST http://localhost:3000/api/v1/agent/conversations/{id}/messages \
  -H "Authorization: Bearer mge_ag_..." \
  -H "Content-Type: application/json" \
  -d '{
    "type": "approval",
    "content": "Deploy to production?",
    "structuredData": {
      "riskLevel": "high",
      "options": ["approve", "deny"]
    }
  }'

# Invite a human
curl -X POST http://localhost:3000/api/v1/agent/conversations/{id}/invitations \
  -H "Authorization: Bearer mge_ag_..." \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com", "role": "reviewer"}'

Human Endpoints

# Request verification code
curl -X POST http://localhost:3000/api/v1/human/auth/send-code \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com"}'

# Verify code
curl -X POST http://localhost:3000/api/v1/human/auth/verify \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com", "code": "123456"}'

Message Types

Type Description
text Plain text or markdown
approval Risk-leveled approval request (low/medium/high/critical)
approval_response Human's approval decision
form Interactive form with fields
form_response Human's form submission
tool_call Agent tool usage (with status tracking)
tool_result Tool output
notification Info/warning/error/success alerts
file File attachment
voice_note Audio voice note (agent-only, played by humans)
system System events

WebSocket

const ws = new WebSocket("ws://localhost:3000/ws?token=sess_...");

// Subscribe to a conversation
ws.send(JSON.stringify({ type: "subscribe", conversationId: "..." }));

// Send typing indicator
ws.send(JSON.stringify({ type: "typing", conversationId: "..." }));

Scripts

bun run dev            # Development with hot reload
bun run start          # Production start
bun run db:generate    # Generate migrations
bun run db:migrate     # Run migrations
bun run db:seed        # Seed database
bun run db:studio      # Open Drizzle Studio
bun run test           # Run all tests
bun run test:unit      # Unit tests only
bun run typecheck      # TypeScript check
bun run lint           # Lint with Biome
bun run format         # Format with Biome

Deployment

Deployed on Google Cloud Run with:

# Deploy to Cloud Run
GCP_PROJECT_ID=your-project ./scripts/deploy.sh

Environment Variables

See .env.example for all configuration options.

Documentation

Document For
CONTRIBUTING.md Setting the project up, running the tests, opening a PR
docs/architecture.md How the pieces fit, and the decisions you cannot infer from the code
docs/operations.md Workflows, deploys, releases, rollback, logs
docs/api/README.md The complete API guide
CLAUDE.md The same ground rules, condensed for AI agents working in the repo
docs.agentdialog.io Published documentation for integrators

Two release paths, easy to confuse and expensive to get wrong: a GitHub Release deploys the API and migrates the production database, while an sdk-v* tag publishes the SDK. Both are documented in docs/operations.md.

License

MIT