Pydantic AI API¶
Install threvo-actions[pydantic-ai] before importing this module.
pydantic_ai ¶
Pydantic AI Capability for confirm-first actions.
SafeReference
module-attribute
¶
SafeReference = Annotated[str, StringConstraints(min_length=1, max_length=255), AfterValidator(_validate_safe_reference)]
CommandContraT
module-attribute
¶
_TOOL_NAME_PATTERN
module-attribute
¶
DEFAULT_INTERNAL_ACTION_ARGUMENTS
module-attribute
¶
DEFAULT_INTERNAL_ACTION_ARGUMENTS = frozenset({'authority_evidence', 'organization_id', 'private_snapshot', 'proposal_reference', 'request_id', 'snapshot', 'tenant_reference', 'user_id'})
__all__
module-attribute
¶
__all__ = ['ActionAgentContext', 'ActionCapability', 'ActionContextResolver', 'ActionRecoveryToolBinding', 'ActionRecoveryToolRequest', 'ActionRecoveryToolResult', 'ActionToolBinding', 'ActionToolFailureHandler', 'ActionToolResult', 'DeferredActionRequest', 'DEFAULT_INTERNAL_ACTION_ARGUMENTS', 'ExistingToolActionBinding', 'InlineAuthorityHandler', 'IntegrationOutcome', 'ScopedActionToolBinding', 'build_existing_tool_action_toolset']
ActionApplication ¶
Bases: Generic[DepsT]
Minimal registration catalog for experimental action declarations.
register ¶
register(specification: ActionSpec[CommandT, PrivateSnapshotT, PreviewT, ResultT], recipe: ActionRecipe[DepsT, CommandT, PrivateSnapshotT, PreviewT, ResultT]) -> RegisteredAction[CommandT, PrivateSnapshotT, PreviewT, ResultT]
inspect ¶
inspect(action: RegisteredAction[CommandT, PrivateSnapshotT, PreviewT, ResultT]) -> ActionInspection
bind ¶
bind(action: RegisteredAction[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, dependencies: DepsT) -> Iterator[BoundAction[CommandT, PrivateSnapshotT, PreviewT, ResultT]]
RegisteredAction
dataclass
¶
RegisteredAction(action_type: ActionType, _registration_id: int, _application_token: object)
Bases: Generic[CommandT, PrivateSnapshotT, PreviewT, ResultT]
Typed static handle returned by explicit registration.
ActionType ¶
EvidenceConsumer ¶
Bases: ExperimentalModel
ExperimentalModel ¶
LifecycleStatus ¶
ProposingAgent ¶
Bases: ExperimentalModel
RequestingPrincipal ¶
Bases: ExperimentalModel
kind
class-attribute
instance-attribute
¶
ActionRecoveryView ¶
Bases: ActionModel
Versioned, read-only explanation of one proposal's recovery state.
schema_version
class-attribute
instance-attribute
¶
next_verification_at
class-attribute
instance-attribute
¶
max_verification_attempts
class-attribute
instance-attribute
¶
last_verification_status
class-attribute
instance-attribute
¶
last_verification_status: VerificationReceiptStatus | None = None
recommended_steps
class-attribute
instance-attribute
¶
ActionDefinition
dataclass
¶
ActionDefinition(action_type: ActionType, command_model: type[CommandT], private_snapshot_model: type[PrivateSnapshotT], display_preview_model: type[PreviewT], result_model: type[ResultT], preparation: PreparationPort[CommandT, PrivateSnapshotT, PreviewT], authorization: AuthorizationPort[CommandT, PrivateSnapshotT], authority_evaluator: AuthorityEvaluatorPort, state_resolver: StateResolverPort[PrivateSnapshotT, PreviewT], executor: GovernedExecutorPort[PrivateSnapshotT, ResultT], verifier: VerifierPort[ResultT], commitment_provider: CommitmentProviderPort, protection_codec: ProtectionCodecPort, retention: RetentionPort, proposal_ttl: timedelta, executor_identity: GovernedExecutor, target_identity: AuthoritativeTarget, authority_audience: str, authority_channel_assurance: str, recovery_authorization: RecoveryAuthorizationPort | None = None, verification_delay: timedelta = timedelta(0), max_verification_attempts: int = 3, effect_kind: EffectKind = 'single', allow_resend_after_final_absence: bool = False, verification_lease_duration: timedelta = timedelta(minutes=1), semantic_idempotency_strategy: Literal['host_defined'] = 'host_defined')
Bases: Generic[CommandT, PrivateSnapshotT, PreviewT, ResultT]
recovery_authorization
class-attribute
instance-attribute
¶
recovery_authorization: RecoveryAuthorizationPort | None = None
verification_delay
class-attribute
instance-attribute
¶
allow_resend_after_final_absence
class-attribute
instance-attribute
¶
verification_lease_duration
class-attribute
instance-attribute
¶
semantic_idempotency_strategy
class-attribute
instance-attribute
¶
ReadContext ¶
Bases: ExperimentalModel
ActionOperationResult ¶
Bases: ExperimentalModel
display_preview
class-attribute
instance-attribute
¶
fresh_proposal_reference
class-attribute
instance-attribute
¶
fresh_proposal_reference: SafeReference | None = None
is_terminal
property
¶
Whether this proposal has no reconciliation or recovery path.
automatic_processing_closed
property
¶
Whether unattended processing should stop for this proposal.
needs_reconciliation
property
¶
Whether authoritative reconciliation may advance this proposal.
ActionRuntime ¶
ActionRuntime(*, store: ActionStore, retention_store: RetentionStore | None = None, clock: Clock | None = None, identifiers: IdentifierProvider | None = None, event_sink: EventSink | None = None, runtime_revision: str | None = None)
Coordinates host-owned controls without owning host business truth.
prepare
async
¶
prepare(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, tenant_reference: str, command: CommandT, requesting_principal: RequestingPrincipal, proposing_agent: ProposingAgent | None = None, proposal_reference: str | None = None) -> ActionOperationResult
record_authority
async
¶
record_authority(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, evidence: AuthorityEvidence, authenticated_authority: ConfirmingAuthority, proposal_reference: str | None = None) -> ActionOperationResult
expire_due
async
¶
expire_due(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, tenant_reference: str, proposal_reference: str) -> ActionOperationResult
Expire an unexecuted proposal once its prepared lifetime has elapsed.
execute
async
¶
execute(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, tenant_reference: str, proposal_reference: str) -> ActionOperationResult
reconcile
async
¶
reconcile(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, tenant_reference: str, proposal_reference: str) -> ActionOperationResult
resume_verification
async
¶
resume_verification(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, tenant_reference: str, proposal_reference: str, expected_revision: int, operator: RecoveryOperator, intervention_reference: str) -> ActionOperationResult
Resume observation after a host operator resolves an external ambiguity.
This transition never calls the executor. It records the intervention, advances an unresolved or waiting verification state, and immediately performs one fresh authoritative observation through the action verifier.
read
async
¶
read(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, proposal_reference: str, context: ReadContext) -> ProposalView
read_recovery
async
¶
read_recovery(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, proposal_reference: str, context: ReadContext) -> ActionRecoveryView
Describe safe recovery options without granting authority or mutating state.
export_evidence
async
¶
export_evidence(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, proposal_reference: str, context: ReadContext) -> ActionEvidenceBundle
Export one authorized, minimized proposal revision.
observation_context
async
¶
observation_context(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, proposal_reference: str, context: ReadContext) -> ExecutionContext
Authorize a read-only target observation and bind it to stored identity.
erase
async
¶
erase(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], *, proposal_reference: str, context: ReadContext) -> ActionOperationResult
AuthorizationDeniedError ¶
Bases: PermissionError
OperationOutcome ¶
ProposalView ¶
Bases: ExperimentalModel
ActionAgentContext ¶
IntegrationOutcome ¶
ActionToolResult ¶
Bases: ExperimentalModel
Display-safe result returned to the model after a continuation attempt.
proposal_reference
class-attribute
instance-attribute
¶
proposal_reference: SafeReference | None = None
lifecycle_status
class-attribute
instance-attribute
¶
lifecycle_status: LifecycleStatus | None = None
display_preview
class-attribute
instance-attribute
¶
display_preview: JsonObject = Field(default_factory=dict)
fresh_proposal_reference
class-attribute
instance-attribute
¶
fresh_proposal_reference: SafeReference | None = None
ActionRecoveryToolRequest ¶
Bases: ExperimentalModel
ActionRecoveryToolResult ¶
Bases: ExperimentalModel
DeferredActionRequest ¶
ActionContextResolver ¶
Bases: Protocol[DepsContraT]
InlineAuthorityHandler ¶
Bases: Protocol[DepsContraT]
ActionToolFailureHandler ¶
Bases: Protocol
Host-controlled diagnostics for failures hidden from a model caller.
ExistingToolActionBinding
dataclass
¶
ExistingToolActionBinding(name: str, action_type: ActionType, forbidden_model_arguments: frozenset[str] = DEFAULT_INTERNAL_ACTION_ARGUMENTS)
Bind a host's existing model tool to a durable action identity.
This is the small, brownfield layer: the host keeps its established tool function and confirmation record while the binding makes approval suspension explicit and prevents internal action material from becoming model-controlled input.
forbidden_model_arguments
class-attribute
instance-attribute
¶
forbidden_model_arguments: frozenset[str] = DEFAULT_INTERNAL_ACTION_ARGUMENTS
_ContinuationMetadata ¶
Bases: ExperimentalModel
_BuildableBinding ¶
Bases: Protocol[DepsContraT]
_ActionOperations ¶
Bases: Protocol[CommandContraT]
prepare
async
¶
prepare(*, tenant_reference: str, command: CommandContraT, requesting_principal: RequestingPrincipal, proposing_agent: ProposingAgent | None = None) -> ActionOperationResult
reconcile
async
¶
reconcile(*, tenant_reference: str, proposal_reference: str) -> ActionOperationResult
_FixedActionOperations
dataclass
¶
_FixedActionOperations(runtime: ActionRuntime, definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT])
Bases: Generic[CommandT, PrivateSnapshotT, PreviewT, ResultT]
definition
instance-attribute
¶
definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT]
prepare
async
¶
prepare(*, tenant_reference: str, command: CommandT, requesting_principal: RequestingPrincipal, proposing_agent: ProposingAgent | None = None) -> ActionOperationResult
reconcile
async
¶
reconcile(*, tenant_reference: str, proposal_reference: str) -> ActionOperationResult
ActionToolBinding
dataclass
¶
ActionToolBinding(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], context_resolver: ActionContextResolver[DepsT], name: str, description: str, binding_failure_handler: ActionToolFailureHandler | None = None)
Bases: Generic[DepsT, CommandT, PrivateSnapshotT, PreviewT, ResultT]
Explicitly binds one action definition to one model-visible tool.
definition
instance-attribute
¶
definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT]
binding_failure_handler
class-attribute
instance-attribute
¶
binding_failure_handler: ActionToolFailureHandler | None = None
ActionRecoveryToolBinding
dataclass
¶
ActionRecoveryToolBinding(definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT], context_resolver: ActionContextResolver[DepsT], name: str, description: str)
Bases: Generic[DepsT, CommandT, PrivateSnapshotT, PreviewT, ResultT]
Opt-in read-only recovery tool for one fixed action definition.
definition
instance-attribute
¶
definition: ActionDefinition[CommandT, PrivateSnapshotT, PreviewT, ResultT]
ScopedActionToolBinding
dataclass
¶
ScopedActionToolBinding(application: ActionApplication[ScopedDepsT], action: RegisteredAction[CommandT, PrivateSnapshotT, PreviewT, ResultT], dependency_scope: Callable[[DepsT], AbstractAsyncContextManager[ScopedDepsT]], context_resolver: ActionContextResolver[ScopedDepsT], name: str, description: str, binding_failure_handler: ActionToolFailureHandler | None = None)
Bases: Generic[DepsT, ScopedDepsT, CommandT, PrivateSnapshotT, PreviewT, ResultT]
Bind one registered action through fresh host dependencies per tool call.
dependency_scope
instance-attribute
¶
dependency_scope: Callable[[DepsT], AbstractAsyncContextManager[ScopedDepsT]]
binding_failure_handler
class-attribute
instance-attribute
¶
binding_failure_handler: ActionToolFailureHandler | None = None
ActionCapability
dataclass
¶
ActionCapability(*, bindings: Sequence[_BuildableBinding[DepsT]], runtime: ActionRuntime | None = None, inline_authority_handler: InlineAuthorityHandler[DepsT] | None = None, id: str = 'threvo_actions')
Bases: AbstractCapability[DepsT]
Expose confirm-first actions without trusting framework approval as authority.
build_continuation_results ¶
build_continuation_results(requests: DeferredToolRequests, *, decisions: Mapping[str, bool]) -> DeferredToolResults
Build framework continuations while preserving safe proposal metadata.
build_existing_tool_action_toolset ¶
build_existing_tool_action_toolset(*, bindings: Sequence[ExistingToolActionBinding], executors: Mapping[str, ToolFuncEither[DepsT, ...]], id: str = 'threvo_actions_existing_tools') -> FunctionToolset[DepsT]
Add approval suspension to validated host-owned tool functions.
Pydantic AI approval remains routing metadata. The tool itself must create and later execute its durable action through the normal runtime authority checks.
_report_tool_failure ¶
_report_tool_failure(handler: ActionToolFailureHandler | None, failure: BaseException, *, action_type: ActionType, tool_name: str) -> None
_contains_json_float_for_decimal ¶
Detect JSON numbers that would lose precision at Decimal boundaries.
_invoke_action_tool
async
¶
_invoke_action_tool(*, approved: bool, continuation_value: object, arguments: dict[str, object], command_model: type[CommandT], action_type: ActionType, operations: _ActionOperations[CommandT], trusted: ActionAgentContext, tool_name: str) -> ActionToolResult | _ContinuationMetadata