Skip to content

cayu.runtime.loop_policies

Public Cayu API. Definitions are grouped by their public source module, and definitions from private implementation modules appear on their package’s page; adding a symbol does not move existing links. The import shown at each entry is a supported public namespace. Read the Python API overview and install the required extra.

from cayu import BeforeStopAction

Bases: StrEnum.

Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.

Name Type Default
COMPLETE class attribute 'complete'
CONTINUE class attribute 'continue'
INTERRUPT class attribute 'interrupt'
FAIL class attribute 'fail'

Release source · Runtime guarantees · Capability guides

from cayu import BeforeStopContext

Immutable context passed to loop policies at the before-stop boundary.

BeforeStopContext.__init__(*, session: Session, step_result: AssistantStepResult, classification: StepClassification, step: int, max_steps: int, metadata: dict[str, Any], messages: Sequence[Message]=(), continuation_message_indices: Iterable[int]=()) -> None
BeforeStopContext.session() -> Session
BeforeStopContext.step_result() -> AssistantStepResult
BeforeStopContext.classification() -> StepClassification
BeforeStopContext.step() -> int
BeforeStopContext.max_steps() -> int
BeforeStopContext.metadata() -> dict[str, Any]
BeforeStopContext.messages() -> tuple[Message, ...]

Durable conversation messages at this boundary, oldest first.

Includes tool results and runtime-authored continuation messages. An empty model step that produced nothing is not a message and is absent.

BeforeStopContext.continuation_message_indices() -> frozenset[int]

Positions of this policy’s retained, durably appended continuation sequence.

Release source · Runtime guarantees · Capability guides

from cayu import BeforeStopDecision

Control decision returned before Cayu marks a no-tool-call step complete.

Bases: BaseModel.

Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.

Name Type Default
action BeforeStopAction BeforeStopAction.COMPLETE
reason str 'complete'
message Message | None None
metadata dict[str, Any] Field(default_factory=dict)
BeforeStopDecision.complete(reason: str='complete', **metadata: Any) -> BeforeStopDecision
BeforeStopDecision.continue_with(message: Message, *, reason: str='continue', metadata: dict[str, Any] | None=None) -> BeforeStopDecision
BeforeStopDecision.interrupt(reason: str, *, metadata: dict[str, Any] | None=None) -> BeforeStopDecision
BeforeStopDecision.fail(reason: str, *, metadata: dict[str, Any] | None=None) -> BeforeStopDecision
BeforeStopDecision.validate_reason(value: str, info) -> str
BeforeStopDecision.copy_message(value: Message | None) -> Message | None
BeforeStopDecision.copy_metadata(value: dict[str, Any]) -> dict[str, Any]
BeforeStopDecision.validate_action_payload() -> BeforeStopDecision

Release source · Runtime guarantees · Capability guides

from cayu import LoopPolicy
LoopPolicy.execution_profile_identity() -> ExecutionProfileBehaviorIdentity | None

Return a stable application declaration, or None when non-portable.

LoopPolicy.name() -> str
LoopPolicy.adoption_replay_identity() -> str | None

Return stable, versioned identity for explicit profile-adoption replay.

Stateful request policies must override this property when they can be used with ResumeRequest.profile_adoption. The identity must change whenever configuration that can affect policy behavior changes. A missing identity fails that combination closed without affecting ordinary run or resume requests.

async LoopPolicy.before_stop(context: BeforeStopContext) -> BeforeStopDecision

Run when the model step has no tool calls and Cayu is about to complete.

Release source · Runtime guarantees · Capability guides

from cayu import RequireFinalTool

Keep a turn going until one of tool_names has returned without error.

Some agents must end every turn through a specific tool, for example a clarification question or a recorded proposal. Models occasionally stop before calling one, sometimes with an empty step. This policy appends a reminder and lets the model continue, up to max_reminders times, and then interrupts (or fails) the session with a reason instead of completing it.

The turn is read from the durable conversation: messages after the latest user message other than this policy’s own durably receipted reminder. Matching reminder text in a real user message still starts a new turn. A tool result counts when its tool_name is listed and is_error is false, so tools should return is_error=True for failures. The policy keeps no state between calls; continuation provenance is checkpointed with each reminder so counts survive restarts and recovery.

Bases: LoopPolicy.

RequireFinalTool.execution_profile_identity() -> ExecutionProfileBehaviorIdentity
RequireFinalTool.name() -> str
RequireFinalTool.adoption_replay_identity() -> str
async RequireFinalTool.before_stop(context: BeforeStopContext) -> BeforeStopDecision
RequireFinalTool.__init__(tool_names: Iterable[str], *, reminder: str | None=None, max_reminders: int=2, on_exhausted: BeforeStopAction=BeforeStopAction.INTERRUPT) -> None
RequireFinalTool.tool_names() -> tuple[str, ...]

Release source · Runtime guarantees · Capability guides