Skip to content

Built-in Functions

This page lists every user-facing built-in function and built-in language construct in Agency. These are available in every .agency file without an import statement.

For the auto-imported standard library (print, sleep, read, fetch, range, ...) see Agency's Standard Library and the stdlib reference.

LLM

NameSignatureDescription
llmllm(prompt: any, options?): TSend a message to an LLM and return its response. The return type T is inferred from the variable annotation at the call site and compiled to a JSON schema. options accepts model, provider, apiKey, maxTokens, temperature, stream, reasoningEffort ("low"/"medium"/"high"), thinking ({ enabled, budgetTokens? }), tools, memory, metadata. See LLMs.

Checkpointing

NameSignatureDescription
checkpointcheckpoint(): numberTake a snapshot of the current execution state and return a checkpoint ID.
getCheckpointgetCheckpoint(id: number): anyReturn the full checkpoint object for a given ID.
restorerestore(checkpoint, options?): voidRestore execution to a previously captured checkpoint. Accepts either a checkpoint object or ID, plus an options object (e.g. { maxRestores: 3 } or variable overrides). See Checkpointing.

Interrupts and Handlers

NameSignatureDescription
interruptinterrupt <kind>(message, payload?)Statement (not a regular function call) that throws an interrupt of the given kind. Execution state is captured so that, once responded to, execution resumes from exactly this point. See Interrupts.
approveapprove(value?): anyUsed inside a handle ... with block to approve the wrapped action, optionally substituting a return value.
rejectreject(value?): anyUsed inside a handle ... with block to block the wrapped action.
propagatepropagate(): anyUsed inside a handle ... with block to pass the interrupt up to the next handler in the chain. See Handlers.

Concurrency

NameSignatureDescription
forkfork(labels) as <name> { ... }Run multiple branches in parallel and wait for all of them to finish. Returns an array of results, one per label.
racerace(labels) as <name> { ... }Like fork, but returns as soon as the first branch completes and cancels the rest. See Concurrency.

Result Type

NameSignatureDescription
successsuccess(value): ResultWrap a value in a successful Result.
failurefailure(error, value?): ResultWrap an error (and optionally a value) in a failed Result.
isSuccessisSuccess(result): booleanCheck whether a Result is a success.
isFailureisFailure(result): booleanCheck whether a Result is a failure. See Error Handling.

Types and Schemas

NameSignatureDescription
schemaschema<T>Expression that returns the Zod schema for a type T. Useful when passing a schema to a TypeScript function or validator. See Schemas.

Debugging

NameSignatureDescription
debuggerdebugger "<label>"?No-op when running the agent normally, but pauses execution when running under the Agency debugger. Accepts an optional label string. See Debugger.