Interface: Agent
Prefactor TypeScript SDK / @prefactor/openclaw-prefactor-plugin / Agent
Interface: Agent
Section titled “Interface: Agent”Defined in: packages/openclaw-prefactor-plugin/src/agent.ts:157
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.
AgentConfig with connection and retry settings.
Logger instance used for structured diagnostic output.
Key public methods:
- Agent.createSpan — Creates a span under the given session, registering an AgentInstance first if one does not yet exist.
- Agent.finishSpan — Marks a span as finished; queues the operation for retry on failure.
- Agent.finishAgentInstance — Completes the AgentInstance for a session.
- Agent.flushQueue — Replays any queued operations that previously failed.
- Agent.stop — Stops the background flush loop.
- Agent.emergencyCleanup — Tears down all sessions and clears the queue.
Methods
Section titled “Methods”resolveToolSpanType()
Section titled “resolveToolSpanType()”resolveToolSpanType(
toolName):string
Defined in: packages/openclaw-prefactor-plugin/src/agent.ts:429
Resolves a tool name to its span type. Returns the specific span type for supported tools, or the generic fallback.
Parameters
Section titled “Parameters”toolName
Section titled “toolName”string
Returns
Section titled “Returns”string
stop()
Section titled “stop()”stop():
void
Defined in: packages/openclaw-prefactor-plugin/src/agent.ts:470
Returns
Section titled “Returns”void
emergencyCleanup()
Section titled “emergencyCleanup()”emergencyCleanup():
Promise<void>
Defined in: packages/openclaw-prefactor-plugin/src/agent.ts:477
Returns
Section titled “Returns”Promise<void>
finishAgentInstance()
Section titled “finishAgentInstance()”finishAgentInstance(
sessionKey,status?):Promise<void>
Defined in: packages/openclaw-prefactor-plugin/src/agent.ts:592
Parameters
Section titled “Parameters”sessionKey
Section titled “sessionKey”string
status?
Section titled “status?”"complete" | "failed" | "cancelled"
Returns
Section titled “Returns”Promise<void>
createSpan()
Section titled “createSpan()”createSpan(
sessionKey,schemaName,payload,parentSpanId?):Promise<string|null>
Defined in: packages/openclaw-prefactor-plugin/src/agent.ts:643
Parameters
Section titled “Parameters”sessionKey
Section titled “sessionKey”string
schemaName
Section titled “schemaName”string
payload
Section titled “payload”Record<string, unknown>
parentSpanId?
Section titled “parentSpanId?”string | null
Returns
Section titled “Returns”Promise<string | null>
finishSpan()
Section titled “finishSpan()”finishSpan(
sessionKey,spanId,status?,resultPayload?):Promise<void>
Defined in: packages/openclaw-prefactor-plugin/src/agent.ts:735
Parameters
Section titled “Parameters”sessionKey
Section titled “sessionKey”string
spanId
Section titled “spanId”string
status?
Section titled “status?”"complete" | "failed" | "cancelled"
resultPayload?
Section titled “resultPayload?”Record<string, unknown>
Returns
Section titled “Returns”Promise<void>
flushQueue()
Section titled “flushQueue()”flushQueue():
Promise<void>
Defined in: packages/openclaw-prefactor-plugin/src/agent.ts:775
Returns
Section titled “Returns”Promise<void>