ai-query library uses a unified transport layer that decouples Agent Logic from Infrastructure. This allows you to write agent code once and deploy it anywhere—in a single process, across microservices, or on serverless functions.
Concepts
Agent Registry
The Registry maps Agent IDs (e.g.,"researcher", "room-1") to their implementation. It solves the problem of “Where does this agent live?”.
- Local Mapping: Maps an ID to a Python class. The
AgentServerinstantiates it on demand. - Remote Mapping: Maps an ID to a URL via a
Transport. The agent lives on another server.
Transports
Transports handle the low-level communication between agents.LocalTransport: Direct in-memory communication. Used when agents are in the same process.HTTPTransport: Uses HTTP/REST to communicate with agents on other servers (or serverless functions).
Detailed API Reference
For comprehensive API documentation and examples, see:- AgentRegistry - Registry for multi-agent routing
- HTTPTransport - HTTP transport for remote agents
- RemoteAgent - Client-side proxy for remote agents
- Transport Base Classes - Abstract base for custom transports
- Serverless Adapters - FastAPI, Vercel, AWS Lambda adapters
Configuration
Basic (Single Agent Class)
The default behavior is simple: serve one type of agent for all IDs.Advanced (Multi-Agent Registry)
UseAgentRegistry to serve multiple different agent types or route to remote agents.
Consuming Remote Agents
You don’t needAgentServer to use remote agents. You can use connect() in your client scripts or other applications.
Wire Protocol
HTTPTransport uses a standard JSON protocol over HTTP POST.
Endpoints
POST /{agent_id}/chat: Standard chat interaction.POST /{agent_id}/invoke: RPC method calls.
Chat Request
Streaming Request
text/event-stream with data: ... chunks.