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

# new AgentSocketServer()

> **new AgentSocketServer**\<`TState`>(`actor`: `object`, `opts`: [`AgentSocketServerOptions`](/docs/agent-sdk/internals/the-socket-server#agentsocketserveroptions)\<`TState`>): `AgentSocketServer`\<`TState`>

Creates the socket server for one actor instance. Construct one per instance, usually as a field of the class, and delegate the class's `webSocket(ws, req)` to [`attach`](/docs/agent-sdk/internals/socket/attach).

```ts theme={null}
import { Agent, type Env } from "@telnyx/edge-runtime";
import { AgentSocketServer, type AgentServerSocket } from "@telnyx/edge-runtime/agent-socket";

interface ConvState extends Record<string, unknown> {
  status: string;
}

export class Conversation extends Agent<Env, ConvState> {
  private desk = new AgentSocketServer<ConvState>(this, {
    getState: () => this.getState(),
    getMessages: () => this.messages.all(),
    authorize: (token) => (token === undefined ? ["read"] : ["read", "rpc"]),
  });

  async webSocket(ws: AgentServerSocket, req: Request): Promise<void> {
    await this.desk.attach(ws, req);
  }
}
```

**Parameters**

| Parameter | Type | Meaning |
| - | - | - |
| `actor` | `object` | The instance whose `@rpc()` methods inbound `call` frames dispatch to, usually `this`. |
| `opts` | [`AgentSocketServerOptions`](/docs/agent-sdk/internals/the-socket-server#agentsocketserveroptions)\<`TState`> | How the server reads state and messages, and how it authorizes a connection. |

**Type Parameters**

| Parameter | Meaning |
| - | - |
| `TState` | The agent's persistent state shape, as snapshotted and broadcast to clients. |
