Expose Agent over RPC and HTTP
Use AgentRPC and AgentHTTP from @downcity/server to expose a local Agent as a network service
Expose Agent over RPC and HTTP
@downcity/agent only constructs Agents and runs sessions. Network exposure lives in a separate package, @downcity/server. Install and start it on demand.
pnpm add @downcity/agent @downcity/serverAgent has no start() anymore
After new Agent(...), plugin lifecycle and ActionSchedule start automatically. You do not need to call start().
await agent.ready(): wait until background services are up. Use it before reading plugin state right after construction.await agent.dispose(): release background resources (plugins, ActionSchedule, shell).
RPC and HTTP are no longer Agent responsibilities.
AgentRPC: expose as local RPC
AgentRPC exposes an Agent over NDJSON-on-TCP for RemoteAgent("rpc://...").
import { Agent } from "@downcity/agent";
import { AgentRPC } from "@downcity/server";
const agent = new Agent({ id, path, model });
await agent.ready();
const rpc = new AgentRPC(agent);
const binding = await rpc.listen({ host: "127.0.0.1", port: 15314 });
console.log(binding.url); // rpc://127.0.0.1:15314
// shutdown
await rpc.close();
await agent.dispose();AgentRPC defaults to 127.0.0.1:15314. The protocol is NDJSON, no auth. Use it on local or trusted networks.
AgentHTTP: expose minimal SDK HTTP surface
AgentHTTP provides the minimal HTTP surface (/api/sdk/sessions/*) consumed by the RemoteAgent HTTP client. Two usage modes; pick one.
Mode 1: standalone HTTP server
import { Agent } from "@downcity/agent";
import { AgentHTTP } from "@downcity/server";
const agent = new Agent({ id, path, model });
await agent.ready();
const http = new AgentHTTP(agent);
const binding = await http.server().listen({ host: "127.0.0.1", port: 5314 });
console.log(binding.url); // http://127.0.0.1:5314
// shutdown
await http.close();
await agent.dispose();Mode 2: mount onto your own Hono server
AgentHTTP.router() returns a Hono sub-router. Mount it directly:
import { Hono } from "hono";
import { AgentHTTP } from "@downcity/server";
const app = new Hono();
const http = new AgentHTTP(agent);
app.route("/", http.router());CORS / logger / auth middleware are your responsibility. AgentHTTP does not attach any.
Relationship with Downcity and RemoteAgent
downcity agent startwiresAgent + AgentRPC + AgentHTTP.router()together and adds Downcity's own control / static routes on top.RemoteAgentclients can connect to therpc://URL exposed byAgentRPC.listen()or to the HTTP surface exposed byAgentHTTP.
Related docs
- Local Agent quickstart
- RemoteAgent quickstart
- AgentRPC — RPC transport setup
- AgentHTTP — HTTP transport setup