BackgroundPolicy
Defined in: agents/src/background-types.ts:43
Extends
Section titled “Extends”Pick<RunOptions,"onEvent"|"onLifecycle"|"bindModelProvider">.Required<Pick<AgentHost,"authorizeResume"|"prepareRequest"|"resolveRequest"|"beforeTool">>.Pick<AgentHost, |"canRunConcurrently"|"needsApproval"|"screenCall"|"answerNow"|"inbox"|"reconcileToolRetry"|"beforeStep"|"reconcileStep">
Properties
Section titled “Properties”answerNow?
Section titled “answerNow?”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
request |
PendingRequest |
options |
{ signal: AbortSignal; } |
options.signal |
AbortSignal |
Returns
Section titled “Returns”| Decision
| Promise<Decision | undefined>
| undefined
Inherited from
Section titled “Inherited from”authorizeResume
Section titled “authorizeResume”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
snapshot |
TreeNode |
Returns
Section titled “Returns”void | Promise<void>
Inherited from
Section titled “Inherited from”beforeStep?
Section titled “beforeStep?”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
step |
StepRequest |
decided? |
{ decision: Decision; request: PendingRequest; } |
decided.decision? |
Decision |
decided.request? |
PendingRequest |
Returns
Section titled “Returns”void | Promise<void>
Inherited from
Section titled “Inherited from”beforeTool
Section titled “beforeTool”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
call |
ToolRequest |
decided? |
{ decision: Decision; request: PendingRequest; } |
decided.decision? |
Decision |
decided.request? |
PendingRequest |
Returns
Section titled “Returns”void | Promise<void>
Inherited from
Section titled “Inherited from”bindModelProvider?
Section titled “bindModelProvider?”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.
Inherited from
Section titled “Inherited from”canRunConcurrently?
Section titled “canRunConcurrently?”optional canRunConcurrently?: (request) => boolean;Defined in: agents/src/types.ts:748
Both this callback and the tool’s isConcurrencySafe flag must allow batching.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
request |
ToolRequest |
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”context?
Section titled “context?”optional context?: ToolContext;Defined in: agents/src/background-types.ts:61
Worker-only values for tools. Never serialized; the SDK supplies reserved IDs/signals.
inbox?
Section titled “inbox?”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.
Inherited from
Section titled “Inherited from”loadMedia?
Section titled “loadMedia?”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ref |
MediaRef |
run |
{ runId: string; signal: AbortSignal; } |
run.runId |
string |
run.signal |
AbortSignal |
Returns
Section titled “Returns”string | Promise<string>
needsApproval?
Section titled “needsApproval?”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
call |
ToolRequest |
Returns
Section titled “Returns”boolean | Promise<boolean>
Inherited from
Section titled “Inherited from”onEvent?
Section titled “onEvent?”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
event |
AgentEvent |
Returns
Section titled “Returns”void | Promise<void>
Inherited from
Section titled “Inherited from”onLifecycle?
Section titled “onLifecycle?”optional onLifecycle?: LifecycleHook;Defined in: agents/src/types.ts:837
Privileged observer, inherited by children. Return values and failures are ignored.
Inherited from
Section titled “Inherited from”prepareRequest
Section titled “prepareRequest”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
draft |
RequestOrigin & Omit<PendingRequest, "step" | "call" | "scope"> |
Returns
Section titled “Returns”| {
ask?: ApprovalAsk;
scope: RequestScope;
}
| Promise<{
ask?: ApprovalAsk;
scope: RequestScope;
}>
Inherited from
Section titled “Inherited from”reconcileStep?
Section titled “reconcileStep?”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
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
step |
StepRequest |
attempt |
{ attemptId: string; error?: StepError; } |
attempt.attemptId |
string |
attempt.error? |
StepError |
signal |
AbortSignal |
Returns
Section titled “Returns”| {
outcome: "not_run";
receipt: string;
}
| {
outcome: "unknown";
}
| Promise<
| {
outcome: "not_run";
receipt: string;
}
| {
outcome: "unknown";
}>
Inherited from
Section titled “Inherited from”reconcileToolRetry?
Section titled “reconcileToolRetry?”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.
Parameters
Section titled “Parameters”| 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 |
- |
Returns
Section titled “Returns”| {
outcome: "not_run";
receipt: string;
}
| {
outcome: "unknown";
}
| Promise<
| {
outcome: "not_run";
receipt: string;
}
| {
outcome: "unknown";
}>
Inherited from
Section titled “Inherited from”resolveRequest
Section titled “resolveRequest”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
request |
PendingRequest |
evidence |
unknown |
Returns
Section titled “Returns”| Resolution
| Promise<Resolution>
Inherited from
Section titled “Inherited from”screenCall?
Section titled “screenCall?”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
call |
ToolRequest |
run |
ScreenContext |
Returns
Section titled “Returns”| CallVerdict
| Promise<CallVerdict | undefined>
| undefined
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”claimContinuation()
Section titled “claimContinuation()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
snapshot |
TreeNode |
continuation |
Continuation |
Returns
Section titled “Returns”void | Promise<void>