---
title: "Interface: Agent"
editUrl: true
head: []
template: doc
sidebar:
  hidden: false
  attrs: {}
pagefind: true
draft: false
---

[**Prefactor TypeScript SDK**](../../index.md)

***

[Prefactor TypeScript SDK](../../modules.md) / [@prefactor/openclaw-prefactor-plugin](../index.md) / Agent

# Interface: Agent

Defined in: [packages/openclaw-prefactor-plugin/src/agent.ts:157](https://github.com/prefactordev/typescript-sdk/blob/231423a775642bec119a2db45acf108c6383d05d/packages/openclaw-prefactor-plugin/src/agent.ts#L157)

HTTP client that manages AgentInstance lifecycle and span CRUD against the
Prefactor API. Supports multiple concurrent sessions, each backed by its own
AgentInstance, and automatically retries failed operations via a background
replay queue.

## Param

[AgentConfig](AgentConfig.md) with connection and retry settings.

## Param

Logger instance used for structured diagnostic output.

Key public methods:
- [Agent.createSpan](#createspan) — Creates a span under the given session, registering
  an AgentInstance first if one does not yet exist.
- [Agent.finishSpan](#finishspan) — Marks a span as finished; queues the operation for
  retry on failure.
- [Agent.finishAgentInstance](#finishagentinstance) — Completes the AgentInstance for a session.
- [Agent.flushQueue](#flushqueue) — Replays any queued operations that previously failed.
- [Agent.stop](#stop) — Stops the background flush loop.
- [Agent.emergencyCleanup](#emergencycleanup) — Tears down all sessions and clears the queue.

## Methods

### resolveToolSpanType()

> **resolveToolSpanType**(`toolName`): `string`

Defined in: [packages/openclaw-prefactor-plugin/src/agent.ts:429](https://github.com/prefactordev/typescript-sdk/blob/231423a775642bec119a2db45acf108c6383d05d/packages/openclaw-prefactor-plugin/src/agent.ts#L429)

Resolves a tool name to its span type.
Returns the specific span type for supported tools, or the generic fallback.

#### Parameters

##### toolName

`string`

#### Returns

`string`

***

### stop()

> **stop**(): `void`

Defined in: [packages/openclaw-prefactor-plugin/src/agent.ts:470](https://github.com/prefactordev/typescript-sdk/blob/231423a775642bec119a2db45acf108c6383d05d/packages/openclaw-prefactor-plugin/src/agent.ts#L470)

#### Returns

`void`

***

### emergencyCleanup()

> **emergencyCleanup**(): `Promise`\<`void`\>

Defined in: [packages/openclaw-prefactor-plugin/src/agent.ts:477](https://github.com/prefactordev/typescript-sdk/blob/231423a775642bec119a2db45acf108c6383d05d/packages/openclaw-prefactor-plugin/src/agent.ts#L477)

#### Returns

`Promise`\<`void`\>

***

### finishAgentInstance()

> **finishAgentInstance**(`sessionKey`, `status?`): `Promise`\<`void`\>

Defined in: [packages/openclaw-prefactor-plugin/src/agent.ts:592](https://github.com/prefactordev/typescript-sdk/blob/231423a775642bec119a2db45acf108c6383d05d/packages/openclaw-prefactor-plugin/src/agent.ts#L592)

#### Parameters

##### sessionKey

`string`

##### status?

`"complete"` | `"failed"` | `"cancelled"`

#### Returns

`Promise`\<`void`\>

***

### createSpan()

> **createSpan**(`sessionKey`, `schemaName`, `payload`, `parentSpanId?`): `Promise`\<`string` \| `null`\>

Defined in: [packages/openclaw-prefactor-plugin/src/agent.ts:643](https://github.com/prefactordev/typescript-sdk/blob/231423a775642bec119a2db45acf108c6383d05d/packages/openclaw-prefactor-plugin/src/agent.ts#L643)

#### Parameters

##### sessionKey

`string`

##### schemaName

`string`

##### payload

`Record`\<`string`, `unknown`\>

##### parentSpanId?

`string` | `null`

#### Returns

`Promise`\<`string` \| `null`\>

***

### finishSpan()

> **finishSpan**(`sessionKey`, `spanId`, `status?`, `resultPayload?`): `Promise`\<`void`\>

Defined in: [packages/openclaw-prefactor-plugin/src/agent.ts:735](https://github.com/prefactordev/typescript-sdk/blob/231423a775642bec119a2db45acf108c6383d05d/packages/openclaw-prefactor-plugin/src/agent.ts#L735)

#### Parameters

##### sessionKey

`string`

##### spanId

`string`

##### status?

`"complete"` | `"failed"` | `"cancelled"`

##### resultPayload?

`Record`\<`string`, `unknown`\>

#### Returns

`Promise`\<`void`\>

***

### flushQueue()

> **flushQueue**(): `Promise`\<`void`\>

Defined in: [packages/openclaw-prefactor-plugin/src/agent.ts:775](https://github.com/prefactordev/typescript-sdk/blob/231423a775642bec119a2db45acf108c6383d05d/packages/openclaw-prefactor-plugin/src/agent.ts#L775)

#### Returns

`Promise`\<`void`\>