Hooks and contexts

Hooks that change the agent loop, the contexts your code gets, and the helpers that give the same values when a deployed agent runs the loop again.

Give a hook result's content as content blocks, such as agents.TextContentBlock(text="..."), or use agents.skip(reason), agents.retry(feedback) and agents.reject(reason) with a string.

Guide: Guardrails.

NameWhat it is
HookCode that runs at points of the agent loop: before and after each turn, model call and tool call.
HookDecisionA hook's decision, turned into the result of the point that returns it.
agents.skipStop the turn, model call or tool call.
agents.retryDiscard the model's response and call the model again with feedback.
agents.rejectReject the model's response and end the turn with reason.
agents.hookWhat a hook gets at each point and returns: continue, or replace the input or output.
StateThe saved form of a hook or sandbox: its type, and the JSON data it keeps across turns.
hook.PreAgentTurnThe turn a pre_agent_turn hook receives.
hook.PreLlmCallThe model call a pre_llm_call hook receives.
hook.PostLlmCallThe model reply a post_llm_call hook receives.
hook.PostAgentTurnThe final answer of the turn a post_agent_turn hook receives.
hook.PreToolCallThe tool call a pre_tool_call hook receives.
hook.PostToolCallThe tool call and result a post_tool_call hook receives.
hook.PreAgentTurnHookContinueWhat pre_agent_turn returns to start the turn with other user content.
hook.PreAgentTurnHookSkipWhat pre_agent_turn returns to end the turn before the model runs, as agents.skip does.
hook.PreLlmCallHookContinueWhat pre_llm_call returns to let the model call run, as None does.
hook.PreLlmCallHookSkipWhat pre_llm_call returns to end the turn instead of calling the model, as agents.skip does.
hook.PostLlmCallHookAcceptWhat post_llm_call returns to keep the model's response, or to replace its content.
hook.PostLlmCallHookRetryWhat post_llm_call returns to drop the response and call the model again, as agents.retry does.
hook.PostLlmCallHookRejectWhat post_llm_call returns to reject the response and end the turn, as agents.reject does.
hook.PreToolCallHookContinueWhat pre_tool_call returns to run the tool with other arguments.
hook.PreToolCallHookSkipWhat pre_tool_call returns to skip the call, as agents.skip does.
hook.PostToolCallHookContinueWhat post_tool_call returns to give the model another tool result.
hook.PostAgentTurnHookAcceptWhat post_agent_turn returns to keep the final answer, or to replace its content.
hook.ReplaceAssistantContentReplace the model's reply with content, from post_llm_call or post_agent_turn.
pattern.hook.StructuredOutputHookValidate the final answer of each turn with a Pydantic model, and ask the model to correct it.
CallbackContextWhat a callback gets as ctx: the session it runs in and the session's sandbox.
CallbackSessionThe session a callback runs in: its ID and the turn's.
HookCallbackContextWhat a hook method gets as ctx: the session it runs in and the session's sandbox.
ToolCallbackContextWhat a tool gets as its first, positional-only parameter: the session, its sandbox and the call.
ApprovalCallbackContextWhat an approval handler gets as ctx: the session that asked, and the approval's ID.
SandboxCallbackContextContext a sandbox hook receives in on_create and on_destroy.
agents.nowThe current time in UTC, as a timezone-aware datetime.
agents.sleepWait for duration, in the agent loop, a tool, a Hook or a local run.
agents.uuid4A random UUID that stays the same when a deployed agent runs the agent loop again.
agents.randomA random number generator that gives the same numbers when a deployed agent runs the loop again.
Hooks

Hooks

Hook

Hook

class Hook(*, tools: Sequence[PythonTool[..., Any] | ClientTool[..., Any]] = (), **data: Any)

Code that runs at points of the agent loop: before and after each turn, model call and tool call.

Override the points you need; returning None continues unchanged. A hook is a Pydantic model. Its fields are its state: the session keeps their values and every call starts from the values the last successful call left. Anything else the hook holds, such as a client, is a PrivateAttr, which is never saved. __init__ runs only when you build the hook: each call starts from a copy.

A saved value records its class, and the SDK finds the class again among the modules already loaded. Loading a value never imports a module. Define every hook class, and the class of every hook kept in a field, at module level, in a module your agent's module imports. Otherwise, creating a session fails. Keep hooks held in a field in a list or a tuple. A set raises SdkError.

