Skip to content
providerkit
GitHub

BackgroundPolicy

Defined in: agents/src/background-types.ts:43

  • Pick<RunOptions, "onEvent" | "onLifecycle" | "bindModelProvider">.Required<Pick<AgentHost, "authorizeResume" | "prepareRequest" | "resolveRequest" | "beforeTool">>.Pick<AgentHost, | "canRunConcurrently" | "needsApproval" | "screenCall" | "answerNow" | "inbox" | "reconcileToolRetry" | "beforeStep" | "reconcileStep">
optional answerNow?: (request, options) =>
| Decision
| Promise<Decision | undefined>
| undefined;

Defined in: agents/src/types.ts:711

Optional standing host policy, or an in-process wait for a person under the run signal. Returning undefined leaves the request pending so the run suspends. While this callback waits, limits.activeMs is paused; limits.elapsedMs, treeLimits.elapsedMs and the caller’s signal still apply.

Parameter Type
request PendingRequest
options { signal: AbortSignal; }
options.signal AbortSignal

| Decision | Promise<Decision | undefined> | undefined

AgentHost.answerNow


authorizeResume: (snapshot) => void | Promise<void>;

Defined in: agents/src/types.ts:684

Load/compare authoritative state and check ownership and freshness, or throw. The host must also exclude concurrent attempts; this loop does not take a lease.

Parameter Type
snapshot TreeNode

void | Promise<void>

AgentHost.authorizeResume


optional beforeStep?: (step, decided?) => void | Promise<void>;

Defined in: agents/src/types.ts:735

Required before every workflow effect or use of an answer. Check current ownership and lease.

Parameter Type
step StepRequest
decided? { decision: Decision; request: PendingRequest; }
decided.decision? Decision
decided.request? PendingRequest

void | Promise<void>

AgentHost.beforeStep


beforeTool: (call, decided?) => void | Promise<void>;

Defined in: agents/src/types.ts:720

Recheck current access and resource version, with the arguments that will run. Required for every invocation carrying a decision, and before exposing a client-tool request.

Parameter Type
call ToolRequest
decided? { decision: Decision; request: PendingRequest; }
decided.decision? Decision
decided.request? PendingRequest

void | Promise<void>

AgentHost.beforeTool


optional bindModelProvider?: ModelProviderBinding;

Defined in: agents/src/types.ts:840

Per-dispatch provider instrumentation. Inherited by children, never saved in checkpoints. Does not wrap tool execution or install an ambient async context manager.

RunOptions.bindModelProvider


optional canRunConcurrently?: (request) => boolean;

Defined in: agents/src/types.ts:748

Both this callback and the tool’s isConcurrencySafe flag must allow batching.

Parameter Type
request ToolRequest

boolean

AgentHost.canRunConcurrently


optional context?: ToolContext;

Defined in: agents/src/background-types.ts:61

Worker-only values for tools. Never serialized; the SDK supplies reserved IDs/signals.


optional inbox?: InputInbox;

Defined in: agents/src/types.ts:672

New user messages for the root’s active conversation owner, never every specialist. A durable host must supply durable authenticated storage. Does not answer human requests.

AgentHost.inbox


optional loadMedia?: (ref, run) => string | Promise<string>;

Defined in: agents/src/background-types.ts:63

Check that the current owner may read each media reference.

Parameter Type
ref MediaRef
run { runId: string; signal: AbortSignal; }
run.runId string
run.signal AbortSignal

string | Promise<string>


optional needsApproval?: (call) => boolean | Promise<boolean>;

Defined in: agents/src/types.ts:686

May require approval for an unmarked tool, never waive a tool’s needsApproval.

Parameter Type
call ToolRequest

boolean | Promise<boolean>

AgentHost.needsApproval


optional onEvent?: (event) => void | Promise<void>;

Defined in: agents/src/types.ts:835

Best-effort progress from the one stream reader. Observer errors do not stop work.

Parameter Type
event AgentEvent

void | Promise<void>

RunOptions.onEvent


optional onLifecycle?: LifecycleHook;

Defined in: agents/src/types.ts:837

Privileged observer, inherited by children. Return values and failures are ignored.

RunOptions.onLifecycle


prepareRequest: (draft) =>
| {
ask?: ApprovalAsk;
scope: RequestScope;
}
| Promise<{
ask?: ApprovalAsk;
scope: RequestScope;
}>;

Defined in: agents/src/types.ts:702

