Catalog PyPI
PACKAGE EXPLORERView in registry

ai-agent-bridge

PyPI

Modular bridge between chat platforms and AI agents

Versions collected1
Direct dependencies6From release 0.13.1
Last observed21 Oct, 09:51 UTC

README

Version 0.13.1 documentation

Agent Bridge

Modular bridge that connects chat platforms to AI agents. Each layer is independent — swap platforms or agents without touching the others.

Currently supports: Slack, Heartbeat, HTTP Webhook + Claude Code, Pi, Codex, Opencode

┌──────────────┐     ┌──────────┐     ┌──────────────┐
│   Platform   │────▶│  Bridge  │────▶│    Agent     │
│   (Slack)    │◀────│ (Router) │◀────│ (Claude Code)│
└──────────────┘     └──────────┘     └──────────────┘
  Session owner       Pure routing      Purely invoked
  Locking & render    Key → ID map      Yields events
  UI logic            Concurrency       No UI knowledge

Quick Start

Prerequisites

Install

git clone https://github.com/htkuan/ai-agent-bridge.git
cd agent-bridge
uv sync

Configure

cp .env.example .env

Edit .env with your tokens:

# Required for Slack
AGENT_BRIDGE_SLACK_BOT_TOKEN=xoxb-your-bot-token
AGENT_BRIDGE_SLACK_APP_TOKEN=xapp-your-app-level-token

# Claude Code working directory
AGENT_BRIDGE_CLAUDE_WORK_DIR=/path/to/your/project

See Environment Variables for the full list. Every variable is read in one place — AppConfig.from_env() walks each layer's {Component}Config.from_env(), and the whole app is then built from that single AppConfig.

Slack App Setup

  1. Create a Slack App at api.slack.com/apps
  2. Enable Socket Mode → generate an App-Level Token (xapp-...)
  3. Add Bot Token Scopes (OAuth & Permissions):
    • app_mentions:read, chat:write, files:write, im:history, im:read
    • channels:read, users:read, team:read — name lookups for the agent's context and the channel allow-list (add groups:read / mpim:read for private channels / group DMs). Missing these logs missing_scope warnings; see docs/platforms/slack.md
  4. Subscribe to Events:
    • app_mention, message.im
  5. Install to workspace → copy Bot User OAuth Token (xoxb-...)

Run

uv run agent-bridge

Usage

ActionHow
Channel@AgentBridge help me refactor this function
DMSend a direct message to the bot
Continue conversationReply in the same Slack thread
Attach filesUpload files in the message — the agent receives download URLs

Each Slack thread is one agent session. The agent remembers context within a thread.

Architecture

The system has three independent layers:

LayerRoleDocs
Platform AdapterOwns session semantics, per-session locking, UI renderingSlack · Heartbeat · Webhook
BridgeMiddleware pipeline: routing at the core; dedupe, session resolution, usage and capacity as stages over swappable portsBridge · Design
Agent ControllerExecutes prompts, yields generic eventsClaude Agent · Pi Agent · Codex Agent · Opencode Agent

Event Model

All agent output flows through generic events — the shared language between agents and platforms:

EventDescription
ProcessingSlot acquired, agent is starting
TextDeltaIncremental text from agent
StatusUpdateAgent performing an action (tool use, etc.)
UserQuestionAgent asking user for input
CompletionAgent finished (with cost, duration, error status)

Session Lifecycle

  1. User sends message → Platform constructs session key (e.g. slack:{channel}:{thread_ts})
  2. Bridge resolves key → UUID session ID (creates new if first message)
  3. Agent runs with session ID (new session or resume existing)
  4. Sessions expire after configurable TTL (default 72h)

Environment Variables