A field with an alias, such as max_calls: int = Field(0, alias="maxCalls"), takes its name when you build the hook, Budget(max_calls=5), and its alias in the saved value. To build the hook by alias too, set validate_by_alias=True in model_config. Pydantic's own model_validate reads a hook by field name, so it does not load the saved value of a hook with an aliased field.

ParameterTypeDefaultDescription
toolsSequence[PythonTool[..., Any] | ClientTool[..., Any]]()The tools that the hook adds to the agent's tools.
**dataAny{}The values of the hook's fields.
AttributeTypeDescription
toolsSequence[PythonTool[..., Any]]The tools that the hook adds to the agent's tools.
Hook.pre_agent_turn

Hook.pre_agent_turn

async def pre_agent_turn(
    ctx: HookCallbackContext,
    request: hook.PreAgentTurn,
) -> hook.PreAgentTurnHookContinue | hook.PreAgentTurnHookSkip | HookDecision | None

Runs before each turn, with its user content in request.user_content.

Return hook.PreAgentTurnHookContinue to send other content, such as [*request.user_content, agents.TextContentBlock(text="...")], or agents.skip or hook.PreAgentTurnHookSkip to skip the turn.

ParameterTypeDefaultDescription
ctxHookCallbackContextrequiredThe session the hook runs in and its sandbox.
requesthook.PreAgentTurnrequiredThe turn about to run.
Hook.post_agent_turn

Hook.post_agent_turn

async def post_agent_turn(
    ctx: HookCallbackContext,
    result: hook.PostAgentTurn,
) -> hook.PostAgentTurnHookAccept | None

Runs after each turn, with the model's final answer in result: result.text, result.content.

Return hook.PostAgentTurnHookAccept() to keep the answer, or replace its content with acceptance=hook.ReplaceAssistantContent(content=[agents.TextContentBlock(text="...")]).

ParameterTypeDefaultDescription
ctxHookCallbackContextrequiredThe session the hook runs in and its sandbox.
resulthook.PostAgentTurnrequiredThe turn that ran, with the model's final answer.
Hook.pre_llm_call

Hook.pre_llm_call

async def pre_llm_call(
    ctx: HookCallbackContext,
    invocation: hook.PreLlmCall,
) -> hook.PreLlmCallHookContinue | hook.PreLlmCallHookSkip | HookDecision | None

Runs before each model call. Return agents.skip or hook.PreLlmCallHookSkip to end the turn without calling the model (stop_reason="skipped").

ParameterTypeDefaultDescription
ctxHookCallbackContextrequiredThe session the hook runs in and its sandbox.
invocationhook.PreLlmCallrequiredThe model call about to run.
Hook.post_llm_call

Hook.post_llm_call

async def post_llm_call(
    ctx: HookCallbackContext,
    invocation: hook.PostLlmCall,
) -> hook.PostLlmCallHookAccept | hook.PostLlmCallHookRetry | hook.PostLlmCallHookReject | HookDecision | None

Runs after each model call, with its response in invocation: invocation.text, invocation.tool_calls, invocation.content.

Return hook.PostLlmCallHookAccept to keep the response or replace its content, as hook.PostAgentTurnHookAccept does, agents.retry to call the model again with feedback, or agents.reject to end the turn.

ParameterTypeDefaultDescription
ctxHookCallbackContextrequiredThe session the hook runs in and its sandbox.
invocationhook.PostLlmCallrequiredThe model call that ran, with its response.
Hook.pre_tool_call

Hook.pre_tool_call

async def pre_tool_call(
    ctx: HookCallbackContext,
    call: hook.PreToolCall,
) -> hook.PreToolCallHookContinue | hook.PreToolCallHookSkip | HookDecision | None

Runs before each tool call, with the call in call.

Return hook.PreToolCallHookContinue to run the tool with other effective_arguments, or agents.skip or hook.PreToolCallHookSkip to skip the call: the model sees the reason instead. The history's tool call entry shows the arguments the hook set; a skipped call keeps the model's.

ParameterTypeDefaultDescription
ctxHookCallbackContextrequiredThe session the hook runs in and its sandbox.
callhook.PreToolCallrequiredThe tool call about to run.
Hook.post_tool_call

Hook.post_tool_call

async def post_tool_call(
    ctx: HookCallbackContext,
    result: hook.PostToolCall,
) -> hook.PostToolCallHookContinue | None

