ACP HTTP Client

0.4.2 · active · verified Wed Apr 22

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the AcpHttpClient, define an agent's API interface, and make a basic JSON-RPC call to interact with a sandboxed agent's desktop and file system APIs.

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();

view raw JSON →