ACP HTTP Client
acp-http-client is a TypeScript-first client library designed for interacting with Agent Computer Protocol (ACP) JSON-RPC services over streamable HTTP. It facilitates communication with a 'sandbox agent,' enabling operations such as desktop computer-use APIs, agent computer providers, and lifecycle management features like auto-pause support. The library is part of the larger Rivet Sandbox Agent project, which focuses on advanced agent capabilities for AI agents. Currently, the stable version is 0.4.2, with active development progressing towards 0.5.0, as indicated by recent release candidates (e.g., 0.5.0-rc.3). Development appears continuous, with frequent releases incorporating new features and fixes related to agent providers, E2B integration, and underlying agent infrastructure. Its key differentiator lies in its specialized focus on ACP and streamable HTTP for robust agent-computer interaction, contrasting with generic HTTP or RPC clients.
Common errors
-
TypeError: AcpHttpClient is not a constructor
cause Attempting to import `AcpHttpClient` using CommonJS `require` syntax or an incorrect named import.fixEnsure you are using `import { AcpHttpClient } from 'acp-http-client';` for modern JavaScript/TypeScript environments. If forced to use CommonJS, ensure your build tool correctly transpiles ESM imports or look for a specific CJS build if available (though unlikely for this library). -
Error: RPC Method '...' not found
cause The agent being communicated with does not expose the requested RPC method, likely due to a version mismatch between the client and the agent, or a misconfigured agent.fixVerify that the `sandbox-agent` running matches the expected version by the `acp-http-client` library. Check the agent's logs for available RPC methods or ensure your agent's configuration properly registers the required capabilities. -
ECONNREFUSED connect ECONNREFUSED ::1:8080
cause The `acp-http-client` could not establish a connection to the configured agent endpoint, often because the agent is not running or is listening on a different address/port.fixEnsure the `sandbox-agent` is running and accessible at the `baseUrl` provided during `AcpHttpClient` initialization (e.g., `http://localhost:8080`). Check firewall rules and the agent's actual listening address and port.
Warnings
- breaking The install script URL for the underlying sandbox agent changed between v0.3.x and v0.4.x. While this client library primarily interfaces with a running agent, changes in the agent's installation and version compatibility might require updates to your agent deployment strategy.
- gotcha The library is under active development, with frequent release candidates (e.g., 0.5.0-rc.X) introducing new features like 'Agent Computer providers' and 'desktop computer-use APIs.' These features may involve new RPC methods or changes to existing ones, potentially requiring updates to your client-side API interfaces.
- breaking Error handling for RPC calls has been improved to surface agent `stderr` in RPC errors, and a `defaultCwd` parameter was added. This change might affect how you parse or react to RPC errors from the agent and how you configure command execution.
Install
-
npm install acp-http-client -
yarn add acp-http-client -
pnpm add acp-http-client
Imports
- AcpHttpClient
const AcpHttpClient = require('acp-http-client').AcpHttpClient;import { AcpHttpClient } from 'acp-http-client'; - AcpRpcError
import { AcpRpcError } from 'acp-http-client'; - AcpClientConfig
import type { AcpClientConfig } from 'acp-http-client';
Quickstart
import { AcpHttpClient } from 'acp-http-client';
interface AgentApi {
desktop: {
getScreenResolution(): Promise<{ width: number; height: number }>;
click(x: number, y: number): Promise<void>;
};
fileSystem: {
readFile(path: string): Promise<string>;
};
}
async function runAgentTask() {
const agentEndpoint = process.env.ACP_AGENT_ENDPOINT ?? 'http://localhost:8080';
const client = new AcpHttpClient<AgentApi>({
baseUrl: agentEndpoint,
// Optional: Add authentication headers if your agent requires it
headers: {
'Authorization': `Bearer ${process.env.ACP_AGENT_TOKEN ?? ''}`
}
});
try {
console.log('Connecting to ACP agent at:', agentEndpoint);
const resolution = await client.call('desktop.getScreenResolution');
console.log('Agent screen resolution:', resolution);
// Example: Click at the center of the screen
await client.call('desktop.click', resolution.width / 2, resolution.height / 2);
console.log('Successfully simulated a click.');
const fileContent = await client.call('fileSystem.readFile', '/etc/hostname');
console.log('Hostname file content:', fileContent.trim());
} catch (error) {
if (error instanceof AcpRpcError) {
console.error(`RPC Error (${error.code}): ${error.message}`);
} else {
console.error('An unexpected error occurred:', error);
}
process.exit(1);
}
}
runAgentTask();