Overview
This example demonstrates how to build a functional ACP Client using the TypeScript SDK. The client spawns an agent as a subprocess, establishes a connection, manages sessions, and handles user interactions including permission requests.What This Example Demonstrates
Agent Process Management
Spawning and communicating with an agent subprocess
Connection Lifecycle
Initializing connections and negotiating capabilities
Permission Handling
Prompting users for approval on sensitive operations
Session Updates
Receiving and displaying real-time agent updates
Complete Code
Hereβs the full implementation fromsrc/examples/client.ts:
Code Walkthrough
Implement the Client Interface
Create a class that implements the
acp.Client interface with all required methods:Spawn the Agent Process
Launch the agent as a subprocess:
We use
npx tsx to run TypeScript files directly. Adjust this based on your agentβs runtime requirements.Running the Example
Prerequisites
Ensure you have the SDK installed:Run the Complete Example
- Spawn the example agent
- Initialize the connection
- Create a session
- Send a test prompt
- Display the agentβs response
- Handle any permission requests
Expected Output
Key Concepts
Process Management
The client is responsible for:- Spawning the agent process
- Managing stdio streams
- Handling process lifecycle
- Cleaning up on exit
Bidirectional Communication
The client and agent communicate through:- Client β Agent: Requests (initialize, newSession, prompt)
- Agent β Client: Notifications (sessionUpdate) and requests (requestPermission)
Capability Negotiation
During initialization, the client declares its capabilities:Permission Model
The client controls what the agent can do:- Auto-approved: Read operations, low-risk actions
- User approval: File modifications, deletions, sensitive operations
- Blocked: Operations not supported by the client
Session Lifecycle
- Initialize: Establish connection and exchange capabilities
- New Session: Create isolated conversation context
- Prompt: Send user requests and receive responses
- Updates: Handle real-time agent notifications
- Cleanup: Close session and terminate agent
Platform Considerations
This example handles Windows compatibility by detecting the platform and using the appropriate npx command:
Next Steps
Simple Agent Example
Build an agent that works with this client
API Reference
Explore the full ClientSideConnection API
Production Examples
See how production clients integrate ACP
Client Capabilities
Learn about all available client capabilities