> ## 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.

# createRuntimeAgentHarnessPorts()

> **createRuntimeAgentHarnessPorts**\<`State`, `E`>(`agent`, `options?`): [`AgentHarnessPorts`](/docs/agent-sdk/harness-sdk/ports)\<`State`>

Adapt an actual Agent through its runtime-owned symbol seam.

The function never reflects over protected fields and never adds a
string-named method to the Agent instance. All calls remain in-process.

**Type Parameters**

| Type Parameter | Default type |
| - | - |
|  `State` *extends* `Record`\<`string`, `unknown`> | - |
|  `E` *extends* `Env` | `Env` |

**Parameters**

| Parameter | Type |
| - | - |
| `agent` | `object` |
| `options?` | [`RuntimeAgentHarnessPortsOptions`](/docs/agent-sdk/harness-sdk/adapters/runtime#runtimeagentharnessportsoptions)\<`E`> |

**Returns**
[`AgentHarnessPorts`](/docs/agent-sdk/harness-sdk/ports)\<`State`>

## On the Agent Runtime

`getAgentHarnessHost(agent)`, from `@telnyx/edge-runtime/internal`, hands the harness the protected members of the [`Agent`](/docs/agent-sdk/runtime-sdk) class. The harness therefore works on the same stores as the class's own methods.

```ts theme={null}
// runtime-adapter.ts
import { getAgentHarnessHost, getAgentHarnessAuthorizationProvider } from "@telnyx/edge-runtime/internal";
import { AGENT_HARNESS_PORTS_VERSION } from "./ports.js";
// …
export function createRuntimeAgentHarnessPorts(agent, options = {}) {
  const host = getAgentHarnessHost(agent);
  const authorization = getAgentHarnessAuthorizationProvider(agent);
  const environment = host.selectEnvironment(options.environmentKeys ?? []);
  // … messages, state, events and tasks
  const ports = {
    version: AGENT_HARNESS_PORTS_VERSION,
    identity: Object.freeze({ id: host.id }),
    activation: activationFor(agent),
    clock: Object.freeze({ now: () => host.now() }),
    ...(authorization === undefined ? {} : { authorization }),
    messages,
    state,
    events,
    tasks,
    sql: Object.freeze({
      exec(query, ...bindings) {
        return host.sql.exec(query, ...bindings);
      },
      transactionSync(fn) {
        return host.transactionSync(fn);
      },
    }),
    environment,
  };
  return Object.freeze(ports);
}
```

| Port | Built from |
| - | - |
| [`messages`](/docs/agent-sdk/harness-sdk/ports/messages) | [`this.messages`](/docs/agent-sdk/interface/messages) |
| [`state`](/docs/agent-sdk/harness-sdk/ports/state) | [`getState()`](/docs/agent-sdk/interface/getState), [`setState()`](/docs/agent-sdk/interface/setState) and [`replaceState()`](/docs/agent-sdk/interface/replaceState) |
| [`events`](/docs/agent-sdk/harness-sdk/ports/events) | [`this.events`](/docs/agent-sdk/interface/events) |
| [`tasks`](/docs/agent-sdk/harness-sdk/ports/tasks) | [`queue()`](/docs/agent-sdk/interface/queue), [`schedule()`](/docs/agent-sdk/interface/schedule), [`every()`](/docs/agent-sdk/interface/every), [`cancelSchedule()`](/docs/agent-sdk/interface/cancelSchedule) and [`listSchedules()`](/docs/agent-sdk/interface/listSchedules). The harness's tasks name no method of the class, so they reach [`onTask()`](/docs/agent-sdk/interface/onTask). |
| [`sql`](/docs/agent-sdk/harness-sdk/ports/sql) | The instance's own SQLite database, [`this.ctx.storage.sql`](/docs/agent-sdk/interface/ctx), and `this.ctx.storage.transactionSync()` |
| [`identity`](/docs/agent-sdk/harness-sdk/ports/identity) | The instance's id, [`this.ctx.id`](/docs/agent-sdk/interface/ctx) |
| [`clock`](/docs/agent-sdk/harness-sdk/ports/clock) | [`now()`](/docs/agent-sdk/interface/now) |
| [`environment`](/docs/agent-sdk/harness-sdk/ports/environment) | [`this.env`](/docs/agent-sdk/interface/env), restricted to the `environmentKeys` option |
| [`activation`](/docs/agent-sdk/harness-sdk/ports/activation) | One frozen token per `Agent` object. The Agent Runtime constructs a new object on every activation, through the [`constructor()`](/docs/agent-sdk/interface/constructor). |
| [`authorization`](/docs/agent-sdk/harness-sdk/ports/authorization) | No public `Agent` member. Omitted unless a provider is registered through `@telnyx/edge-runtime/internal`. |
| [`version`](/docs/agent-sdk/harness-sdk/ports/version) | The constant `AGENT_HARNESS_PORTS_VERSION` |

## RuntimeAgentHarnessPortsOptions

Trusted construction options for selecting environment capabilities.

**Type Parameters**

| Type Parameter |
| - |
|  `E` *extends* `Env` |

**Properties**
**environmentKeys?**

> `optional` **environmentKeys?**: readonly (keyof `E` & `string`)\[]

Only these bindings cross into the portable ports object.