Runs after each tool call, with the call and its result, an agents.ToolResult, in result.

Return hook.PostToolCallHookContinue with another tool_result to change what the model gets, such as agents.ToolResult(content=[agents.TextContentBlock(text="...")]).

ParameterTypeDefaultDescription
ctxHookCallbackContextrequiredThe session the hook runs in and its sandbox.
resulthook.PostToolCallrequiredThe tool call that ran, with its result.
HookDecision

HookDecision

class HookDecision

A hook's decision, turned into the result of the point that returns it.

Build it with agents.skip, agents.retry or agents.reject.

AttributeTypeDescription
kindLiteral['skip', 'retry', 'reject']"skip", "retry" or "reject": the function that built it.
messagestrThe reason or feedback the function took.
agents.skip

agents.skip

def agents.skip(reason: str) -> HookDecision

Stop the turn, model call or tool call.

From pre_tool_call, reason is what the model sees in place of the tool result. From pre_agent_turn or pre_llm_call, the turn ends with stop_reason="skipped" and reason as its text.

ParameterTypeDefaultDescription
reasonstrrequiredWhat the model sees in place of the tool result, or the text of the ended turn.
agents.retry

agents.retry

def agents.retry(feedback: str) -> HookDecision

Discard the model's response and call the model again with feedback.

ParameterTypeDefaultDescription
feedbackstrrequiredWhat the model reads before it answers again.
agents.reject

agents.reject

def agents.reject(reason: str) -> HookDecision

Reject the model's response and end the turn with reason.

ParameterTypeDefaultDescription
reasonstrrequiredThe text the turn ends with.
agents.hook

agents.hook

What a hook gets at each point and returns: continue, or replace the input or output.

A hook that continues unchanged returns None; one that stops returns agents.skip, agents.retry or agents.reject.

Its classes are under Classes of agents.hook.

State

State

class State(*, type: str, state: dict[str, JsonValue])

The saved form of a hook or sandbox: its type, and the JSON data it keeps across turns.

ParameterTypeDefaultDescription
typestrrequiredThe type that rebuilds the value, as module:QualifiedName.
statedict[str, JsonValue]requiredThe value's saved data: a hook's fields, or what a sandbox hook's SandboxHook.to_unified_state() returns.
Classes of agents.hook

Classes of agents.hook

hook.PreAgentTurn

hook.PreAgentTurn

class PreAgentTurn(*, turn_id: str, user_content: list[ContentBlock])

The turn a pre_agent_turn hook receives.

ParameterTypeDefaultDescription
turn_idstrrequiredThe turn's ID.
user_contentlist[ContentBlock]requiredThe user's content for the turn. Blocks handed back unchanged reach the model as they came.
hook.PreLlmCall

hook.PreLlmCall

class PreLlmCall(*, turn_id: str)

The model call a pre_llm_call hook receives.

ParameterTypeDefaultDescription
turn_idstrrequiredThe turn's ID.
hook.PostLlmCall

hook.PostLlmCall

class PostLlmCall(
    *,
    turn_id: str,
    content: list[ContentBlock],
    text: str,
    tool_calls: tuple[ToolCall, ...],
    reasoning: str,
    finish_reason: Literal['stop', 'tool_call', 'length', 'content_filter', 'other'],
    usage: TokenUsage | None,
)

The model reply a post_llm_call hook receives.

ParameterTypeDefaultDescription
turn_idstrrequiredThe turn's ID.
contentlist[ContentBlock]requiredThe reply's content blocks, in order, without its reasoning and tool calls.
textstrrequiredThe reply's text blocks joined, "" when it has none.
tool_callstuple[ToolCall, ...]requiredThe tool calls the reply makes. name is the name the model called, such as get_weather.
reasoningstrrequiredThe reply's reasoning text joined, "" when it has none.
finish_reasonLiteral['stop', 'tool_call', 'length', 'content_filter', 'other']requiredWhy the model stopped.
usageTokenUsage | NonerequiredThe tokens the model call used, when the provider reports them.
hook.PostAgentTurn

hook.PostAgentTurn

class PostAgentTurn(
    *,
    turn_id: str,
    content: list[ContentBlock],
    text: str,
    tool_calls: tuple[ToolCall, ...],
    reasoning: str,
    finish_reason: Literal['stop', 'tool_call', 'length', 'content_filter', 'other'],
    usage: TokenUsage | None,
)

