> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/agentclientprotocol/typescript-sdk/llms.txt
> Use this file to discover all available pages before exploring further.

# Building Agents

> Learn how to build ACP-compliant agents using the TypeScript SDK

## What is an Agent?

In the Agent-Client Protocol (ACP), an **agent** is a program that uses generative AI to autonomously perform tasks like modifying code, answering questions, and executing operations on behalf of users. Agents communicate with clients (typically code editors or IDEs) through a standardized protocol.

## Agent Responsibilities

An ACP-compliant agent is responsible for:

* **Session Management**: Creating and maintaining conversation sessions with independent contexts and history
* **Prompt Processing**: Receiving user prompts, processing them with language models, and returning responses
* **Tool Execution**: Executing tool calls and reporting results back to the client
* **Permission Handling**: Requesting user permission before performing sensitive operations
* **Real-time Updates**: Streaming progress updates to the client during prompt processing
* **State Management**: Tracking session state and handling cancellation requests

## Architecture Overview

The ACP TypeScript SDK provides two main components for building agents:

<Steps>
  <Step title="AgentSideConnection">
    The connection class that handles communication with clients over a bidirectional stream. It provides methods for sending session updates, requesting permissions, and accessing client capabilities.
  </Step>

  <Step title="Agent Interface">
    The interface you implement to define your agent's behavior. It includes methods for initialization, session management, prompt processing, and cancellation handling.
  </Step>
</Steps>

```typescript theme={null}
import * as acp from "@agentprotocol/acp";

class MyAgent implements acp.Agent {
  private connection: acp.AgentSideConnection;

  constructor(connection: acp.AgentSideConnection) {
    this.connection = connection;
  }

  async initialize(params: acp.InitializeRequest): Promise<acp.InitializeResponse> {
    return {
      protocolVersion: acp.PROTOCOL_VERSION,
      agentCapabilities: {
        loadSession: false,
      },
    };
  }

  async newSession(params: acp.NewSessionRequest): Promise<acp.NewSessionResponse> {
    const sessionId = crypto.randomUUID();
    return { sessionId };
  }

  async authenticate(params: acp.AuthenticateRequest): Promise<void> {
    // Implement authentication if needed
  }

  async prompt(params: acp.PromptRequest): Promise<acp.PromptResponse> {
    // Process the user's prompt
    return { stopReason: "end_turn" };
  }

  async cancel(params: acp.CancelNotification): Promise<void> {
    // Handle cancellation
  }
}

// Create the connection
const stream = acp.ndJsonStream(input, output);
new acp.AgentSideConnection((conn) => new MyAgent(conn), stream);
```

## Example Agent

For a complete working example, see the [example agent implementation](https://github.com/agentclientprotocol/typescript-sdk/blob/main/src/examples/agent.ts) in the TypeScript SDK repository.

The example demonstrates:

* Session management
* Sending message chunks
* Tool call lifecycle
* Permission requests
* Cancellation handling

## Next Steps

<CardGroup cols={2}>
  <Card title="AgentSideConnection" icon="plug" href="/agents/agent-side-connection">
    Learn about the connection class and its methods
  </Card>

  <Card title="Agent Interface" icon="code" href="/agents/implementing-agent-interface">
    Implement the required Agent interface methods
  </Card>

  <Card title="Handling Prompts" icon="message" href="/agents/handling-prompts">
    Process user prompts and send updates
  </Card>

  <Card title="Session Management" icon="list" href="/agents/session-management">
    Create and manage conversation sessions
  </Card>
</CardGroup>
