This example builds an Agent. If you want to build a Client instead, see the Building Clients guide.
Prerequisites
Before starting, make sure you have:- Node.js 18+ installed
- The ACP SDK and Zod installed (see Installation)
- A TypeScript project set up
Build a Minimal Agent
Import the SDK
Create a new file The SDK provides all core types and classes, while Node.js streams enable stdio communication.
agent.ts and import the necessary modules:agent.ts
Implement the Agent interface
Create a class that implements the Key methods explained:
Agent interface with the required methods:agent.ts
initialize(): Establishes the connection and declares agent capabilitiesnewSession(): Creates a new conversation session with a unique IDauthenticate(): Handles authentication (empty for this example)prompt(): Processes user prompts and sends responses viasessionUpdate()cancel(): Handles cancellation requests from the client
Create the connection
Set up stdio streams and create an The
AgentSideConnection:agent.ts
AgentSideConnection automatically:- Routes incoming requests to your agent’s methods
- Validates all messages using Zod schemas
- Handles JSON-RPC 2.0 protocol details
Run your agent
Execute your agent using Your agent is now listening on stdin for ACP messages from a client!
tsx or compile with tsc:Test with a client
You can test your agent by:
- Using an ACP-compatible client like Zed
- Running the example client from the SDK (see Building Clients)
- Sending JSON-RPC messages manually via stdin
Complete Example
Here’s the full minimal agent code:agent.ts
Understanding the Flow
Connection Initialization
The client sends an
initialize request. Your agent responds with its protocol version and capabilities.Session Creation
The client calls
newSession to create a conversation context. Your agent generates a unique session ID.Next Steps
Now that you have a working agent, explore more advanced features:Building Agents
Learn about tool calls, permissions, and advanced agent patterns
Building Clients
Build the client side to connect to your agent
API Reference
Explore the full SDK API documentation
Protocol Docs
Deep dive into the ACP protocol specification