class RunContext

Properties

protected Step> $steps
protected ClaimsPendingApprovals|null $approvalStore
protected string|null $conversationId
protected ApprovalClaim|null $approvalClaim
protected bool $toolWasInvoked

Methods

__construct(string $invocationId, Agent $agent, TextProvider $provider, string $model, Dispatcher $events, Closure|null $contextRunner = null)

Create the context for a generation run.

Closure|null
contextRunner()

Get the captured operation context runner.

withApprovalStore(ClaimsPendingApprovals $store, string $conversationId)

Claim and record the approvals this run resumes through the given conversation's store.

void
claimPendingApprovals(array $toolCallIds)

Claim the stored pause before any of its tools execute.

bool
hasUnclaimedApprovals()

Determine whether a stored continuation failed before obtaining ownership.

approvalClaim()

Get the claim that owns this continuation.

void
recordApprovalResult(ToolResult $result)

Persist a completed approval result before another tool can execute.

void
recordStep(Step $step)

Keep the step the model just produced, so a run that dies later can still be recorded as far as it got.

void
recordToolResult(ToolResult $result)

Answer the step being worked on, one tool at a time, so a step that dies partway keeps the tools that ran.

recordedResponse()

Get the response the run had built by the time it ended, however it ended.

void
startingStep(StepContext $step, array $messages, TextGenerationOptions|null $options, string|null $model = null, string|null $instructions = null, array $tools = [])

Report that a generation step is about to start.

void
stepCompleted(StepContext|null $step, StepResponse $response, float $time, string|null $model = null)

Report that a generation step returned a response.

void
stepFailed(StepContext|null $step, Throwable $exception, float $time, string|null $model = null)

Report that a generation step ended without producing a response.

void
invokingTool(Tool $tool, array $arguments, string $toolInvocationId)

Report that a tool is about to be invoked.

bool
hasInvokedTool()

Determine whether any tool has started executing in this run.

void
toolInvoked(Tool $tool, array $arguments, mixed $result, string $toolInvocationId, float $time)

Report that a tool returned a result.

void
toolFailed(Tool $tool, array $arguments, Throwable $exception, string $toolInvocationId, float $time)

Report that a tool's handler threw.

Details

at line 48
__construct(string $invocationId, Agent $agent, TextProvider $provider, string $model, Dispatcher $events, Closure|null $contextRunner = null)

Create the context for a generation run.

Parameters

string $invocationId
Agent $agent
TextProvider $provider
string $model
Dispatcher $events
Closure|null $contextRunner

at line 65
Closure|null contextRunner()

internal  
 

Get the captured operation context runner.

Return Value

Closure|null

at line 73
RunContext withApprovalStore(ClaimsPendingApprovals $store, string $conversationId)

Claim and record the approvals this run resumes through the given conversation's store.

Parameters

ClaimsPendingApprovals $store
string $conversationId

Return Value

RunContext

at line 86
void claimPendingApprovals(array $toolCallIds)

Claim the stored pause before any of its tools execute.

Parameters

array $toolCallIds

Return Value

void

at line 102
bool hasUnclaimedApprovals()

Determine whether a stored continuation failed before obtaining ownership.

Return Value

bool

at line 110
ApprovalClaim|null approvalClaim()

Get the claim that owns this continuation.

Return Value

ApprovalClaim|null

at line 118
void recordApprovalResult(ToolResult $result)

Persist a completed approval result before another tool can execute.

Parameters

ToolResult $result

Return Value

void

at line 128
void recordStep(Step $step)

Keep the step the model just produced, so a run that dies later can still be recorded as far as it got.

Parameters

Step $step

Return Value

void

at line 136
void recordToolResult(ToolResult $result)

Answer the step being worked on, one tool at a time, so a step that dies partway keeps the tools that ran.

Parameters

ToolResult $result

Return Value

void

at line 148
AgentResponse recordedResponse()

Get the response the run had built by the time it ended, however it ended.

Return Value

AgentResponse

at line 166
void startingStep(StepContext $step, array $messages, TextGenerationOptions|null $options, string|null $model = null, string|null $instructions = null, array $tools = [])

Report that a generation step is about to start.

Parameters

StepContext $step
array $messages
TextGenerationOptions|null $options
string|null $model
string|null $instructions
array $tools

Return Value

void

at line 190
void stepCompleted(StepContext|null $step, StepResponse $response, float $time, string|null $model = null)

Report that a generation step returned a response.

Parameters

StepContext|null $step
StepResponse $response
float $time
string|null $model

Return Value

void

at line 211
void stepFailed(StepContext|null $step, Throwable $exception, float $time, string|null $model = null)

Report that a generation step ended without producing a response.

Parameters

StepContext|null $step
Throwable $exception
float $time
string|null $model

Return Value

void

at line 234
void invokingTool(Tool $tool, array $arguments, string $toolInvocationId)

Report that a tool is about to be invoked.

Parameters

Tool $tool
array $arguments
string $toolInvocationId

Return Value

void

at line 255
bool hasInvokedTool()

Determine whether any tool has started executing in this run.

Return Value

bool

at line 265
void toolInvoked(Tool $tool, array $arguments, mixed $result, string $toolInvocationId, float $time)

Report that a tool returned a result.

Parameters

Tool $tool
array $arguments
mixed $result
string $toolInvocationId
float $time

Return Value

void

at line 287
void toolFailed(Tool $tool, array $arguments, Throwable $exception, string $toolInvocationId, float $time)

Report that a tool's handler threw.

Parameters

Tool $tool
array $arguments
Throwable $exception
string $toolInvocationId
float $time

Return Value

void