ACP
ACP agents use the @ACP class decorator and implement AcpAgentRuntime. HTTP is
the default endpoint transport; stdio is selected explicitly per agent. Each endpoint
and accepted connection has independent authentication, initialization, session,
and cancellation state.
import {Module} from '@heronjs/common';
import {HeronJS} from '@heronjs/core';
import {ACP, type AcpAgentRuntime, type AcpSessionContext} from '@heronjs/acp';
@ACP({path: '/acp/review', name: 'review', version: '1.0.0'})
class ReviewAgent implements AcpAgentRuntime {
createSession() {
return {};
}
async prompt({context}: {context: AcpSessionContext}) {
await context.update({sessionUpdate: 'agent_message_chunk', content: {type: 'text', text: 'Reviewed'}});
return {stopReason: 'end_turn' as const};
}
}
@ACP({path: '/acp/chat', name: 'chat', version: '1.0.0'})
class ChatAgent extends ReviewAgent {}
@Module({acps: [ReviewAgent, ChatAgent]})
class App {}
const app = await HeronJS.create({module: App});
await app.listen({port: 3000, host: '127.0.0.1'});@ACP({path: '/path'}) uses the class name and version 1.0.0. The object form accepts
{ name, version, path? }; its default path is /acp. Give agents distinct paths.
Duplicate paths fail registration before the listener opens. Imported modules and
auto-registration follow the same rules as other Heron extensions.
HTTP endpoints use the official SDK’s experimental/server and
experimental/node Streamable HTTP transport APIs, with stable ACP v1 agent
messages. The SDK transport API is experimental. Connect with
createHttpStream(url) from @agentclientprotocol/sdk/experimental/http-client.
The adapter shares core’s Node server and releases SDK connections on shutdown.
Configure limits and authentication directly on each agent:
@ACP({path: '/acp/chat', options: {
maxSessions: 100,
promptTimeout: 60_000,
authMethods,
authenticate,
}})
class ChatAgent implements AcpAgentRuntime {
/* ... */
}The path form defaults name/version as before. app.add({acp: {path}}) only sets
the default path; endpoint policies and transport selectors there are rejected.
allowedHosts and allowedOrigins default to loopback hostnames. Remote use
requires application authentication or explicit publicAccess, plus the relevant
Host/Origin allowlists. authMethods and authenticate implement ACP application
authentication and are isolated per connection. Session creation requires an
absolute cwd; unsupported content/capabilities fail explicitly. Prompt
cancellation and timeouts abort the context signal, and closeSession runs during
connection cleanup. Handler results support values, Promises, and Observables.
For stdio, declare transport: 'stdio' on the agent decorator and enable
runtime: {stdio: true}. Use start() without an HTTP listener, or listen() to
serve REST and other MCP/ACP HTTP endpoints alongside the selected stdio agent.
Every other endpoint still defaults to HTTP. Only one MCP or ACP endpoint per process
can own stdio. Framework logs go to stderr; stdout contains protocol messages.
The path identifies a stdio agent but is not exposed as an HTTP route.
Stdio echo agent
This complete example echoes text chunks and closes the application when the client closes stdin:
import { finished } from 'node:stream/promises';
import type { NewSessionRequest, PromptRequest, PromptResponse } from '@agentclientprotocol/sdk';
import { Module } from '@heronjs/common';
import { HeronJS } from '@heronjs/core';
import { ACP, type AcpAgentRuntime, type AcpSessionContext } from '@heronjs/acp';
@ACP({ name: 'heron-echo', version: '1.0.0', transport: 'stdio' })
class Echo implements AcpAgentRuntime {
createSession({request}: {request: NewSessionRequest}) {
if (request.mcpServers.length) throw new Error('This agent does not connect to MCP servers');
return {};
}
async prompt({request, context}: {request: PromptRequest; context: AcpSessionContext}): Promise<PromptResponse> {
for (const content of request.prompt) {
if (context.signal.aborted) return { stopReason: 'cancelled' };
if (content.type === 'text') await context.update({ sessionUpdate: 'agent_message_chunk', content });
}
return { stopReason: 'end_turn' };
}
}
@Module({ acps: [Echo] })
class App {}
await using app = await HeronJS.create({ module: App, runtime: { stdio: true } });
await app.start();
await finished(process.stdin, { cleanup: true });Launch node dist/main.js as the ACP client’s agent subprocess.
Prompt updates and output limits
Await context.update(update) to preserve send order and observe failures. Each prompt
has a bounded update queue: maxPendingUpdates defaults to 128 and maxPendingUpdateBytes
to 1 MiB. Prompt completion drains accepted updates; cancellation discards pending updates.
Retained contexts cannot send updates after their prompt ends. HTTP connection settings
maxBufferedBytes, maxOutputStallMs, and maxBufferedSessionStreams are forwarded to
the ACP SDK; omitted values retain its defaults. The SDK counts HTTP output in serialized
UTF-16 code units, while the framework pending-update budget counts UTF-8 bytes.