The final answer of the turn a post_agent_turn hook receives.

ParameterTypeDefaultDescription
turn_idstrrequiredThe turn's ID.
contentlist[ContentBlock]requiredThe reply's content blocks, in order, without its reasoning and tool calls.
textstrrequiredThe reply's text blocks joined, "" when it has none.
tool_callstuple[ToolCall, ...]requiredThe tool calls the reply makes. name is the name the model called, such as get_weather.
reasoningstrrequiredThe reply's reasoning text joined, "" when it has none.
finish_reasonLiteral['stop', 'tool_call', 'length', 'content_filter', 'other']requiredWhy the model stopped.
usageTokenUsage | NonerequiredThe tokens the model call used, when the provider reports them.
hook.PreToolCall

hook.PreToolCall

class PreToolCall(
    *,
    turn_id: str,
    tool_name: str,
    tool_id: str,
    tool_call_id: str,
    arguments: dict[str, JsonValue],
)

The tool call a pre_tool_call hook receives.

ParameterTypeDefaultDescription
turn_idstrrequiredThe turn's ID.
tool_namestrrequiredThe authored tool's name, or the built-in's, such as file_system.bash.
tool_idstrrequiredThe tool's ID: <namespace>.<name>, such as billing.charge, or the built-in's name.
tool_call_idstrrequiredThe call's ID, as ToolCallEntry.tool_call_id and ToolCallbackContext.tool_call_id give it.
argumentsdict[str, JsonValue]requiredThe arguments the model produced.
hook.PostToolCall

hook.PostToolCall

class PostToolCall(
    *,
    turn_id: str,
    tool_name: str,
    tool_id: str,
    tool_call_id: str,
    arguments: dict[str, JsonValue],
    tool_result: ToolResult,
)

The tool call and result a post_tool_call hook receives.

Inherits turn_id, tool_name, tool_id and tool_call_id from hook.PreToolCall.

ParameterTypeDefaultDescription
argumentsdict[str, JsonValue]requiredThe arguments the tool ran with, after any pre_tool_call hook changed them.
tool_resultToolResultrequiredThe call's result. Return it, or a copy, in hook.PostToolCallHookContinue: blocks handed back unchanged reach the model as they came, and a failed call kept is_error=True keeps its error.
hook.PreAgentTurnHookContinue

hook.PreAgentTurnHookContinue

class PreAgentTurnHookContinue(*, user_content: Sequence[ContentBlock])

What pre_agent_turn returns to start the turn with other user content.

ParameterTypeDefaultDescription
user_contentSequence[ContentBlock]requiredThe content the model sees in place of the user's message.
hook.PreAgentTurnHookSkip

hook.PreAgentTurnHookSkip

class PreAgentTurnHookSkip(*, reason: Sequence[ContentBlock] = [])

What pre_agent_turn returns to end the turn before the model runs, as agents.skip does.

ParameterTypeDefaultDescription
reasonSequence[ContentBlock][]The text the turn ends with.
hook.PreLlmCallHookContinue

hook.PreLlmCallHookContinue

class PreLlmCallHookContinue()

What pre_llm_call returns to let the model call run, as None does.

hook.PreLlmCallHookSkip

hook.PreLlmCallHookSkip

class PreLlmCallHookSkip(*, reason: Sequence[ContentBlock] = [])

What pre_llm_call returns to end the turn instead of calling the model, as agents.skip does.

ParameterTypeDefaultDescription
reasonSequence[ContentBlock][]The text the turn ends with.
hook.PostLlmCallHookAccept

hook.PostLlmCallHookAccept

class PostLlmCallHookAccept(*, acceptance: ReplaceAssistantContent = ...)

What post_llm_call returns to keep the model's response, or to replace its content.

ParameterTypeDefaultDescription
acceptanceReplaceAssistantContent...The default keeps the response as the model gave it. hook.ReplaceAssistantContent(content=[...]) replaces its content.
hook.PostLlmCallHookRetry

hook.PostLlmCallHookRetry

class PostLlmCallHookRetry(*, feedback: Sequence[ContentBlock])

What post_llm_call returns to drop the response and call the model again, as agents.retry does.

ParameterTypeDefaultDescription
feedbackSequence[ContentBlock]requiredWhat the model reads before it answers again.
hook.PostLlmCallHookReject

hook.PostLlmCallHookReject

class PostLlmCallHookReject(*, reason: Sequence[ContentBlock])

