Skip to content

RunState

Serializable snapshot of an agent’s run, including context, usage and trace. While this class has publicly writable properties (prefixed with _), they are not meant to be used directly. To read these properties, use the RunResult instead.

Manipulation of the state directly can lead to unexpected behavior and should be avoided. Instead, use the approve and reject methods to interact with the state.

Type Parameter

TContext

TAgent extends Agent<any, any>

new RunState<TContext, TAgent>(
context,
originalInput,
startingAgent,
maxTurns): RunState<TContext, TAgent>;
Parameter Type

context

RunContext<TContext>

originalInput

| string | AgentInputItem[]

startingAgent

TAgent

maxTurns

number

RunState<TContext, TAgent>

_context: RunContext<TContext>;

Run context tracking approvals, usage, and other metadata.


_conversationId: string | undefined;

Conversation identifier when the server manages conversation history.


_currentAgent: TAgent;

The agent currently handling the conversation.


_currentAgentSpan:
| Span<AgentSpanData>
| undefined;

Active tracing span for the current agent if tracing is enabled.


_currentStep:
| {
newAgent: any;
type: "next_step_handoff";
}
| {
output: string;
type: "next_step_final_output";
}
| {
type: "next_step_run_again";
}
| {
data: z.ZodRecord<z.ZodString, z.ZodAny>;
type: "next_step_interruption";
}
| undefined;

Next step computed for the agent to take.


_currentTurn: number;

Current turn number in the conversation.


_currentTurnInProgress: boolean;

Whether the current turn has already been counted (useful when resuming mid-turn).


_currentTurnPersistedItemCount: number;

Number of _generatedItems already flushed to session storage for the current turn.

Persisting the entire turn on every save would duplicate responses and tool outputs. Instead, saveToSession appends only the delta since the previous write. This counter tracks how many generated run items from this turn were already written so the next save can slice off only the new entries. When a turn is interrupted (e.g., awaiting tool approval) and later resumed, we rewind the counter before continuing so the pending tool output still gets stored.


_generatedItems: RunItem[];

Items generated by the agent during the run.


_inputGuardrailResults: InputGuardrailResult[];

Results from input guardrails applied to the run.


_lastProcessedResponse: ProcessedResponse<TContext> | undefined;

Parsed model response after applying guardrails and tools.


_lastTurnResponse:
| ModelResponse
| undefined;

Last model response for the previous turn.


_maxTurns: number;

Maximum allowed turns before forcing termination.


_modelResponses: ModelResponse[];

Responses from the model so far.


_noActiveAgentRun: boolean;

Whether the run has an active agent step in progress.


_originalInput:
| string
| AgentInputItem[];

Original user input prior to any processing.


_outputGuardrailResults: OutputGuardrailResult<any, any>[];

Results from output guardrails applied to the run.


_previousResponseId: string | undefined;

Latest response identifier returned by the server for server-managed conversations.


_toolInputGuardrailResults: ToolInputGuardrailResult[];

Results from tool input guardrails applied during tool execution.


_toolOutputGuardrailResults: ToolOutputGuardrailResult[];

Results from tool output guardrails applied during tool execution.


_toolUseTracker: AgentToolUseTracker;

Tracks what tools each agent has used.


_trace: Trace | null;

Trace associated with this run if tracing is enabled.

get history(): AgentInputItem[];

The history of the agent run. This includes the input items and the new items generated during the run.

This can be used as inputs for the next agent run.

AgentInputItem[]


get usage(): Usage;

The usage aggregated for this run. This includes per-request breakdowns when available.

Usage

approve(approvalItem, options?): void;

Approves a tool call requested by the agent through an interruption and approval item request.

To approve the request use this method and then run the agent again with the same state object to continue the execution.

By default it will only approve the current tool call. To allow the tool to be used multiple times throughout the run, set the alwaysApprove option to true.

Parameter Type Description

approvalItem

RunToolApprovalItem

The tool call approval item to approve.

options?

{ alwaysApprove?: boolean; }

Options for the approval.

options.alwaysApprove?

boolean

void


getInterruptions(): any;

Returns all interruptions if the current step is an interruption otherwise returns an empty array.

any


reject(approvalItem, options?): void;

Rejects a tool call requested by the agent through an interruption and approval item request.

