---
title: Agent adapters API
description: Generated public TypeScript reference for relkit/agent-adapters.
search:
  exclude: true
sidebar:
  icon: braces
---

{/* Generated by apps/docs/scripts/generate.ts. Do not edit. */}

For configuration and examples, read [ai](/docs/modules/ai), [tools](/docs/modules/ai/tools), [function tools](/docs/modules/ai/function-tools).

## Public imports

- `relkit/agent-adapters` — 40 exports

## All exported APIs

Names link to their complete contracts. Re-exports share their original contract; legacy exports keep their separate identity. Examples link to the API's inline sample, a maintained repository usage, or the shared module walkthrough.

| API                                                                                           | Kind  | Import from             | Example                                                                                                                             |
| --------------------------------------------------------------------------------------------- | ----- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| [AgentAccessCheck](/docs/api/agent-adapters#agentaccesscheck-type-alias)                      | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentAccessDecision](/docs/api/agent-adapters#agentaccessdecision-type-alias)                | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentAccessRequest](/docs/api/agent-adapters#agentaccessrequest-interface)                   | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentAdapterAgent](/docs/api/agent-adapters#agentadapteragent-interface)                     | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentAdapterContext](/docs/api/agent-adapters#agentadaptercontext-interface)                 | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentAdapterDefinitionInput](/docs/api/agent-adapters#agentadapterdefinitioninput-interface) | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentAdapterError](/docs/api/agent-adapters#agentadaptererror-class)                         | Value | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentAdapterExecution](/docs/api/agent-adapters#agentadapterexecution-interface)             | Type  | `relkit/agent-adapters` | [Source example](https://github.com/rel-kit/relkit/blob/main/tests/types/agent-adapters.ts#L36)                                     |
| [AgentAdapterFrame](/docs/api/agent-adapters#agentadapterframe-type-alias)                    | Type  | `relkit/agent-adapters` | [Source example](https://github.com/rel-kit/relkit/blob/main/packages/relkit/tests/runtime-hono/agent-protocol-mapping.test.ts#L22) |
| [AgentAdapterRuntime](/docs/api/agent-adapters#agentadapterruntime-interface)                 | Type  | `relkit/agent-adapters` | [Source example](https://github.com/rel-kit/relkit/blob/main/tests/types/agent-adapters.ts#L34)                                     |
| [AgentLoopOptions](/docs/api/agent-adapters#agentloopoptions)                                 | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentModelResolver](/docs/api/agent-adapters#agentmodelresolver-interface)                   | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentModelTurn](/docs/api/agent-adapters#agentmodelturn-interface)                           | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentModelTurnPart](/docs/api/agent-adapters#agentmodelturnpart-type-alias)                  | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentModelTurnRequest](/docs/api/agent-adapters#agentmodelturnrequest-interface)             | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentResumeRequest](/docs/api/agent-adapters#agentresumerequest-interface)                   | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentRunRequest](/docs/api/agent-adapters#agentrunrequest-interface)                         | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentRunResult](/docs/api/agent-adapters#agentrunresult-type-alias)                          | Type  | `relkit/agent-adapters` | [Source example](https://github.com/rel-kit/relkit/blob/main/tests/types/agent-adapters.ts#L48)                                     |
| [AgentRuntimeAdapter](/docs/api/agent-adapters#agentruntimeadapter-interface)                 | Type  | `relkit/agent-adapters` | [Source example](https://github.com/rel-kit/relkit/blob/main/tests/types/agent-adapters.ts#L109)                                    |
| [AgentRuntimeAdapterAny](/docs/api/agent-adapters#agentruntimeadapterany-type-alias)          | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentRuntimeNativeFields](/docs/api/agent-adapters#agentruntimenativefields-type-alias)      | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentRuntimeReference](/docs/api/agent-adapters#agentruntimereference-interface)             | Type  | `relkit/agent-adapters` | [Source example](https://github.com/rel-kit/relkit/blob/main/tests/types/agent-adapters.ts#L30)                                     |
| [AgentRuntimeStateKey](/docs/api/agent-adapters#agentruntimestatekey-type-alias)              | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentStateHooks](/docs/api/agent-adapters#agentstatehooks-interface)                         | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentThreadMessage](/docs/api/agent-adapters#agentthreadmessage-type-alias)                  | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentThreadState](/docs/api/agent-adapters#agentthreadstate-interface)                       | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentToolBridge](/docs/api/agent-adapters#agenttoolbridge-interface)                         | Type  | `relkit/agent-adapters` | [Source example](https://github.com/rel-kit/relkit/blob/main/tests/types/agent-adapters.ts#L35)                                     |
| [AgentToolBridgeOptions](/docs/api/agent-adapters#agenttoolbridgeoptions)                     | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentToolCall](/docs/api/agent-adapters#agenttoolcall-interface)                             | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentToolDefinition](/docs/api/agent-adapters#agenttooldefinition-interface)                 | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentToolOutcome](/docs/api/agent-adapters#agenttooloutcome-type-alias)                      | Type  | `relkit/agent-adapters` | [Source example](https://github.com/rel-kit/relkit/blob/main/tests/types/agent-adapters.ts#L57)                                     |
| [AgentTraceHooks](/docs/api/agent-adapters#agenttracehooks-interface)                         | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [AgentTraceSpan](/docs/api/agent-adapters#agenttracespan-type-alias)                          | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [agUiEvents](/docs/api/agent-adapters#aguievents)                                             | Value | `relkit/agent-adapters` | [API example](/docs/api/agent-adapters#aguievents)                                                                                  |
| [createAgentAdapterRuntime](/docs/api/agent-adapters#createagentadapterruntime)               | Value | `relkit/agent-adapters` | [API example](/docs/api/agent-adapters#createagentadapterruntime)                                                                   |
| [createAgentToolBridge](/docs/api/agent-adapters#createagenttoolbridge)                       | Value | `relkit/agent-adapters` | [API example](/docs/api/agent-adapters#createagenttoolbridge)                                                                       |
| [defineAgentRuntime](/docs/api/agent-adapters#defineagentruntime)                             | Value | `relkit/agent-adapters` | [API example](/docs/api/agent-adapters#defineagentruntime)                                                                          |
| [DefineAgentRuntimeOptions](/docs/api/agent-adapters#defineagentruntimeoptions-interface)     | Type  | `relkit/agent-adapters` | [Module example](/docs/modules/ai)                                                                                                  |
| [modelToolName](/docs/api/agent-adapters#modeltoolname)                                       | Value | `relkit/agent-adapters` | [API example](/docs/api/agent-adapters#modeltoolname)                                                                               |
| [ResolvedAgentModel](/docs/api/agent-adapters#resolvedagentmodel-interface)                   | Type  | `relkit/agent-adapters` | [Source example](https://github.com/rel-kit/relkit/blob/main/integrations/packages/langchain/tests/model-profile.test.ts#L41)       |

## `adapter-bridge.ts`

Bridges model tool calls to the common engine. Approvals, the engine's access check and tool
failures are handled here, so every adapter calls tools the same way.

### createAgentToolBridge

Creates the tool bridge for one agent invocation.

**Example**

```ts
const bridge = createAgentToolBridge({ agentId, invocationId, tools, engine });
```

**Signature**

```ts
declare const createAgentToolBridge: (options: AgentToolBridgeOptions) => AgentToolBridge;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-bridge.ts#L35)

### modelToolName

Derives the model-facing name of a tool; dots and other separators become underscores.

**Example**

```ts
modelToolName("orders.lookup"); // "orders_lookup"
```

**Signature**

```ts
declare const modelToolName: (toolId: string) => string;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-bridge.ts#L25)

## `adapter-bridge.types.ts`

Inputs of the RelKit-owned tool bridge an adapter run calls for every model tool call.

### AgentToolBridgeOptions (interface)

Options for `createAgentToolBridge`.

**Signature**

```ts
export interface AgentToolBridgeOptions {
  readonly agentId: string;
  /** Invocation identity copied into approval records. */
  readonly invocationId: string;
  /** Tool descriptors the agent declared, in declaration order. */
  readonly tools: readonly ToolDescriptor<string>[];
  /** Common function engine every tool call runs through. */
  readonly engine: ToolEngine;
  /** Engine access check run before each tool; group 18's access rules plug in here. */
  readonly access?: AgentAccessCheck;
  /** Caller principal forwarded to the access check. */
  readonly principal?: unknown;
  readonly trace?: AgentTraceHooks;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-bridge.types.ts#L6)

## `adapter-events.ts`

Maps neutral adapter frames to AG-UI events. An adapter frame first becomes the journal frames the
server stores for it, and those are encoded with the server's own encoder, so a client of the
generated server receives the events the conformance suite asserts.

### adapterProtocolFrames

Translates one adapter frame into the journal frames the server streams for it.

**Signature**

```ts
declare const adapterProtocolFrames: (frame: AgentAdapterFrame) => Iterable<AgentProtocolFrame>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-events.ts#L15)

### agUiEvents

Translates one adapter frame into ordered AG-UI events, with the encoder the server uses.

**Example**

```ts
[...agUiEvents({ kind: "text", messageId: "m", delta: "hi" })];
```

**Signature**

```ts
declare const agUiEvents: (frame: AgentAdapterFrame) => Iterable<Readonly<Record<string, unknown>>>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-events.ts#L93)

## `adapter-execution.types.ts`

Execution half of the agent adapter interface: stream frames, run results, the context RelKit
hands an adapter, and the run, stream, resume and stop contract.

### AgentAdapterAgent (interface)

Agent fields an adapter reads at execution time.

**Signature**

```ts
export interface AgentAdapterAgent {
  readonly id: string;
  readonly model?: string;
  readonly instructions: unknown;
  readonly output: StandardSchemaV1;
  readonly limits: {
    readonly maxSteps: number;
    readonly maxToolCalls: number;
    readonly timeoutMs: number;
  };
  readonly runtime: AgentRuntimeReference;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-execution.types.ts#L63)

### AgentAdapterContext (interface)

Everything RelKit hands an adapter for one agent.

**Signature**

```ts
export interface AgentAdapterContext {
  readonly agent: AgentAdapterAgent;
  readonly models: AgentModelResolver;
  readonly tools: AgentToolBridge;
  readonly state: AgentStateHooks;
  readonly trace?: AgentTraceHooks;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-execution.types.ts#L54)

### AgentAdapterExecution (interface)

Execution contract every adapter runtime implements.

**Signature**

```ts
export interface AgentAdapterExecution {
  readonly run: (request: AgentRunRequest) => Promise<AgentRunResult>;
  readonly stream: (request: AgentRunRequest) => AsyncIterable<AgentAdapterFrame>;
  readonly resume: (request: AgentResumeRequest) => Promise<AgentRunResult>;
  readonly stop: (runId: string) => Promise<void>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-execution.types.ts#L92)

### AgentAdapterFrame (type alias)

Neutral stream frames an adapter run emits; RelKit maps them to AG-UI events.

**Signature**

```ts
type AgentAdapterFrame =
  | { readonly kind: "run-started"; readonly threadId: string; readonly runId: string }
  | {
      readonly kind: "text";
      readonly messageId: string;
      readonly delta: string;
      /**
       * Where this frame sits in a streamed message: `start` opens it, `delta` continues it and
       * `end` closes it. Absent, the frame is a whole message.
       */
      readonly phase?: "start" | "delta" | "end";
    }
  | { readonly kind: "tool-call"; readonly call: AgentToolCall; readonly toolId: string }
  | { readonly kind: "tool-result"; readonly outcome: AgentToolOutcome; readonly toolId: string }
  | { readonly kind: "approval"; readonly approvals: readonly PendingApproval[] }
  | {
      readonly kind: "run-finished";
      readonly threadId: string;
      readonly runId: string;
      readonly result: AgentRunResult;
    }
  | { readonly kind: "run-error"; readonly code: string; readonly message: string };
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-execution.types.ts#L19)

### AgentAdapterRuntime (interface)

Runtime half of an adapter, exported from the adapter package's runtime entry.

**Signature**

```ts
export interface AgentAdapterRuntime<AdapterId extends string = string> {
  readonly adapterId: AdapterId;
  readonly protocolVersion: 1;
  /** Creates the run, stream, resume and stop contract for one agent. */
  readonly execution: (context: AgentAdapterContext) => AgentAdapterExecution;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-execution.types.ts#L121)

### AgentModelTurn (interface)

What a model returned in one turn.

**Signature**

```ts
export interface AgentModelTurn {
  readonly text: string;
  readonly toolCalls: readonly AgentToolCall[];
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-execution.types.ts#L108)

### AgentModelTurnPart (type alias)

One piece of a streamed model turn: text as the model produces it, or a finished tool call. The
turn's text is the concatenation of its text pieces.

**Signature**

```ts
type AgentModelTurnPart =
  | { readonly kind: "text"; readonly delta: string }
  | { readonly kind: "tool-call"; readonly call: AgentToolCall };
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-execution.types.ts#L116)

### AgentModelTurnRequest (interface)

One model turn: the only SDK-specific step of an agent loop.

**Signature**

```ts
export interface AgentModelTurnRequest {
  readonly model: ResolvedAgentModel;
  readonly messages: readonly AgentThreadMessage[];
  readonly tools: readonly AgentToolDefinition[];
  readonly signal: AbortSignal;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-execution.types.ts#L100)

### AgentResumeRequest (interface)

Continuation of an interrupted run with approval decisions.

**Signature**

```ts
export interface AgentResumeRequest {
  readonly threadId: string;
  readonly decisions: Readonly<Record<string, "approved" | "denied">>;
  readonly signal?: AbortSignal;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-execution.types.ts#L85)

### AgentRunRequest (interface)

Start of a run.

**Signature**

```ts
export interface AgentRunRequest {
  readonly input: unknown;
  readonly threadId: string;
  readonly runId?: string;
  readonly signal?: AbortSignal;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-execution.types.ts#L77)

### AgentRunResult (type alias)

Result of a run or resume.

**Signature**

```ts
type AgentRunResult =
  | { readonly status: "completed"; readonly threadId: string; readonly output: unknown }
  | {
      readonly status: "interrupted";
      readonly threadId: string;
      readonly runId: string;
      readonly approvals: readonly PendingApproval[];
    }
  | { readonly status: "stopped"; readonly threadId: string; readonly runId: string };
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-execution.types.ts#L43)

## `adapter-identity.ts`

Recognizes adapter values and copies their identity onto descriptors; internal to RelKit.

### agentRuntimeReference

Copies the serializable adapter identity stored on descriptors and graph nodes.

**Example**

```ts
agentRuntimeReference(runtime).adapterId;
```

**Signature**

```ts
declare const agentRuntimeReference: (runtime: AgentRuntimeAdapter) => AgentRuntimeReference;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-identity.ts#L28)

### isAgentRuntimeAdapter

Recognizes an agent adapter value.

**Example**

```ts
isAgentRuntimeAdapter(runtime);
```

**Signature**

```ts
declare const isAgentRuntimeAdapter: (value: unknown) => value is AgentRuntimeAdapter;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-identity.ts#L10)

## `adapter-loop-support.ts`

Helpers of the shared agent loop: instructions, input text, the output tool and output checks.

### AgentAdapterError (class)

Error carrying a stable code from an adapter run.

**Signature**

```ts
declare class AgentAdapterError {
  constructor(code: string, message: string);
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop-support.ts#L10)

### code (property)

**Signature**

```ts
readonly code: string
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop-support.ts#L11)

### OUTPUT_TOOL_NAME

Model-facing name of the tool a model calls to return the agent's final output.

**Signature**

```ts
declare const OUTPUT_TOOL_NAME: "relkit_output";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop-support.ts#L7)

### inputText

Renders run input as a user message.

**Signature**

```ts
declare const inputText: (input: unknown) => string;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop-support.ts#L40)

### instructionText

Renders authored instructions as one system message.

**Signature**

```ts
declare const instructionText: (instructions: unknown) => string;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop-support.ts#L24)

### outputTool

Builds the output tool definition from the agent's output schema.

**Signature**

```ts
declare const outputTool: (output: StandardSchemaV1) => AgentToolDefinition;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop-support.ts#L49)

### textCandidates

Parses model text as JSON when possible.

**Signature**

```ts
declare const textCandidates: (text: string) => readonly unknown[];
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop-support.ts#L89)

### validOutput

Validates a final output, accepting raw text, JSON text or the output tool's `value`.

**Throws**

AgentAdapterError with `RELKIT_AGENT_OUTPUT_VALIDATION`.

**Signature**

```ts
declare const validOutput: (
  output: StandardSchemaV1,
  candidates: readonly unknown[],
) => Promise<unknown>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop-support.ts#L71)

## `adapter-loop-turns.ts`

Turn and tool-call steps of the shared agent loop: model turns, bridged tool calls, approval
interruption, output checks and thread saves.

### begin

Starts a run: loads the thread and appends the user input.

**Signature**

```ts
declare const begin: (
  options: AgentLoopOptions<string>,
  loop: Loop,
  input: unknown,
) => AsyncGenerator<AgentAdapterFrame, AgentRunResult, any>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop-turns.ts#L24)

### resumed

Continues pending tool calls with approval decisions, then further turns.

**Signature**

```ts
declare const resumed: (
  options: AgentLoopOptions<string>,
  loop: Loop,
  calls: readonly AgentToolCall[],
  decisions: ReadonlyMap<string, ApprovalRecord>,
) => AsyncGenerator<AgentAdapterFrame, AgentRunResult>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop-turns.ts#L193)

## `adapter-loop.ts`

Shared agent loop behind every first-party adapter. RelKit owns threads, approvals, tool calls,
limits, stop, traces and stream frames; the adapter supplies one model turn.

### AgentAdapterError

**Signature**

```ts
declare const AgentAdapterError: typeof AgentAdapterError;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop.ts#L20)

### createAgentAdapterRuntime

Builds an adapter runtime from one SDK-specific model turn.

**Example**

```ts
createAgentAdapterRuntime({ adapterId: "echo", turn: async () => ({ text: "hi", toolCalls: [] }) });
```

**Signature**

```ts
declare const createAgentAdapterRuntime: <const AdapterId extends string>(
  options: AgentLoopOptions<AdapterId>,
) => AgentAdapterRuntime<AdapterId>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop.ts#L27)

## `adapter-loop.types.ts`

Inputs of the shared agent loop that adapters build on; only the model turn is SDK-specific.

### AgentAdapterFailure (interface)

Error raised by a run that cannot finish.

**Signature**

```ts
export interface AgentAdapterFailure {
  readonly code: string;
  readonly message: string;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop.types.ts#L26)

### AgentLoopOptions (interface)

Options for `createAgentAdapterRuntime`.

**Signature**

```ts
export interface AgentLoopOptions<AdapterId extends string> {
  readonly adapterId: AdapterId;
  /**
   * Runs one model turn with the adapter's SDK.
   * @param request - Resolved model, thread messages, bridged tool definitions and cancellation.
   * @returns Text and tool calls the model produced, or the turn's parts as the model produces
   * them, so the loop streams its text.
   */
  readonly turn: (
    request: AgentModelTurnRequest,
  ) => Promise<AgentModelTurn> | AsyncIterable<AgentModelTurnPart>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop.types.ts#L12)

### AgentLoopState (interface)

Mutable state of one run inside the shared loop.

**Signature**

```ts
export interface AgentLoopState {
  readonly context: AgentAdapterContext;
  readonly threadId: string;
  readonly runId: string;
  readonly signal: AbortSignal;
  readonly model: ResolvedAgentModel;
  messages: AgentThreadMessage[];
  steps: number;
  toolCalls: number;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop.types.ts#L32)

## `adapter.ts`

Builds agent adapter values. Adapter packages call `defineAgentRuntime` from their authoring
entry, so declaring an agent never loads an execution SDK.

### "./adapter.types.js" (namespace export)

Re-exports all named exports from the "./adapter.types.js" module.

**Signature**

```ts
export * from "./adapter.types.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.ts#L7)

### AgentAdapterError

**Signature**

```ts
declare const AgentAdapterError: typeof AgentAdapterError;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.ts#L10)

### AgentLoopOptions

Options for `createAgentAdapterRuntime`.

**Signature**

```ts
export interface AgentLoopOptions<AdapterId extends string> {
  readonly adapterId: AdapterId;
  /**
   * Runs one model turn with the adapter's SDK.
   * @param request - Resolved model, thread messages, bridged tool definitions and cancellation.
   * @returns Text and tool calls the model produced, or the turn's parts as the model produces
   * them, so the loop streams its text.
   */
  readonly turn: (
    request: AgentModelTurnRequest,
  ) => Promise<AgentModelTurn> | AsyncIterable<AgentModelTurnPart>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-loop.types.ts#L12)

### AgentToolBridgeOptions

Options for `createAgentToolBridge`.

**Signature**

```ts
export interface AgentToolBridgeOptions {
  readonly agentId: string;
  /** Invocation identity copied into approval records. */
  readonly invocationId: string;
  /** Tool descriptors the agent declared, in declaration order. */
  readonly tools: readonly ToolDescriptor<string>[];
  /** Common function engine every tool call runs through. */
  readonly engine: ToolEngine;
  /** Engine access check run before each tool; group 18's access rules plug in here. */
  readonly access?: AgentAccessCheck;
  /** Caller principal forwarded to the access check. */
  readonly principal?: unknown;
  readonly trace?: AgentTraceHooks;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter-bridge.types.ts#L6)

### DefineAgentRuntimeOptions (interface)

Options an adapter package passes to `defineAgentRuntime`.

**Signature**

```ts
export interface DefineAgentRuntimeOptions<
  AdapterId extends string,
  Options,
  StateKey extends string,
> {
  readonly adapterId: AdapterId;
  readonly integrationId: string;
  readonly options: Options;
  /** Adapter-specific option keys this value uses; they tie the agent to the adapter. */
  readonly nativeOptions?: readonly string[];
  readonly clientStateKeys?: readonly StateKey[];
  readonly extend?: (input: AgentAdapterDefinitionInput) => Readonly<Record<string, unknown>>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.ts#L15)

### agUiEvents

**Signature**

```ts
declare const agUiEvents: (frame: AgentAdapterFrame) => Iterable<Readonly<Record<string, unknown>>>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.ts#L8)

### createAgentAdapterRuntime

**Signature**

```ts
declare const createAgentAdapterRuntime: <const AdapterId extends string>(
  options: AgentLoopOptions<AdapterId>,
) => AgentAdapterRuntime<AdapterId>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.ts#L10)

### createAgentToolBridge

**Signature**

```ts
declare const createAgentToolBridge: (options: AgentToolBridgeOptions) => AgentToolBridge;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.ts#L9)

### defineAgentRuntime

Creates the frozen value an agent's `runtime` field holds.

**Example**

```ts
import { defineAgentRuntime } from "relkit/agent-adapters";

const runtime = defineAgentRuntime({ adapterId: "echo", integrationId: "echo", options: {} });
void runtime;
```

**Signature**

```ts
declare const defineAgentRuntime: <
  const AdapterId extends string,
  Options,
  Native extends object = {},
  const StateKey extends string = never,
>(
  options: DefineAgentRuntimeOptions<AdapterId, Options, StateKey>,
) => AgentRuntimeAdapter<AdapterId, Options, Native, StateKey>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.ts#L41)

### modelToolName

**Signature**

```ts
declare const modelToolName: (toolId: string) => string;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.ts#L9)

## `adapter.types.ts`

Declares the agent adapter interface: the authoring value an agent's `runtime` field holds, and
the execution contract (run, stream, resume, stop) an adapter implements on top of RelKit's tool
bridge, model profiles, state hooks and AG-UI event mapping.

### "./adapter-execution.types.js" (namespace export)

Re-exports all named exports from the "./adapter-execution.types.js" module.

**Signature**

```ts
export * from "./adapter-execution.types.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L200)

### AgentAccessCheck (type alias)

The engine hook the tool bridge calls before every tool execution. Access rules are owned by the
engine; the bridge only calls this check and reports a denial to the model.

**Signature**

```ts
type AgentAccessCheck = (request: AgentAccessRequest) => MaybePromise<AgentAccessDecision>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L127)

### AgentAccessDecision (type alias)

Decision returned by the engine's access check.

**Signature**

```ts
type AgentAccessDecision =
  | { readonly allowed: true }
  | { readonly allowed: false; readonly code: string; readonly message: string };
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L119)

### AgentAccessRequest (interface)

Request passed to the engine's access check before a tool runs.

**Signature**

```ts
export interface AgentAccessRequest {
  readonly source: "agent";
  readonly agentId: string;
  readonly toolId: string;
  readonly functionId: string;
  readonly input: unknown;
  readonly principal?: unknown;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L109)

### AgentAdapterDefinitionInput (interface)

Portable fields every adapter receives when an agent is defined.

**Signature**

```ts
export interface AgentAdapterDefinitionInput {
  readonly id: string;
  /** The authored `defineAgent` options without `runtime`. */
  readonly options: Readonly<Record<string, unknown>>;
  /** The portable descriptor RelKit built before the adapter adds its fields. */
  readonly descriptor: Readonly<Record<string, unknown>>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L23)

### AgentModelResolver (interface)

Resolves the model profile an agent references; adapters never read configuration directly.

**Signature**

```ts
export interface AgentModelResolver {
  /**
   * @param selector - The agent's `model` value, such as `default` or `default:gpt-5`.
   * @returns The bound model for that profile.
   */
  readonly resolve: (selector: string | undefined) => MaybePromise<ResolvedAgentModel>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L81)

### AgentRuntimeAdapter (interface)

Value stored in an agent's `runtime` field. It carries adapter options only and never loads an
SDK: execution lives in the adapter package's runtime entry.

**Signature**

```ts
export interface AgentRuntimeAdapter<
  AdapterId extends string = string,
  Options = unknown,
  Native extends object = {},
  StateKey extends string = never,
> extends AgentRuntimeReference<AdapterId> {
  readonly options: Options;
  /** Client state keys an agent may expose through `client.state`. */
  readonly clientStateKeys: readonly StateKey[];
  /**
   * Adds adapter-owned descriptor fields, validating adapter options against the portable ones.
   * @param input - Agent identity, authored options and the portable descriptor.
   * @returns Fields merged over the portable descriptor.
   */
  readonly extend?: (input: AgentAdapterDefinitionInput) => Readonly<Record<string, unknown>>;
  /** Phantom marker carrying the native descriptor fields; never present at runtime. */
  readonly "~native"?: Native;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L39)

### AgentRuntimeAdapterAny (type alias)

Any agent adapter value.

**Signature**

```ts
type AgentRuntimeAdapterAny = AgentRuntimeAdapter<string, unknown, object, string>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L59)

### AgentRuntimeNativeFields (type alias)

Native descriptor fields an adapter value adds.

**Signature**

```ts
type AgentRuntimeNativeFields<Runtime> =
  Runtime extends AgentRuntimeAdapter<string, unknown, infer Native, string> ? Native : {};
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L62)

### AgentRuntimeReference (interface)

Serializable identity of an agent adapter, copied into descriptors and the graph.

**Signature**

```ts
export interface AgentRuntimeReference<AdapterId extends string = string> {
  readonly kind: "agent-runtime";
  readonly adapterId: AdapterId;
  /** Package integration that registers the adapter's `agent-execution` capability. */
  readonly integrationId: string;
  readonly protocolVersion: 1;
  /** Adapter-specific option keys the agent uses; a non-empty list ties the agent to this adapter. */
  readonly nativeOptions: readonly string[];
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L11)

### AgentRuntimeStateKey (type alias)

Client state keys an adapter value exposes.

**Signature**

```ts
type AgentRuntimeStateKey<Runtime> =
  Runtime extends AgentRuntimeAdapter<string, unknown, object, infer StateKey> ? StateKey : never;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L66)

### AgentStateHooks (interface)

State persistence hooks backed by the application's `agent-state` profile.

**Signature**

```ts
export interface AgentStateHooks {
  readonly load: (threadId: string) => MaybePromise<AgentThreadState | undefined>;
  readonly save: (state: AgentThreadState) => MaybePromise<void>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L184)

### AgentThreadMessage (type alias)

Neutral conversation message stored in a thread.

**Signature**

```ts
type AgentThreadMessage =
  | { readonly role: "system" | "user"; readonly content: string }
  | {
      readonly role: "assistant";
      readonly content: string;
      readonly toolCalls?: readonly AgentToolCall[];
    }
  | {
      readonly role: "tool";
      readonly toolCallId: string;
      readonly name: string;
      readonly content: string;
    };
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L155)

### AgentThreadState (interface)

Durable thread state the adapter loads and saves through state hooks.

**Signature**

```ts
export interface AgentThreadState {
  readonly threadId: string;
  readonly messages: readonly AgentThreadMessage[];
  /** Tool calls waiting for approval decisions, with the calls still to run after them. */
  readonly pending?: {
    readonly runId: string;
    readonly approvals: readonly PendingApproval[];
    readonly calls: readonly AgentToolCall[];
    readonly steps: number;
    readonly toolCalls: number;
  };
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L170)

### AgentToolBridge (interface)

RelKit-owned bridge from model tool calls to the common engine.

**Signature**

```ts
export interface AgentToolBridge {
  readonly definitions: readonly AgentToolDefinition[];
  /**
   * Runs one tool call through access checks, approvals and the engine.
   * @param call - Model tool call.
   * @param options - Recorded approval decision and cancellation.
   */
  readonly call: (
    call: AgentToolCall,
    options?: { readonly approval?: ApprovalRecord; readonly signal?: AbortSignal },
  ) => Promise<AgentToolOutcome>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L141)

### AgentToolCall (interface)

One tool call requested by a model.

**Signature**

```ts
export interface AgentToolCall {
  readonly toolCallId: string;
  /** Model-facing tool name. */
  readonly name: string;
  readonly input: unknown;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L101)

### AgentToolDefinition (interface)

Tool exposed to a model through the bridge.

**Signature**

```ts
export interface AgentToolDefinition {
  readonly id: string;
  /** Model-facing name; dots are replaced so every SDK accepts it. */
  readonly name: string;
  readonly description: string;
  /** JSON Schema of the tool input. */
  readonly inputSchema: Readonly<Record<string, unknown>>;
  readonly requiresApproval: boolean;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L90)

### AgentToolOutcome (type alias)

Outcome of one bridged tool call.

**Signature**

```ts
type AgentToolOutcome =
  | { readonly status: "succeeded"; readonly toolCallId: string; readonly output: unknown }
  | {
      readonly status: "failed" | "denied";
      readonly toolCallId: string;
      readonly code: string;
      readonly message: string;
    }
  | { readonly status: "approval-required"; readonly approval: PendingApproval };
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L130)

### AgentTraceHooks (interface)

Trace hooks; RelKit's observability implements them, tests record them.

**Signature**

```ts
export interface AgentTraceHooks {
  readonly start: (
    span: AgentTraceSpan,
    attributes: Readonly<Record<string, string | number | boolean>>,
  ) => { readonly end: (outcome: "ok" | "error") => void };
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L193)

### AgentTraceSpan (type alias)

Span names an adapter run records.

**Signature**

```ts
type AgentTraceSpan = "agent.run" | "agent.model" | "agent.tool";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L190)

### ResolvedAgentModel (interface)

A model selected from a profile bound in `relkit.config.ts`.

**Signature**

```ts
export interface ResolvedAgentModel {
  /** Stable model identity, such as `openai:gpt-5`. */
  readonly id: string;
  /** Profile the model was resolved from. */
  readonly profile: string;
  /** Adapter-native model value or a provider-qualified model name. */
  readonly model: unknown;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/adapter.types.ts#L70)

## `index.ts`

Labs agent adapter interface: adapter values, the tool bridge, the shared agent loop and AG-UI mapping.

### "./adapter.js" (namespace export)

Re-exports all named exports from the "./adapter.js" module.

**Signature**

```ts
export * from "./adapter.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/index.ts#L2)

## `protocol-events.ts`

Encodes journal frames as AG-UI events: the one mapping the generated server and `agUiEvents` share.
Event types are the string values of `@ag-ui/core`'s `EventType`; this module does not import it,
because every agent loads `relkit/agent-adapters` and `@ag-ui/core` is an optional peer that only
the AG-UI transport needs. `agent-protocol-event-types.test.ts` keeps the two in step.

### agUiFrames

Translate one journal frame into AG-UI protocol events. The generated server encodes its stream
with it, and `agUiEvents` encodes an adapter's frames with it, so both send the same events.

**Signature**

```ts
declare const agUiFrames: (
  frame: AgentProtocolFrame,
) => Iterable<Readonly<Record<string, unknown>>>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/protocol-events.ts#L18)

## `protocol-frame.types.ts`

### AgentProtocolFrame (type alias)

One frame of a run's stream as the server journals it; AG-UI events are encoded from it.

**Signature**

```ts
type AgentProtocolFrame =
  | { readonly kind: "run-started"; readonly threadId: string; readonly runId: string }
  | { readonly kind: "state"; readonly value: unknown }
  | { readonly kind: "text-start"; readonly messageId: string }
  | { readonly kind: "text-delta"; readonly messageId: string; readonly delta: string }
  | { readonly kind: "text-end"; readonly messageId: string }
  | ({
      readonly kind: "progress";
      readonly partId: string;
      readonly value: unknown;
    } & import("../agents/index.js").AgentProgressScope)
  | { readonly kind: "approval"; readonly approvalId: string; readonly value: unknown }
  | {
      readonly kind: "event";
      readonly event: JournalRecord["kind"] | "execution" | "execution-snapshot" | "observation";
      readonly value: unknown;
      readonly eventId?: string;
      readonly recordId?: string;
      readonly runId?: string;
      readonly createdAt?: string;
    }
  | {
      readonly kind: "tool";
      readonly toolCallId: string;
      readonly toolId: string;
      readonly state: import("../agents/index.js").ToolPartState;
      readonly value?: unknown;
      readonly inputStarted?: boolean;
      readonly inputDelta?: string;
    }
  | {
      readonly kind: "terminal";
      readonly threadId: string;
      readonly runId: string;
      readonly status: string;
      readonly text?: string;
      /** Structured output of a run that did not end in text; it takes the place of `text`. */
      readonly output?: unknown;
      readonly code?: string;
      readonly message?: string;
      readonly approvals?: readonly unknown[];
    };
```

[Source](https://github.com/rel-kit/relkit/blob/main/packages/relkit/src/agent-adapters/protocol-frame.types.ts#L4)