What post_llm_call returns to reject the response and end the turn, as agents.reject does.

ParameterTypeDefaultDescription
reasonSequence[ContentBlock]requiredThe text the turn ends with.
hook.PreToolCallHookContinue

hook.PreToolCallHookContinue

class PreToolCallHookContinue(*, effective_arguments: dict[str, JsonValue] = {})

What pre_tool_call returns to run the tool with other arguments. Pass effective_arguments=; with none, the tool runs with no arguments.

ParameterTypeDefaultDescription
effective_argumentsdict[str, JsonValue]{}The arguments the tool runs with, in place of the model's. The default, {}, runs it with no arguments.
hook.PreToolCallHookSkip

hook.PreToolCallHookSkip

class PreToolCallHookSkip(*, reason: Sequence[ContentBlock] = [])

What pre_tool_call returns to skip the call, as agents.skip does.

ParameterTypeDefaultDescription
reasonSequence[ContentBlock][]What the model sees in place of the tool result.
hook.PostToolCallHookContinue

hook.PostToolCallHookContinue

class PostToolCallHookContinue(*, tool_result: ToolResult)

What post_tool_call returns to give the model another tool result.

ParameterTypeDefaultDescription
tool_resultToolResultrequiredThe result the model gets for the call.
hook.PostAgentTurnHookAccept

hook.PostAgentTurnHookAccept

class PostAgentTurnHookAccept(*, acceptance: ReplaceAssistantContent = ...)

What post_agent_turn returns to keep the final answer, or to replace its content.

ParameterTypeDefaultDescription
acceptanceReplaceAssistantContent...The default keeps the answer as the model gave it. hook.ReplaceAssistantContent(content=[...]) replaces its content.
hook.ReplaceAssistantContent

hook.ReplaceAssistantContent

class ReplaceAssistantContent(*, content: Sequence[ContentBlock])

Replace the model's reply with content, from post_llm_call or post_agent_turn.

ParameterTypeDefaultDescription
contentSequence[ContentBlock]requiredThe content in place of the model's reply, such as [agents.TextContentBlock(text="...")]; at least one block.
Ready-made hooks

Ready-made hooks

pattern.hook.StructuredOutputHook

pattern.hook.StructuredOutputHook

class StructuredOutputHook[T](
    *,
    tools: Sequence[PythonTool[..., Any] | ClientTool[..., Any]] = (),
    **data: Any,
)

Validate the final answer of each turn with a Pydantic model, and ask the model to correct it.

Name the Pydantic model in brackets, as in StructuredOutputHook[City](max_retries=2), or subclass StructuredOutputHook[City] and set new defaults for its fields.

The hook asks for a correction only while max_retries allows it and the turn has an iteration left under the agent's max_iterations. At that limit it accepts the last answer, or, when on_limit is "reject", raises ValueError, which fails the turn. Set schema_in_prompt to False to leave the JSON Schema out of the user message, for example when output_type already gives it to the model; corrections still include it. Set enabled to False to let answers through unchecked.

The hook counts each model call before it is made, so a call that a guardrail or an earlier hook retries still counts toward max_iterations.

Based on Hook.

ParameterTypeDefaultDescription
toolsSequence[PythonTool[..., Any] | ClientTool[..., Any]]()The tools that the hook adds to the agent's tools.
**dataAny{}The values of the hook's fields.
AttributeTypeDescription
max_retriesintHow many corrections the hook asks for in one turn. Default: 2.
on_limitLiteral['accept', 'reject']What the hook does at the limit: "accept", the default, keeps the last answer; "reject" raises ValueError, which fails the turn.
schema_in_promptboolWhether the user message includes the JSON Schema. Default: True. Corrections always include it.
enabledboolWhether the hook checks answers. Default: True. False lets them through unchecked.
Contexts

Contexts

CallbackContext

CallbackContext

class CallbackContext

What a callback gets as ctx: the session it runs in and the session's sandbox.

The shared base: a hook method gets a HookCallbackContext, and a tool a ToolCallbackContext.

