Connect to Agents
Use any agent, anywhere, as if local. Create a proxy to a remote agent with the same interface.
Why connect? Access specialized agents from anywhere, build distributed workflows, scale horizontally across multiple machines.
60-Second Quick Start
Connect to a remote agent with one function call:
What Just Happened?
wss://oo.openonion.ai/ws/announceComplete Example: Two Terminals
Terminal 1: Host an Agent
Terminal 2: Connect and Use
Common Patterns
1. Connect to Multiple Agents
Build workflows with specialized remote agents:
2. Retry on Connection Failure
Handle network failures gracefully:
3. Agent Pool (Load Balancing)
Distribute load across multiple identical agents:
Multi-Turn Conversations
Remote agents maintain conversation state across multiple input() calls:
Real-World: Distributed Workflow
Local orchestrator using remote specialized agents:
Configuration
Default Relay (Production)
Local Relay (Development)
Environment-Based
Local vs Remote Agents
Local Agent
+ No network latency
+ Works offline
− Limited to one machine
− No sharing
Remote Agent
+ Access from anywhere
+ Share across team
− Network latency
− Requires connectivity
TypeScript SDK
The connectonion npm package provides the same connect() interface for TypeScript and JavaScript:
Basic Usage
Direct Connection (Deployed Agents)
Streaming Events
While the agent works, events stream in real-time via the ui property. Each event is a ChatItem:
| Event Type | Description |
|---|---|
| user | User message |
| agent | Agent response text |
| thinking | LLM thinking/reasoning |
| tool_call | Tool execution with name, args, result |
| ask_user | Agent asking a question (with options) |
| approval_needed | Tool requires user approval before running |
| plan_review | Agent presenting a plan for review |
React Hook: useAgent()
The SDK includes a React hook that wraps connect() with state management and localStorage persistence:
Session persistence: The hook automatically saves conversation state to localStorage using the sessionId. Page refreshes restore the full conversation.
Interactive Features
Agents can ask questions, request approval for dangerous tools, and present plans for review. Here's how to handle each:
Ask User
Agent needs information from the user:
Tool Approval
Agent wants to run a tool that needs permission:
Plan Review
Agent presenting a plan before executing:
oo-chat: Open-Source Reference Client
oo-chat is an open-source Next.js chat client built on the TypeScript SDK. It's a complete working example of how to build a chat UI for ConnectOnion agents.
oo-chat/ ├── app/[address]/[sessionId]/page.tsx ← session page (uses useAgentSDK) ├── components/chat/ │ ├── chat.tsx ← main Chat component │ ├── chat-input.tsx ← message input │ ├── chat-messages.tsx ← message list │ ├── use-agent-sdk.ts ← wrapper hook around useAgent() │ └── messages/ │ ├── tool-call.tsx ← tool call rendering │ └── tools/plan-card.tsx ← plan review UI └── package.json ← depends on connectonion
How oo-chat Connects
Architecture
┌──────────────────────────────────────────────────┐
│ oo-chat (Next.js) │
│ │
│ page.tsx │
│ └─ useAgentSDK() ← elapsed time, pending │
│ └─ useAgent() ← connectonion/react │
│ └─ connect() ← WebSocket to agent │
│ │
│ <Chat /> │
│ ├─ <ChatMessages /> ← renders ui: ChatItem[] │
│ ├─ <AskUser /> ← from pendingAskUser │
│ ├─ <Approval /> ← from pendingApproval │
│ └─ <ChatInput /> ← calls send() │
└──────────────────────────────────────────────────┘
│ WebSocket
▼
┌──────────────────────────────────────────────────┐
│ Hosted Agent (Python) │
│ host(agent) │
└──────────────────────────────────────────────────┘Ready to Use Remote Agents?
Python, TypeScript, or React — connect to any agent with one function call.
