AgentHost
Defined in: agents/src/types.ts:669
Host callbacks are trusted code, never functions reconstructed from a client snapshot. Data passed to callbacks is a frozen copy, not the loop’s live state. Without checkpoint, execution is in-memory only. Checkpoints are not leases or exactly-once effect guarantees.
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
authorizeResume?
Section titled “authorizeResume?”optional 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>
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>
beforeTool?
Section titled “beforeTool?”optional 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>
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
checkpoint?
Section titled “checkpoint?”optional checkpoint?: (snapshot) => void | Promise<void>;Defined in: agents/src/types.ts:681
Persist the whole snapshot before returning. Writes are serialized within this attempt.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
snapshot |
TreeNode |
Returns
Section titled “Returns”void | Promise<void>
child?
Section titled “child?”optional child?: (request, execute) => Promise<ChildEnvelope>;Defined in: agents/src/types.ts:753
Optional in-process child binding under this root’s lease and cancellation. A host may return a saved envelope. To resume a suspended SDK child it must call execute in a new/resumable segment, not treat a cached suspension as completion. execute may be called once, and must settle before the hook returns.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
request |
ChildRequest |
execute |
() => Promise<ChildEnvelope> |
Returns
Section titled “Returns”Promise<ChildEnvelope>
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.
loadMedia?
Section titled “loadMedia?”optional loadMedia?: (ref, run) => string | Promise<string>;Defined in: agents/src/types.ts:756
Check that this run’s owner may read the media, then return its bytes as base64. Called once per id per attempt, before the model call that needs it. An id is not permission.
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>
onContextLimit?
Section titled “onContextLimit?”optional onContextLimit?: (limit) => void;Defined in: agents/src/types.ts:768
Reports a length rejection from a turn. Counts are present only if the provider supplied them; the configured window and earlier calls are not measurements of this request.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
limit |
{ contextLimit?: number; inputTokens?: number; model: string; operationId: string; provider: string; runId: string; } |
limit.contextLimit? |
number |
limit.inputTokens? |
number |
limit.model |
string |
limit.operationId |
string |
limit.provider |
string |
limit.runId |
string |
Returns
Section titled “Returns”void
prepareRequest?
Section titled “prepareRequest?”optional 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;
}>
priceModelCall?
Section titled “priceModelCall?”optional priceModelCall?: (call) => number;Defined in: agents/src/types.ts:765
USD for one model call’s usage, from the host’s own rates: no price table ships here, and
core’s costUsd(usage, rate) does the arithmetic. Required by limits.costUsd. Called
when usage arrives and when the call completes, then saved in the journal, so a resumed
run never prices a saved call again, even when the host’s prices change by time of day.
Synchronous; return a finite amount of 0 or more.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
call |
MeasuredModelCall |
Returns
Section titled “Returns”number
progress?
Section titled “progress?”optional progress?: object;Defined in: agents/src/types.ts:676
Required progress storage, separate from best-effort onEvent. push synchronously accepts a frozen event into a bounded buffer; flush must report any write failure, not hide it. The loop awaits flush before every checkpoint and final outcome, including children.
flush()
Section titled “flush()”flush(): Promise<void>;Returns
Section titled “Returns”Promise<void>
push()
Section titled “push()”push(event): void;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
event |
AgentEvent |
Returns
Section titled “Returns”void
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";
}>
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";
}>
resolveRequest?
Section titled “resolveRequest?”optional 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>
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