VariableRequiredDefaultDescription
ANTHROPIC_API_KEYNo—API key for the Claude Code CLI (skip if already authenticated via claude login)
AGENT_BRIDGE_SLACK_BOT_TOKENYes (if using Slack)—Slack Bot User OAuth Token (xoxb-...)
AGENT_BRIDGE_SLACK_APP_TOKENYes (if using Slack)—Slack App-Level Token for Socket Mode (xapp-...)
AGENT_BRIDGE_CLAUDE_WORK_DIRNo.Working directory for Claude Code
AGENT_BRIDGE_CLAUDE_PERMISSION_MODENoacceptEditsClaude permission mode
AGENT_BRIDGE_CLAUDE_TIMEOUT_SECONDSNo600Per-invocation timeout (seconds)
AGENT_BRIDGE_CLAUDE_WORKTREE_ENABLEDNofalseRun each session in an isolated git worktree (requires origin/HEAD)
AGENT_BRIDGE_CLAUDE_MODELNo— (CLI default)Model passed to claude --model
AGENT_BRIDGE_PROFILES_PATHNo— (disabled)TOML file with named agent profiles ([claude.profiles.*], [pi.profiles.*], [codex.profiles.*], [opencode.profiles.*]) + Slack channel→profile routing (see profiles.example.toml)
AGENT_BRIDGE_PI_*No—Base config for named Pi agent profiles (work dir, provider, model, thinking, tool allowlist)
AGENT_BRIDGE_CODEX_*No—Base config for named Codex agent profiles (work dir, sandbox mode, model, effort, session map path)
AGENT_BRIDGE_OPENCODE_*No—Base config for named Opencode agent profiles (work dir, model, variant, session map path)
AGENT_BRIDGE_DEFAULT_AGENTNo— (env-built claude)Profile name that messages without an explicit agent route to
AGENT_BRIDGE_SESSION_STORE_PATHNo./sessions.jsonSession mapping file path
AGENT_BRIDGE_SESSION_TTL_HOURSNo72Session TTL (hours)
AGENT_BRIDGE_MAX_CONCURRENT_SESSIONSNo5Max concurrent agent processes
AGENT_BRIDGE_HEARTBEAT_ENABLEDNofalseEnable the heartbeat platform — fires a fixed prompt on a fixed interval
AGENT_BRIDGE_HEARTBEAT_INTERVAL_MINUTESYes (if heartbeat enabled)—Interval between heartbeat ticks (minutes)
AGENT_BRIDGE_HEARTBEAT_PROMPTYes (if heartbeat enabled)—Prompt sent on every heartbeat tick
AGENT_BRIDGE_HEARTBEAT_STATE_PATHNo./heartbeat.jsonLast-run timestamp path (used for restart catch-up)
AGENT_BRIDGE_HEARTBEAT_AGENTNo— (bridge default)Named agent profile the heartbeat ticks route to
AGENT_BRIDGE_HTTP_ENABLEDNofalseEnable the shared HTTP server (console page + HTTP platforms)
AGENT_BRIDGE_HTTP_HOSTNo127.0.0.1HTTP server bind address (loopback by default)
AGENT_BRIDGE_HTTP_PORTNo8080HTTP server port
AGENT_BRIDGE_WEBHOOK_ENABLEDNofalseEnable the webhook platform — POST /platforms/webhook/v1/messages, result delivered via callback
AGENT_BRIDGE_WEBHOOK_TOKENYes (if webhook enabled)—Bearer token guarding the webhook endpoint
AGENT_BRIDGE_LOG_LEVELNoINFODEBUG / INFO / WARNING / ERROR

Extending

Add a new platform

Create platforms/{name}/ with config.py and adapter.py. Subclass BasePlatformAdapter (platforms/base.py): pre-process your platform's native event into a BridgeRequest, call process(), and override the on_* hooks to render the streamed events. Define your session key format with make_session_key. HTTP-based platforms expose an APIRouter that gets mounted on the shared HTTP server. See the Slack and Webhook docs for reference.

Add a new agent

Create agents/{name}/ with config.py, controller.py, and events.py. Subclass CliAgentController (agents/base.py): describe your CLI with build_command() and parse_line(), and the base engine handles the subprocess lifecycle — the AgentController protocol stays the contract, and run() yields BridgeEvents. See Claude Agent docs for reference.

Neither change requires modifying the bridge, the other agent, or the other platform.

Development

# Run tests
uv run pytest tests/ -v

# Run the live e2e against the real claude CLI (opt-in, spends tokens)
uv run pytest -m live --live --no-cov -v

# Run with debug logging
AGENT_BRIDGE_LOG_LEVEL=DEBUG uv run agent-bridge

Test layout, fakes and markers: docs/testing.md.

Commits follow Conventional Commits (lowercase types: feat:, fix:, ...) and are enforced on PRs. Merging to main cuts a release automatically — see docs/releasing.md.

License

MIT

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.13.125 Aug 20266

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
htkuan/ai-agent-bridge

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 09:51 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:b6d3b1cdec984200c8a031d3fc703230a92be0fd68fbfe44037e9f3e0980d1f5