Required to open a request. Supplies trusted actor, resource version and expiry. Only an approval’s presentation/edit policy may be overridden.

Parameter Type
draft RequestOrigin & Omit<PendingRequest, "step" | "call" | "scope">

| { ask?: ApprovalAsk; scope: RequestScope; } | Promise<{ ask?: ApprovalAsk; scope: RequestScope; }>

AgentHost.prepareRequest


optional reconcileStep?: (step, attempt, signal) =>
| {
outcome: "not_run";
receipt: string;
}
| {
outcome: "unknown";
}
| Promise<
| {
outcome: "not_run";
receipt: string;
}
| {
outcome: "unknown";
}>;

Defined in: agents/src/types.ts:739

Parameter Type
step StepRequest
attempt { attemptId: string; error?: StepError; }
attempt.attemptId string
attempt.error? StepError
signal AbortSignal

| { outcome: "not_run"; receipt: string; } | { outcome: "unknown"; } | Promise< | { outcome: "not_run"; receipt: string; } | { outcome: "unknown"; }>

AgentHost.reconcileStep


optional reconcileToolRetry?: (attempt, context) =>
| {
outcome: "not_run";
receipt: string;
}
| {
outcome: "unknown";
}
| Promise<
| {
outcome: "not_run";
receipt: string;
}
| {
outcome: "unknown";
}>;

Defined in: agents/src/types.ts:727

Authoritatively query the external service for this exact failed attempt. Return not_run only when it cannot still complete. An error string or literal key is not proof. Never dispatch from this callback. Requests and control tools cannot use this retry path.

Parameter Type Description
attempt { request: ToolRequest; result: { content: string; kind: | "denied" | "cancelled" | "interrupted" | ToolFailure | "refused" | "unknown_tool" | "disabled_tool" | "invalid_output"; ok: false; }; } -
attempt.request ToolRequest -
attempt.result { content: string; kind: | "denied" | "cancelled" | "interrupted" | ToolFailure | "refused" | "unknown_tool" | "disabled_tool" | "invalid_output"; ok: false; } -
attempt.result.content string -
attempt.result.kind | "denied" | "cancelled" | "interrupted" | ToolFailure | "refused" | "unknown_tool" | "disabled_tool" | "invalid_output" refused: host.screenCall refused the call before it started.
attempt.result.ok false -
context LifecycleContext -

| { outcome: "not_run"; receipt: string; } | { outcome: "unknown"; } | Promise< | { outcome: "not_run"; receipt: string; } | { outcome: "unknown"; }>

AgentHost.reconcileToolRetry


resolveRequest: (request, evidence) =>
| Resolution
| Promise<Resolution>;

Defined in: agents/src/types.ts:717

Authenticate evidence, validate form data and consume it for this exact request. Recovery of the same host claim must return the same decision; another claim must be refused.

Parameter Type
request PendingRequest
evidence unknown

| Resolution | Promise<Resolution>

AgentHost.resolveRequest


optional screenCall?: (call, run) =>
| CallVerdict
| Promise<CallVerdict | undefined>
| undefined;

Defined in: agents/src/types.ts:696

Runs for each call the model or a code program makes, right before it would start. Return nothing to let it run. { refuse } answers this call with that text instead, as the model’s result for it: the tool does not run and no request opens. { cancel } answers this call and every call after it in its turn with that text, and holds after a restart. A call that needs approval is also screened before its approval opens, so nobody is asked about a call the host refuses, and again before it runs, since the calls ahead of it ran in the meantime. Specialists’ calls come here too, each with its own run’s earlier. Decide from earlier rather than process state: after a restart, calls that had not started are screened again.

Parameter Type
call ToolRequest
run ScreenContext

| CallVerdict | Promise<CallVerdict | undefined> | undefined

AgentHost.screenCall

claimContinuation(snapshot, continuation): void | Promise<void>;

Defined in: agents/src/background-types.ts:71

Under the worker’s lease, authenticate every answer and atomically reserve each exact request for continuation.id AND context.segmentId. Repeating that claim succeeds; another claim or segment fails. Empty answers must claim the exact due wake, except an explicit cancel command: claim that command against the current logical segment without granting any pending request. The host owns the durable state. authorizeResume rechecks ownership, and resolveRequest may reuse a consumed answer only within this same claim and segment.

Parameter Type
snapshot TreeNode
continuation Continuation

void | Promise<void>