AttributeTypeDescription
sessionCallbackSessionThe session the callback runs in.
sandboxHookSandboxThe session's sandbox, to run commands and read and write files. await ctx.sandbox.execute(command, cwd=None, timeout_seconds=None, env=None) runs a command once and returns a SandboxExecutionResult. await ctx.sandbox.read_file(path, max_bytes=1048576) returns a file's bytes. A relative path is under the workspace. A file larger than max_bytes raises an error, and a missing one raises FileNotFoundError. await ctx.sandbox.write_file(name, content) writes bytes to a file in a folder the sandbox keeps for hook files, outside the workspace, and returns its path. An absolute name, or one that leaves that folder, raises ValueError. In a sandbox hook of an agent that agents serve or agents deploy runs, content must be UTF-8 text and the request, path included, must fit in 1 MiB of JSON. Each method raises RuntimeError when the session has no sandbox that runs commands.
CallbackSession

CallbackSession

class CallbackSession

The session a callback runs in: its ID and the turn's.

AttributeTypeDescription
idstrThe session's ID.
turn_idstrThe ID of the turn the callback runs in.
HookCallbackContext

HookCallbackContext

class HookCallbackContext(CallbackContext)

What a hook method gets as ctx: the session it runs in and the session's sandbox.

ToolCallbackContext

ToolCallbackContext

class ToolCallbackContext(CallbackContext)

What a tool gets as its first, positional-only parameter: the session, its sandbox and the call.

A tool takes it by type, under any name: def search(ctx: agents.ToolCallbackContext, /, query: str). The model never sees it. A direct call can pass ToolCallbackContext.local(), or leave it out to get that local context. A client tool's answer gets it too, with no sandbox, so the methods of ctx.sandbox raise RuntimeError.

AttributeTypeDescription
tool_call_idstrThe ID of the model's call to the tool, as in the session's tool call entry.
ToolCallbackContext.local

ToolCallbackContext.local

@classmethod
def local() -> ToolCallbackContext

A context for a call outside any session: every ID is "local" and the sandbox is unbound.

ApprovalCallbackContext

ApprovalCallbackContext

class ApprovalCallbackContext(CallbackContext)

What an approval handler gets as ctx: the session that asked, and the approval's ID.

ctx.session.id and ctx.session.turn_id name the session and turn that asked: a subagent's approval has the subagent's session and its own turn there. ctx.callback_id is the approval's ID, the one turn.answer takes. The handler runs in your program, so the methods of ctx.sandbox raise RuntimeError.

AttributeTypeDescription
callback_idstrThe approval's ID, the one turn.answer takes.
SandboxCallbackContext

SandboxCallbackContext

class SandboxCallbackContext

Context a sandbox hook receives in on_create and on_destroy.

AttributeTypeDescription
sandboxHookSandboxThe sandbox, to run commands and read and write files in it.
Same values when the loop runs again

Same values when the loop runs again

agents.now

agents.now

def agents.now() -> datetime

The current time in UTC, as a timezone-aware datetime.

Use it instead of datetime.now(). In the agent loop of a deployed agent, such as in a custom sandbox's methods or a SandboxHook, it gets the same time when the agent runs the loop again to resume a session, so a deadline holds. In a tool, a Hook or a local run, it is the clock's time: tools and Hook methods run as recorded steps, outside the part of the loop a deployed agent replays.

agents.sleep

agents.sleep

async def agents.sleep(duration: timedelta | float, *, summary: str | None = None) -> None

Wait for duration, in the agent loop, a tool, a Hook or a local run.

Use it instead of asyncio.sleep(). In the agent loop of a deployed agent, such as in a custom sandbox's methods or a SandboxHook, the wait is a timer on the server: it survives a restart of the agent, and nothing of the agent runs while it waits. Tools and Hook methods run as recorded steps, outside the part of the loop a deployed agent replays: there the wait must end within the step's time limit. In a local run, it is asyncio.sleep().

ParameterTypeDefaultDescription
durationtimedelta | floatrequiredHow long to wait, as a timedelta or in seconds.
summarystr | NoneNoneA label for the wait in the agent loop of a deployed agent. Ignored elsewhere.
Raises
SdkErrorWhen the wait of a tool or a Hook would outlast the step's time limit.
agents.uuid4

agents.uuid4

def agents.uuid4() -> UUID

A random UUID that stays the same when a deployed agent runs the agent loop again.

Use it instead of uuid.uuid4(). In a tool, a Hook or a local run, it is uuid.uuid4().

agents.random

agents.random

def agents.random() -> Random

A random number generator that gives the same numbers when a deployed agent runs the loop again.

Use it instead of the random module. It has methods such as random, uniform, choice and shuffle. In a tool, a Hook or a local run, it is a new random.Random.