# AgentGateway

**Kind:** Class

**Source:** [`atloria-monorepo/apps/api/src/agent/agent.gateway.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/apps/api/src/agent/agent.gateway.ts#L33)

**Implements:** `OnGatewayConnection`, `OnGatewayDisconnect`

## Methods

| Method | Signature | Returns |
|---|---|---|
| `handleConnection` | `handleConnection(client: Socket)` | `void` |
| `handleDisconnect` | `handleDisconnect(client: Socket)` | `void` |
| `handleStart` | `handleStart(client: Socket, payload: AgentStartPayload)` | `Promise<void>` |
| `handleSend` | `handleSend(client: Socket, payload: AgentSendPayload)` | `Promise<void>` |
| `handleInject` | `handleInject(client: Socket, payload: AgentInjectPayload)` | `void` |
| `handleCancel` | `handleCancel(client: Socket)` | `void` |
| `handleEnd` | `handleEnd(client: Socket)` | `void` |
| `handleGetTodo` | `handleGetTodo(client: Socket)` | `void` |
| `handleVerboseToggle` | `handleVerboseToggle(client: Socket, payload: { enabled?: boolean })` | `void` |
| `handleStatus` | `handleStatus(client: Socket)` | `void` |

## Properties

| Property | Type |
|---|---|
| `server` | `Server` |

## Where it refuses work

- `AgentGateway` stops the work with an early return when `!managed`, in 2 places.
- `AgentGateway` stops the work with an early return when `!err`.
- `AgentGateway` stops the work with an early return when `err.constructor?.name === 'ModelBehaviorError'`.
- `AgentGateway` stops the work with an early return when `typeof err.message === 'string' && err.message.includes('Model did not produce a final re…`.

## When something fails

- `AgentGateway` handles failure in 3 places: it logs it and continues in all 3.

## Referenced By

- `AgentModule` (MODULE_PROVIDES)
- `AgentModule` (MODULE_EXPORTS)