To reject the request use this method and then run the agent again with the same state object to continue the execution.

By default it will only reject the current tool call. To allow the tool to be used multiple times throughout the run, set the alwaysReject option to true.

Parameter Type Description

approvalItem

RunToolApprovalItem

The tool call approval item to reject.

options?

{ alwaysReject?: boolean; }

Options for the rejection.

options.alwaysReject?

boolean

void


resetTurnPersistence(): void;

Resets the counter that tracks how many items were persisted for the current turn.

void


rewindTurnPersistence(count): void;

Rewinds the persisted item counter when pending approvals require re-writing outputs.

Parameter Type

count

number

void


setConversationContext(conversationId?, previousResponseId?): void;

Updates server-managed conversation identifiers as a single operation.

Parameter Type

conversationId?

string

previousResponseId?

string

void


setCurrentAgent(agent): void;

Switches the active agent handling the run.

Parameter Type

agent

TAgent

void


setCurrentAgentSpan(span?): void;

Updates the agent span associated with the current run.

Parameter Type

span?

Span<AgentSpanData>

void


toJSON(options?): object;

Serializes the run state. By default, tracing API keys are omitted to prevent accidental persistence of secrets. Pass includeTracingApiKey: true only when you intentionally need to migrate a run along with its tracing credentials (e.g., to rehydrate in a separate process that lacks the original environment variables).

Parameter Type

options?

{ includeTracingApiKey?: boolean; }

options.includeTracingApiKey?

boolean

object

