# AutonomousTurnHook

**Kind:** Class

**Source:** [`atloria-monorepo/libs/agent-core/src/autonomous/autonomous-loop.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/libs/agent-core/src/autonomous/autonomous-loop.ts#L612)

TurnHook that drives autonomous agent behavior.

It watches what the agent is doing (via tool calls in input items)
and injects nudges when the agent skips investigation or verification.

Usage:
```typescript
const hook = new AutonomousTurnHook({
  maxTurns: 40,
  qualityGateProvider: async () => [
    { id: 'tests_pass', description: 'All tests pass', passed: false },
  ],
});
```

**Implements:** `TurnHook`

## Methods

| Method | Signature | Returns |
|---|---|---|
| `updateTokenUsage` | `updateTokenUsage(inputTokens: number)` | `void` |
| `getCircleDetector` | `getCircleDetector()` | `CircleDetector | null` |
| `beforeModelCall` | `beforeModelCall(args: TurnHookArgs<TContext>)` | `Promise<{ instructions?: string; input?: AgentInputItem[] }>` |
| `getState` | `getState()` | `Readonly<LoopState>` |
| `getRecentFiles` | `getRecentFiles()` | `readonly string[]` |

## Properties

| Property | Type |
|---|---|
| `onPreCompact` | `(data: { turnNumber: number; tokenCount: number; recentFiles: string[] }) => void` |
| `onPostCompact` | `(data: { turnNumber: number; summaryInjected: boolean }) => void` |

## Where it refuses work

- `AutonomousTurnHook` stops the work with an early return when `nudges.length === 0 && !notesBlock && !windowedInput && !phaseDirective`.

## When something fails

- `AutonomousTurnHook` handles failure in 8 places: it discards it silently in 7, and logs it and continues in 1.