$schemaVersion: "1.0" | "1.1";
context: object;
approvals: z.ZodRecord<z.ZodString, z.ZodObject<{
approved: z.ZodUnion<[z.ZodArray<z.ZodString>, z.ZodBoolean]>;
rejected: z.ZodUnion<[z.ZodArray<z.ZodString>, z.ZodBoolean]>;
}, z.core.$strip>>;
context: z.ZodRecord<z.ZodString, z.ZodAny>;
usage: object;
inputTokens: number;
optional inputTokensDetails: Record<string, number>[];
outputTokens: number;
optional outputTokensDetails: Record<string, number>[];
requests: number;
optional requestUsageEntries: object[];
totalTokens: number;
optional conversationId: string;
currentAgent: object;
name: string;
optional currentAgentSpan: SerializedSpanType | null;
optional currentStep:
| {
newAgent: any;
type: "next_step_handoff";
}
| {
output: string;
type: "next_step_final_output";
}
| {
type: "next_step_run_again";
}
| {
data: z.ZodRecord<z.ZodString, z.ZodAny>;
type: "next_step_interruption";
};
currentTurn: number;
optional currentTurnInProgress: boolean;
optional currentTurnPersistedItemCount: number;
generatedItems: (
| {
agent: {
name: string;
};
rawItem: {
content: (
| {
providerData?: Record<string, any>;
text: string;
type: "output_text";
}
| {
providerData?: Record<string, any>;
refusal: string;
type: "refusal";
}
| {
audio: | string
| {
id: string;
};
format?: string | null;
providerData?: Record<string, any>;
transcript?: string | null;
type: "audio";
}
| {
image: string;
providerData?: Record<string, any>;
type: "image";
})[];
id?: string;
providerData?: Record<string, any>;
role: "assistant";
status: "completed" | "in_progress" | "incomplete";
type?: "message";
};
type: "message_output_item";
}
| {
agent: {
name: string;
};
rawItem: | {
action: | {
type: "screenshot";
}
| {
button: "left" | "right" | "wheel" | "back" | "forward";
type: "click";
x: number;
y: number;
}
| {
type: "double_click";
x: number;
y: number;
}
| {
scroll_x: number;
scroll_y: number;
type: "scroll";
x: number;
y: number;
}
| {
text: string;
type: "type";
}
| {
type: "wait";
}
| {
type: "move";
x: number;
y: number;
}
| {
keys: string[];
type: "keypress";
}
| {
path: object[];
type: "drag";
};
callId: string;
id?: string;
providerData?: Record<string, any>;
status: "completed" | "in_progress" | "incomplete";
type: "computer_call";
}
| {
action: {
commands: string[];
maxOutputLength?: number;
timeoutMs?: number;
};
callId: string;
id?: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "shell_call";
}
| {
callId: string;
id?: string;
operation: | {
diff: string;
path: string;
type: "create_file";
}
| {
diff: string;
path: string;
type: "update_file";
}
| {
path: string;
type: "delete_file";
};
providerData?: Record<string, any>;
status: "completed" | "in_progress";
type: "apply_patch_call";
}
| {
arguments: string;
callId: string;
id?: string;
name: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "function_call";
}
| {
arguments?: string;
id?: string;
name: string;
output?: string;
providerData?: Record<string, any>;
status?: string;
type: "hosted_tool_call";
}
| {
arguments?: string;
id?: string;
name: string;
output?: string;
providerData?: Record<string, any>;
status?: string;
type: "hosted_tool_call";
};
type: "tool_call_item";
}
| {
agent: {
name: string;
};
output: string;
rawItem: | {
callId: string;
id?: string;
name: string;
output: | string
| {
providerData?: Record<string, any>;
text: string;
type: "text";
}
| {
detail?: string & object | "low" | "high" | "auto";
image?: | string
| {
data: ... | ...;
mediaType?: ... | ...;
}
| {
url: string;
}
| {
fileId: string;
};
providerData?: Record<string, any>;
type: "image";
}
| {
file: | string
| {
data: ... | ...;
filename: string;
mediaType: string;
}
| {
filename?: ... | ...;
url: string;
}
| {
filename?: ... | ...;
id: string;
};
providerData?: Record<string, any>;
type: "file";
}
| (
| {
providerData?: ... | ...;
text: string;
type: "input_text";
}
| {
detail?: ... | ...;
image?: ... | ... | ...;
providerData?: ... | ...;
type: "input_image";
}
| {
file?: ... | ... | ... | ...;
filename?: ... | ...;
providerData?: ... | ...;
type: "input_file";
})[];
providerData?: Record<string, any>;
status: "completed" | "in_progress" | "incomplete";
type: "function_call_result";
}
| {
callId: string;
id?: string;
output: {
data: string;
providerData?: Record<string, any>;
type: "computer_screenshot";
};
providerData?: Record<string, any>;
type: "computer_call_result";
}
| {
callId: string;
id?: string;
maxOutputLength?: number;
output: object[];
providerData?: Record<string, any>;
type: "shell_call_output";
}
| {
callId: string;
id?: string;
output?: string;
providerData?: Record<string, any>;
status: "completed" | "failed";
type: "apply_patch_call_output";
};
type: "tool_call_output_item";
}
| {
agent: {
name: string;
};
rawItem: {
content: object[];
id?: string;
providerData?: Record<string, any>;
rawContent?: object[];
type: "reasoning";
};
type: "reasoning_item";
}
| {
agent: {
name: string;
};
rawItem: {
arguments: string;
callId: string;
id?: string;
name: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "function_call";
};
type: "handoff_call_item";
}
| {
rawItem: {
callId: string;
id?: string;
name: string;
output: | string
| {
providerData?: Record<string, any>;
text: string;
type: "text";
}
| {
detail?: string & object | "low" | "high" | "auto";
image?: | string
| {
data: string | Uint8Array<...>;
mediaType?: string;
}
| {
url: string;
}
| {
fileId: string;
};
providerData?: Record<string, any>;
type: "image";
}
| {
file: | string
| {
data: string | Uint8Array<...>;
filename: string;
mediaType: string;
}
| {
filename?: string;
url: string;
}
| {
filename?: string;
id: string;
};
providerData?: Record<string, any>;
type: "file";
}
| (
| {
providerData?: Record<..., ...>;
text: string;
type: "input_text";
}
| {
detail?: string;
image?: | string
| {
id: ...;
};
providerData?: Record<..., ...>;
type: "input_image";
}
| {
file?: | string
| {
id: ...;
}
| {
url: ...;
};
filename?: string;
providerData?: Record<..., ...>;
type: "input_file";
})[];
providerData?: Record<string, any>;
status: "completed" | "in_progress" | "incomplete";
type: "function_call_result";
};
sourceAgent: {
name: string;
};
targetAgent: {
name: string;
};
type: "handoff_output_item";
}
| {
agent: {
name: string;
};
rawItem: | {
arguments: string;
callId: string;
id?: string;
name: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "function_call";
}
| {
arguments?: string;
id?: string;
name: string;
output?: string;
providerData?: Record<string, any>;
status?: string;
type: "hosted_tool_call";
}
| {
action: {
commands: string[];
maxOutputLength?: number;
timeoutMs?: number;
};
callId: string;
id?: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "shell_call";
}
| {
callId: string;
id?: string;
operation: | {
diff: string;
path: string;
type: "create_file";
}
| {
diff: string;
path: string;
type: "update_file";
}
| {
path: string;
type: "delete_file";
};
providerData?: Record<string, any>;
status: "completed" | "in_progress";
type: "apply_patch_call";
};
toolName?: string;
type: "tool_approval_item";
})[];
inputGuardrailResults: object[];
optional lastModelResponse: object;
output: (
| {
content: (
| {
providerData?: Record<..., ...>;
text: string;
type: "output_text";
}
| {
providerData?: Record<..., ...>;
refusal: string;
type: "refusal";
}
| {
audio: | string
| {
id: ...;
};
format?: string | null;
providerData?: Record<..., ...>;
transcript?: string | null;
type: "audio";
}
| {
image: string;
providerData?: Record<..., ...>;
type: "image";
})[];
id?: string;
providerData?: Record<string, any>;
role: "assistant";
status: "completed" | "in_progress" | "incomplete";
type?: "message";
}
| {
arguments?: string;
id?: string;
name: string;
output?: string;
providerData?: Record<string, any>;
status?: string;
type: "hosted_tool_call";
}
| {
arguments: string;
callId: string;
id?: string;
name: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "function_call";
}
| {
action: | {
type: "screenshot";
}
| {
button: "left" | "right" | "wheel" | "back" | "forward";
type: "click";
x: number;
y: number;
}
| {
type: "double_click";
x: number;
y: number;
}
| {
scroll_x: number;
scroll_y: number;
type: "scroll";
x: number;
y: number;
}
| {
text: string;
type: "type";
}
| {
type: "wait";
}
| {
type: "move";
x: number;
y: number;
}
| {
keys: string[];
type: "keypress";
}
| {
path: object[];
type: "drag";
};
callId: string;
id?: string;
providerData?: Record<string, any>;
status: "completed" | "in_progress" | "incomplete";
type: "computer_call";
}
| {
action: {
commands: string[];
maxOutputLength?: number;
timeoutMs?: number;
};
callId: string;
id?: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "shell_call";
}
| {
callId: string;
id?: string;
operation: | {
diff: string;
path: string;
type: "create_file";
}
| {
diff: string;
path: string;
type: "update_file";
}
| {
path: string;
type: "delete_file";
};
providerData?: Record<string, any>;
status: "completed" | "in_progress";
type: "apply_patch_call";
}
| {
callId: string;
id?: string;
name: string;
output: | string
| {
providerData?: Record<string, any>;
text: string;
type: "text";
}
| {
detail?: string & object | "low" | "high" | "auto";
image?: | string
| {
data: ... | ...;
mediaType?: ... | ...;
}
| {
url: string;
}
| {
fileId: string;
};
providerData?: Record<string, any>;
type: "image";
}
| {
file: | string
| {
data: ... | ...;
filename: string;
mediaType: string;
}
| {
filename?: ... | ...;
url: string;
}
| {
filename?: ... | ...;
id: string;
};
providerData?: Record<string, any>;
type: "file";
}
| (
| {
providerData?: ... | ...;
text: string;
type: "input_text";
}
| {
detail?: ... | ...;
image?: ... | ... | ...;
providerData?: ... | ...;
type: "input_image";
}
| {
file?: ... | ... | ... | ...;
filename?: ... | ...;
providerData?: ... | ...;
type: "input_file";
})[];
providerData?: Record<string, any>;
status: "completed" | "in_progress" | "incomplete";
type: "function_call_result";
}
| {
callId: string;
id?: string;
maxOutputLength?: number;
output: object[];
providerData?: Record<string, any>;
type: "shell_call_output";
}
| {
callId: string;
id?: string;
output?: string;
providerData?: Record<string, any>;
status: "completed" | "failed";
type: "apply_patch_call_output";
}
| {
content: object[];
id?: string;
providerData?: Record<string, any>;
rawContent?: object[];
type: "reasoning";
}
| {
created_by?: string;
encrypted_content: string;
id?: string;
providerData?: Record<string, any>;
type: "compaction";
}
| {
id?: string;
providerData?: Record<string, any>;
type: "unknown";
})[];
optional providerData: Record<string, any>;
optional responseId: string;
usage: object;
inputTokens: number;
lastModelResponse.usage.inputTokensDetails?
Section titled “lastModelResponse.usage.inputTokensDetails?”
optional inputTokensDetails: Record<string, number>[];
outputTokens: number;
lastModelResponse.usage.outputTokensDetails?
Section titled “lastModelResponse.usage.outputTokensDetails?”
optional outputTokensDetails: Record<string, number>[];
requests: number;
lastModelResponse.usage.requestUsageEntries?
Section titled “lastModelResponse.usage.requestUsageEntries?”
optional requestUsageEntries: object[];
totalTokens: number;
optional lastProcessedResponse: object;
optional applyPatchActions: object[];
computerActions: object[];
functions: object[];
handoffs: object[];
lastProcessedResponse.mcpApprovalRequests?
Section titled “lastProcessedResponse.mcpApprovalRequests?”
optional mcpApprovalRequests: object[];
newItems: (
| {
agent: {
name: string;
};
rawItem: {
content: (
| {
providerData?: ... | ...;
text: string;
type: "output_text";
}
| {
providerData?: ... | ...;
refusal: string;
type: "refusal";
}
| {
audio: ... | ...;
format?: ... | ... | ...;
providerData?: ... | ...;
transcript?: ... | ... | ...;
type: "audio";
}
| {
image: string;
providerData?: ... | ...;
type: "image";
})[];
id?: string;
providerData?: Record<string, any>;
role: "assistant";
status: "completed" | "in_progress" | "incomplete";
type?: "message";
};
type: "message_output_item";
}
| {
agent: {
name: string;
};
rawItem: | {
action: | {
type: "screenshot";
}
| {
button: ... | ... | ... | ... | ...;
type: "click";
x: number;
y: number;
}
| {
type: "double_click";
x: number;
y: number;
}
| {
scroll_x: number;
scroll_y: number;
type: "scroll";
x: number;
y: number;
}
| {
text: string;
type: "type";
}
| {
type: "wait";
}
| {
type: "move";
x: number;
y: number;
}
| {
keys: ...[];
type: "keypress";
}
| {
path: ...[];
type: "drag";
};
callId: string;
id?: string;
providerData?: Record<string, any>;
status: "completed" | "in_progress" | "incomplete";
type: "computer_call";
}
| {
action: {
commands: string[];
maxOutputLength?: number;
timeoutMs?: number;
};
callId: string;
id?: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "shell_call";
}
| {
callId: string;
id?: string;
operation: | {
diff: string;
path: string;
type: "create_file";
}
| {
diff: string;
path: string;
type: "update_file";
}
| {
path: string;
type: "delete_file";
};
providerData?: Record<string, any>;
status: "completed" | "in_progress";
type: "apply_patch_call";
}
| {
arguments: string;
callId: string;
id?: string;
name: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "function_call";
}
| {
arguments?: string;
id?: string;
name: string;
output?: string;
providerData?: Record<string, any>;
status?: string;
type: "hosted_tool_call";
}
| {
arguments?: string;
id?: string;
name: string;
output?: string;
providerData?: Record<string, any>;
status?: string;
type: "hosted_tool_call";
};
type: "tool_call_item";
}
| {
agent: {
name: string;
};
output: string;
rawItem: | {
callId: string;
id?: string;
name: string;
output: | string
| {
providerData?: ... | ...;
text: string;
type: "text";
}
| {
detail?: ... | ... | ... | ... | ...;
image?: ... | ... | ... | ... | ...;
providerData?: ... | ...;
type: "image";
}
| {
file: ... | ... | ... | ...;
providerData?: ... | ...;
type: "file";
}
| (... | ... | ...)[];
providerData?: Record<string, any>;
status: "completed" | "in_progress" | "incomplete";
type: "function_call_result";
}
| {
callId: string;
id?: string;
output: {
data: string;
providerData?: Record<..., ...>;
type: "computer_screenshot";
};
providerData?: Record<string, any>;
type: "computer_call_result";
}
| {
callId: string;
id?: string;
maxOutputLength?: number;
output: object[];
providerData?: Record<string, any>;
type: "shell_call_output";
}
| {
callId: string;
id?: string;
output?: string;
providerData?: Record<string, any>;
status: "completed" | "failed";
type: "apply_patch_call_output";
};
type: "tool_call_output_item";
}
| {
agent: {
name: string;
};
rawItem: {
content: object[];
id?: string;
providerData?: Record<string, any>;
rawContent?: object[];
type: "reasoning";
};
type: "reasoning_item";
}
| {
agent: {
name: string;
};
rawItem: {
arguments: string;
callId: string;
id?: string;
name: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "function_call";
};
type: "handoff_call_item";
}
| {
rawItem: {
callId: string;
id?: string;
name: string;
output: | string
| {
providerData?: Record<..., ...>;
text: string;
type: "text";
}
| {
detail?: ... & ... | "low" | "high" | "auto";
image?: | string
| {
data: ...;
mediaType?: ...;
}
| {
url: ...;
}
| {
fileId: ...;
};
providerData?: Record<..., ...>;
type: "image";
}
| {
file: | string
| {
data: ...;
filename: ...;
mediaType: ...;
}
| {
filename?: ...;
url: ...;
}
| {
filename?: ...;
id: ...;
};
providerData?: Record<..., ...>;
type: "file";
}
| (
| {
providerData?: ...;
text: ...;
type: ...;
}
| {
detail?: ...;
image?: ...;
providerData?: ...;
type: ...;
}
| {
file?: ...;
filename?: ...;
providerData?: ...;
type: ...;
})[];
providerData?: Record<string, any>;
status: "completed" | "in_progress" | "incomplete";
type: "function_call_result";
};
sourceAgent: {
name: string;
};
targetAgent: {
name: string;
};
type: "handoff_output_item";
}
| {
agent: {
name: string;
};
rawItem: | {
arguments: string;
callId: string;
id?: string;
name: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "function_call";
}
| {
arguments?: string;
id?: string;
name: string;
output?: string;
providerData?: Record<string, any>;
status?: string;
type: "hosted_tool_call";
}
| {
action: {
commands: string[];
maxOutputLength?: number;
timeoutMs?: number;
};
callId: string;
id?: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "shell_call";
}
| {
callId: string;
id?: string;
operation: | {
diff: string;
path: string;
type: "create_file";
}
| {
diff: string;
path: string;
type: "update_file";
}
| {
path: string;
type: "delete_file";
};
providerData?: Record<string, any>;
status: "completed" | "in_progress";
type: "apply_patch_call";
};
toolName?: string;
type: "tool_approval_item";
})[];
optional shellActions: object[];
toolsUsed: string[];
maxTurns: number;
modelResponses: object[];
noActiveAgentRun: boolean;
originalInput:
| string
| (
| {
content: | string
| (
| {
providerData?: Record<..., ...>;
text: string;
type: "input_text";
}
| {
detail?: string;
image?: | string
| {
id: ...;
};
providerData?: Record<..., ...>;
type: "input_image";
}
| {
file?: | string
| {
id: ...;
}
| {
url: ...;
};
filename?: string;
providerData?: Record<..., ...>;
type: "input_file";
}
| {
audio: | string
| {
id: ...;
};
format?: string | null;
providerData?: Record<..., ...>;
transcript?: string | null;
type: "audio";
})[];
id?: string;
providerData?: Record<string, any>;
role: "user";
type?: "message";
}
| {
content: (
| {
providerData?: Record<string, any>;
text: string;
type: "output_text";
}
| {
providerData?: Record<string, any>;
refusal: string;
type: "refusal";
}
| {
audio: | string
| {
id: string;
};
format?: string | null;
providerData?: Record<string, any>;
transcript?: string | null;
type: "audio";
}
| {
image: string;
providerData?: Record<string, any>;
type: "image";
})[];
id?: string;
providerData?: Record<string, any>;
role: "assistant";
status: "completed" | "in_progress" | "incomplete";
type?: "message";
}
| {
content: string;
id?: string;
providerData?: Record<string, any>;
role: "system";
type?: "message";
}
| {
arguments?: string;
id?: string;
name: string;
output?: string;
providerData?: Record<string, any>;
status?: string;
type: "hosted_tool_call";
}
| {
arguments: string;
callId: string;
id?: string;
name: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "function_call";
}
| {
action: | {
type: "screenshot";
}
| {
button: "left" | "right" | "wheel" | "back" | "forward";
type: "click";
x: number;
y: number;
}
| {
type: "double_click";
x: number;
y: number;
}
| {
scroll_x: number;
scroll_y: number;
type: "scroll";
x: number;
y: number;
}
| {
text: string;
type: "type";
}
| {
type: "wait";
}
| {
type: "move";
x: number;
y: number;
}
| {
keys: string[];
type: "keypress";
}
| {
path: object[];
type: "drag";
};
callId: string;
id?: string;
providerData?: Record<string, any>;
status: "completed" | "in_progress" | "incomplete";
type: "computer_call";
}
| {
action: {
commands: string[];
maxOutputLength?: number;
timeoutMs?: number;
};
callId: string;
id?: string;
providerData?: Record<string, any>;
status?: "completed" | "in_progress" | "incomplete";
type: "shell_call";
}
| {
callId: string;
id?: string;
operation: | {
diff: string;
path: string;
type: "create_file";
}
| {
diff: string;
path: string;
type: "update_file";
}
| {
path: string;
type: "delete_file";
};
providerData?: Record<string, any>;
status: "completed" | "in_progress";
type: "apply_patch_call";
}
| {
callId: string;
id?: string;
name: string;
output: | string
| {
providerData?: Record<string, any>;
text: string;
type: "text";
}
| {
detail?: string & object | "low" | "high" | "auto";
image?: | string
| {
data: string | Uint8Array<...>;
mediaType?: string;
}
| {
url: string;
}
| {
fileId: string;
};
providerData?: Record<string, any>;
type: "image";
}
| {
file: | string
| {
data: string | Uint8Array<...>;
filename: string;
mediaType: string;
}
| {
filename?: string;
url: string;
}
| {
filename?: string;
id: string;
};
providerData?: Record<string, any>;
type: "file";
}
| (
| {
providerData?: Record<..., ...>;
text: string;
type: "input_text";
}
| {
detail?: string;
image?: | string
| {
id: ...;
};
providerData?: Record<..., ...>;
type: "input_image";
}
| {
file?: | string
| {
id: ...;
}
| {
url: ...;
};
filename?: string;
providerData?: Record<..., ...>;
type: "input_file";
})[];
providerData?: Record<string, any>;
status: "completed" | "in_progress" | "incomplete";
type: "function_call_result";
}
| {
callId: string;
id?: string;
output: {
data: string;
providerData?: Record<string, any>;
type: "computer_screenshot";
};
providerData?: Record<string, any>;
type: "computer_call_result";
}
| {
callId: string;
id?: string;
maxOutputLength?: number;
output: object[];
providerData?: Record<string, any>;
type: "shell_call_output";
}
| {
callId: string;
id?: string;
output?: string;
providerData?: Record<string, any>;
status: "completed" | "failed";
type: "apply_patch_call_output";
}
| {
content: object[];
id?: string;
providerData?: Record<string, any>;
rawContent?: object[];
type: "reasoning";
}
| {
created_by?: string;
encrypted_content: string;
id?: string;
providerData?: Record<string, any>;
type: "compaction";
}
| {
id?: string;
providerData?: Record<string, any>;
type: "unknown";
})[];
outputGuardrailResults: object[];
optional previousResponseId: string;
toolInputGuardrailResults: object[];
toolOutputGuardrailResults: object[];
toolUseTracker: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
trace:
| {
group_id: string | null;
id: string;
metadata: z.ZodRecord<z.ZodString, z.ZodAny>;
object: "trace";
tracing_api_key?: string | null;
workflow_name: string;
}
| null;

toString(options?): string;

Serializes the run state to a string.

This method is used to serialize the run state to a string that can be used to resume the run later.

Parameter Type

options?

{ includeTracingApiKey?: boolean; }

options.includeTracingApiKey?

boolean

string

The serialized run state.


static fromString<TContext, TAgent>(initialAgent, str): Promise<RunState<TContext, TAgent>>;

Deserializes a run state from a string.

This method is used to deserialize a run state from a string that was serialized using the toString method.

Type Parameter

TContext

TAgent extends Agent<any, any>

Parameter Type

initialAgent

TAgent

str

string

Promise<RunState<TContext, TAgent>>