spakky-agent¶
spakky-agent는 Agent workflow를 Spakky 컴포넌트로 모델링하기 위한 계약, 도구, 상태, signal, evidence 타입을 제공합니다.
Agentic Hexagonal Architecture의 core 계약입니다.
설치¶
spakky-agent는 @Agent, AgentExecutionSpec, AgentYield, AgentState,
AgentSignal, AgentEvidence, IAgentModel, @agent_tool, context/safety/recovery,
delegation 타입 같은 public contract를 소유합니다. 이 패키지는 의도적으로 vLLM,
SQLAlchemy, FastAPI, Typer를 import하지 않습니다. 운영에서 durable execution을 사용하려면
spakky-sqlalchemy[agent] 같은 provider contribution의 repository 구현이 필요하며,
운영용 in-memory fallback은 제공하지 않습니다.
Public API¶
Agentic hexagonal architecture contracts for Spakky Framework.
Message = Progress
module-attribute
¶
Backward-compatible progress-yield payload alias.
TextDelta = Token
module-attribute
¶
Backward-compatible token-yield payload alias.
PLUGIN_NAME = Plugin(name='spakky-agent')
module-attribute
¶
Plugin identifier for the Spakky Agent package.
AgentCancellationCleanupCallable = Callable[[AgentCancellationRequest], Awaitable[AgentCancellationCleanupResult]]
¶
Async hook shape invoked for model stream/tool/delegate cancellation cleanup.
JsonObject = Mapping[str, JsonValue]
¶
JSON object payload used by public agent contracts.
JsonPrimitive = bool | float | int | str | None
¶
Scalar JSON value accepted by agent public contracts.
JsonValue = JsonPrimitive | Mapping[str, JsonValue] | Sequence[JsonValue]
¶
Recursive JSON-compatible value used at model, signal, and evidence boundaries.
AbstractSpakkyAgentError
¶
AgentBootstrapError
¶
AgentDefinitionError
¶
AgentModelConfigurationError
¶
AgentOutputGuardError
¶
AgentPersistenceConfigurationError
¶
AgentToolBindingError
¶
ContextDigest(id, context_identity, source_manifest_ref, digest, derived_from_pack_ids=tuple(), compression_evidence_ref=None, algorithm=None, summary=None, created_at=None, metadata=dict())
dataclass
¶
Derived compression evidence for a context identity.
ContextFreshness
¶
Bases: StrEnum
Freshness classification for context rot and budget decisions.
ContextHealthSignal(id, symptom, manifest_ref=None, pack_id=None, evidence_ref=None, score=None, observed_at=None, metadata=dict())
dataclass
¶
Observed context rot signal used to choose optimization actions.
evidence_payload()
¶
Return JSON-compatible signal metadata for append-only evidence.
Source code in core/spakky-agent/src/spakky/agent/context.py
ContextManifest(id, entries, origin_ref=None, evidence_refs=tuple(), created_at=None, metadata=dict())
dataclass
¶
Auditable composition record for model input context packs.
ContextManifestEntry(pack_id, source, role, origin_ref, evidence_ref=None, digest_ref=None, sensitive_fields=(), metadata=dict())
dataclass
¶
One audited pack entry inside a context manifest.
ContextOptimizationAction(id, kind, signal_refs=tuple(), target_pack_ids=tuple(), manifest_ref=None, digest_ref=None, delegation_ref=None, result_evidence_ref=None, reason=None, metadata=dict())
dataclass
¶
Selected optimization action derived from context health signals.
evidence_payload()
¶
Return JSON-compatible action metadata without raw context contents.
Source code in core/spakky-agent/src/spakky/agent/context.py
ContextOptimizationActionKind
¶
Bases: StrEnum
Optimization actions that can be selected from context health signals.
ContextOptimizationEvidenceStage
¶
Bases: StrEnum
Where an optimization action evidence item sits in the agent flow.
ContextPack(id, content, source, role, freshness=ContextFreshness.UNKNOWN, relevance=None, token_budget=ContextTokenBudget(), sensitivity=ContextSensitivity.INTERNAL, sensitive_fields=(), metadata=dict())
dataclass
¶
LLM-facing context unit derived from state, signal, or evidence.
guarded_content(policy=None)
¶
Return deterministic model-safe content for this context pack.
Source code in core/spakky-agent/src/spakky/agent/context.py
message_metadata(policy=None)
¶
Return non-content metadata for provider-neutral model messages.
Source code in core/spakky-agent/src/spakky/agent/context.py
ContextPackRole
¶
Bases: StrEnum
Semantic role of a context pack inside a model request.
ContextRotSymptom
¶
Bases: StrEnum
Typed context rot symptoms observed before model input assembly.
ContextSensitivity
¶
Bases: StrEnum
Deterministic sensitivity metadata carried before model input.
ContextTokenBudget(max_tokens=None, estimated_tokens=None, reserved_output_tokens=None)
dataclass
¶
Token budget allocated to one context pack.
IAgentContextHandler
¶
Bases: ABC
Select context optimization actions from health signals and manifests.
select_optimization_actions(signals, manifest)
abstractmethod
¶
Return optimization actions without mutating raw evidence.
Source code in core/spakky-agent/src/spakky/agent/context.py
AgentCancellationCleanupReport(state_id, signal_id, outcomes=())
dataclass
¶
Aggregate cleanup evidence for one CANCEL signal.
cleanup_succeeded
property
¶
Return whether all cleanup hooks completed without failure.
failed_outcomes
property
¶
Return the hook outcomes that force FAILED terminal state.
__post_init__()
¶
Reject reports that cannot be attached to state and signal evidence.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
to_payload()
¶
Serialize the report for state metadata and evidence payloads.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
to_evidence_candidate(*, summary=None)
¶
Represent cancellation cleanup as append-only evidence.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
AgentCancellationCleanupResult(target_kind, target_ref, status, reason=None, error_code=None, message=None, metadata=dict())
dataclass
¶
Result returned by one cancellation cleanup hook.
failed_cleanup
property
¶
Return whether this hook prevents a clean CANCELLED terminal state.
__post_init__()
¶
Reject outcomes that cannot be correlated with the cleanup target.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
succeeded(*, target_kind, target_ref, reason=None, metadata=None)
classmethod
¶
Record a cleanup hook that released its target.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
failed(*, target_kind, target_ref, error_code, message, metadata=None)
classmethod
¶
Record a cleanup hook that could not release its target.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
skipped(*, target_kind, target_ref, reason, metadata=None)
classmethod
¶
Record a cleanup target that was already inactive or unavailable.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
to_payload()
¶
Serialize this hook outcome into evidence/state metadata.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
AgentCancellationCleanupStatus
¶
Bases: StrEnum
Outcome of one cancellation cleanup hook.
AgentCancellationCleanupTask(target_kind, target_ref, cleanup, metadata=dict())
dataclass
¶
One cleanup hook registered for a running cancellation target.
__post_init__()
¶
Reject hooks that cannot be identified in cleanup evidence.
run(*, state, signal)
async
¶
Invoke the hook and verify that it reports the same target.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
AgentCancellationRequest(state_id, signal_id, target_kind, target_ref, reason=None, requested_by=None, metadata=dict())
dataclass
¶
Cancellation request passed to a model stream, tool, or delegate hook.
__post_init__()
¶
Reject requests that cannot be traced back to state/signal/target.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
from_signal(*, state, signal, target_kind, target_ref, metadata=None)
classmethod
¶
Build a hook request from the durable CANCEL signal payload.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
to_payload()
¶
Serialize the request into append-only evidence metadata.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
AgentCancellationTargetKind
¶
Bases: StrEnum
Running execution target that can receive a cancellation cleanup hook.
AgentEvidence(id, agent_state_id, kind, payload=dict(), summary=None, digest=None, manifest_ref=None, reference=None, sensitive_fields=(), created_at=None)
dataclass
¶
Append-only artifact captured during an agent execution.
AgentEvidenceCandidate(kind, payload=dict(), summary=None, digest=None, manifest_ref=None, reference=None, sensitive_fields=())
dataclass
¶
Append-only evidence candidate before repository id assignment.
tool_result(*, tool_identity, tool_schema_name, result, capture, sensitive_fields=(), exposure_policy=None, summary=None)
classmethod
¶
Create evidence metadata for a captured tool result.
Source code in core/spakky-agent/src/spakky/agent/evidence.py
model_decision(*, model, decision, summary=None)
classmethod
¶
Create evidence metadata for a model decision.
Source code in core/spakky-agent/src/spakky/agent/evidence.py
tool_decision(*, tool_identity, decision, summary=None)
classmethod
¶
Create evidence metadata for a tool-routing decision.
Source code in core/spakky-agent/src/spakky/agent/evidence.py
context_optimization(*, action, stage, signals=(), summary=None)
classmethod
¶
Create before/after evidence for a context optimization action.
Source code in core/spakky-agent/src/spakky/agent/evidence.py
to_evidence(*, evidence_id, agent_state_id, created_at=None)
¶
Assign repository identity while preserving append-only contents.
Source code in core/spakky-agent/src/spakky/agent/evidence.py
AgentEvidenceKind
¶
Bases: StrEnum
Kinds of append-only evidence captured by agent execution.
AgentApprovalBoundaryKind
¶
Bases: StrEnum
Action boundaries where orchestration may require human approval.
AgentApprovalDecisionOutcome(request_id, decision, status, transition, reason=None, modified_payload=dict(), comment=None)
dataclass
¶
Typed result of an approval decision signal.
AgentApprovalPlan(action, request=None, state=None, yield_item=None)
dataclass
¶
Plan for an action boundary before executing it.
requires_approval
property
¶
Return whether orchestration must wait for a HITL decision.
AgentApprovalPlanAction
¶
Bases: StrEnum
Approval plan outcome before an action boundary is executed.
AgentApprovalRequest(id, agent_state_id, boundary, prompt, risk, action_ref, allowed_decisions=DEFAULT_APPROVAL_DECISIONS, metadata=dict())
dataclass
¶
Approval request materialized at a risky action boundary.
__post_init__()
¶
Reject approval requests that cannot be matched by a signal.
Source code in core/spakky-agent/src/spakky/agent/approval.py
from_tool_descriptor(*, approval_id, agent_state_id, descriptor, prompt=None, call_id=None, metadata=None)
classmethod
¶
Build an approval request from a risky tool descriptor.
Source code in core/spakky-agent/src/spakky/agent/approval.py
to_state(*, agent_type)
¶
Materialize the approval wait as interrupted lifecycle state.
Source code in core/spakky-agent/src/spakky/agent/approval.py
to_yield()
¶
Expose this approval request to an inbound adapter stream.
Source code in core/spakky-agent/src/spakky/agent/approval.py
to_metadata()
¶
Return JSON-compatible metadata for state, yield, and evidence.
Source code in core/spakky-agent/src/spakky/agent/approval.py
AgentActionBoundaryCheckpoint(action_id, action_kind, stage, idempotency=Idempotency.UNKNOWN, metadata=dict())
dataclass
¶
Serializable checkpoint recorded before or after one external action.
__post_init__()
¶
Reject checkpoints that cannot be correlated after restart.
before_model_call(action_id, *, idempotency=Idempotency.UNKNOWN, metadata=None)
classmethod
¶
Create the checkpoint recorded before a model call is attempted.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
after_model_call(action_id, *, idempotency=Idempotency.UNKNOWN, metadata=None)
classmethod
¶
Create the checkpoint recorded after a model call completes.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
before_tool_call(action_id, *, idempotency, metadata=None)
classmethod
¶
Create the checkpoint recorded before a tool call is attempted.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
after_tool_call(action_id, *, idempotency, metadata=None)
classmethod
¶
Create the checkpoint recorded after a tool call completes.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
before_approval_wait(action_id, *, metadata=None)
classmethod
¶
Create the checkpoint recorded before waiting for approval.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
after_approval_wait(action_id, *, metadata=None)
classmethod
¶
Create the checkpoint recorded after an approval wait resolves.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
to_evidence_candidate(*, summary=None)
¶
Represent this checkpoint as append-only evidence.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
AgentActionBoundaryStage
¶
Bases: StrEnum
Checkpoint side recorded around an action boundary.
AgentActionKind
¶
Bases: StrEnum
Recoverable external action classes in an agent execution.
AgentResumeAction
¶
Bases: StrEnum
Orchestration action selected from persisted checkpoint evidence.
AgentResumeBoundary(action_id, action_kind, stage, idempotency, evidence_id)
dataclass
¶
Last action boundary reconstructed from append-only evidence.
AgentResumePlan(state, action, boundary=None, signals=())
dataclass
¶
AgentDelegateTarget(agent_type, agent_name=None, metadata=dict())
dataclass
¶
First-class delegate target represented by another @Agent component.
__post_init__()
¶
Reject delegate targets that cannot identify an agent component.
Source code in core/spakky-agent/src/spakky/agent/delegation.py
DelegationBudget(max_steps=None, max_tokens=None, timeout_seconds=None, deadline_at=None, metadata=dict())
dataclass
¶
Budget metadata attached to a delegation packet.
__post_init__()
¶
Reject delegation budgets that cannot be enforced consistently.
Source code in core/spakky-agent/src/spakky/agent/delegation.py
DelegationContextSlice(summary=None, evidence_refs=(), manifest_ref=None, metadata=dict())
dataclass
¶
Minimal parent context projected for a child agent.
DelegationExpectedOutput(description=None, schema=dict(), metadata=dict())
dataclass
¶
Expected child output description and optional JSON schema.
DelegationPacket(id, parent_agent_state_id, target, task, context=DelegationContextSlice(), constraints=(), expected_output=DelegationExpectedOutput(), budget=DelegationBudget(), allowed_capabilities=(), return_policy=DelegationReturnPolicy.SUMMARY_AND_EVIDENCE, metadata=dict())
dataclass
¶
Task packet passed from a parent agent to a delegate agent.
__post_init__()
¶
Reject delegation packets without parent linkage or task identity.
Source code in core/spakky-agent/src/spakky/agent/delegation.py
DelegationResult(id, packet_id, target, summary, output=None, evidence_refs=(), metadata=dict(), created_at=None)
dataclass
¶
Child agent result projected back to the parent execution.
__post_init__()
¶
Reject delegated results that cannot be linked to a packet.
Source code in core/spakky-agent/src/spakky/agent/delegation.py
to_parent_evidence(*, evidence_id, parent_agent_state_id)
¶
Represent a delegated result as append-only parent evidence.
Source code in core/spakky-agent/src/spakky/agent/delegation.py
to_parent_yield(*, evidence_id, parent_agent_state_id)
¶
Expose the delegated result on the parent's AgentYield stream.
Source code in core/spakky-agent/src/spakky/agent/delegation.py
DelegationReturnPolicy
¶
Bases: StrEnum
How a child agent result should be projected back to the parent.
IAgentDelegate
¶
Bases: ABC
Execution hook that runs a delegation packet against a delegate target.
delegate(packet)
abstractmethod
¶
Execute delegation without prescribing spawn topology or transport.
Agent(spec=AgentExecutionSpec(), *, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Pod
UseCase-equivalent Pod stereotype for agentic workflow components.
validate_bootstrap()
¶
Re-run definition validation during application bootstrap.
required_persistence_repository_types()
¶
Return repository ports required by this Agent's durable path.
Source code in core/spakky-agent/src/spakky/agent/execution.py
AgentExecutionLimits(timeout_seconds=None)
dataclass
¶
Bounded execution limits declared outside infrastructure capabilities.
__post_init__()
¶
Reject limits that would fail later at bootstrap.
AgentExecutionSpec(name=None, objective=None, accepted_signals=(), recovery=RecoveryStrategy.NONE, streaming_exposure_mode=StreamingExposureMode.BALANCED, timeout_seconds=None, limits=AgentExecutionLimits(), delegation_allowed=False, metadata=dict())
dataclass
¶
Declarative execution semantics that cannot be inferred from DI alone.
__post_init__()
¶
Reject execution specs that would fail later at bootstrap.
Source code in core/spakky-agent/src/spakky/agent/execution.py
AgentSignalKind
¶
Bases: StrEnum
Inbound stimulus kinds that an agent may accept while running.
RecoveryStrategy
¶
Bases: StrEnum
Recovery strategy requested by an agent execution contract.
StreamingExposureMode
¶
Bases: StrEnum
Streaming output guard profile exposed by agent execution.
IAgentEvidenceRepository
¶
IAgentSignalRepository
¶
IAgentStateRepository
¶
Bases: ABC
Materialized state repository for long-running agent executions.
get(state_id)
abstractmethod
¶
get_or_none(state_id)
abstractmethod
¶
save(state)
abstractmethod
¶
list_by_status(status)
abstractmethod
¶
Return states matching an externally observable lifecycle status.
list_resume_candidates()
abstractmethod
¶
Return active or interrupted states that may resume after restart.
IAgentModel
¶
JsonSchemaConstraint(schema, strict=True)
dataclass
¶
JSON schema constraint shared by structured output and tool calling.
ModelError(code, message, retryable=False, metadata=dict())
dataclass
¶
Provider-neutral model failure payload.
ModelMessage(role, content, metadata=dict())
dataclass
¶
Provider-neutral model message.
ModelMessageRole
¶
Bases: StrEnum
Roles accepted by provider-neutral model messages.
ModelRequest(messages, context=tuple(), context_manifest=None, context_digest=None, structured_output=None, tool_calling=None, sampling=SamplingOptions(), streaming=StreamingOptions(), metadata=dict())
dataclass
¶
Provider-neutral request passed to an agent model adapter.
assemble_messages(policy=None)
¶
Assemble prompt messages from typed context packs without concatenation.
Source code in core/spakky-agent/src/spakky/agent/interfaces/model.py
ModelResponse(content, structured_output=None, tool_calls=tuple(), usage=ModelUsage(), metadata=dict())
dataclass
¶
Provider-neutral non-streaming model response.
guarded(sensitive_fields, policy=None)
¶
Return a copy with sensitive output payloads deterministically guarded.
Source code in core/spakky-agent/src/spakky/agent/interfaces/model.py
ModelStreamEvent(kind, token_delta=None, tool_call=None, structured_output=None, error=None, usage=None, metadata=dict())
dataclass
¶
Provider-neutral model streaming event.
guarded(sensitive_fields, policy=None)
¶
Return a copy with sensitive streaming payloads guarded.
Source code in core/spakky-agent/src/spakky/agent/interfaces/model.py
ModelStreamEventKind
¶
Bases: StrEnum
Provider-neutral streaming event kinds emitted by a model adapter.
ModelToolCall(name, arguments, call_id=None, metadata=dict())
dataclass
¶
Tool invocation candidate emitted by a model adapter.
guarded(sensitive_fields, policy=None)
¶
Return a copy with sensitive argument values deterministically guarded.
Source code in core/spakky-agent/src/spakky/agent/interfaces/model.py
ModelToolChoice
¶
Bases: StrEnum
Provider-neutral tool calling strategy requested from a model adapter.
ModelToolSpec(name, parameters, description=None, metadata=dict())
dataclass
¶
LLM-facing tool descriptor normalized by agent tooling.
ModelUsage(input_tokens=None, output_tokens=None, total_tokens=None)
dataclass
¶
Token accounting reported by a model adapter.
SamplingOptions(temperature=None, top_p=None, max_tokens=None)
dataclass
¶
Portable model sampling options.
StreamingOptions(include_usage=True, include_progress=True)
dataclass
¶
Portable model streaming options.
StructuredOutputSpec(constraint, output_type_name=None)
dataclass
¶
Structured output contract requested from a model adapter.
ToolCallingSpec(tools, choice=ModelToolChoice.AUTO)
dataclass
¶
Tool calling contract requested from a model adapter.
AgentSignal(id, agent_state_id, kind, payload=dict(), created_at=None)
dataclass
¶
Inbound stimulus appended for an agent execution.
ApprovalDecision
¶
Bases: StrEnum
Human-in-the-loop approval outcomes.
AgentSignalConsumptionBatch(state_id, poll_point, signals)
dataclass
¶
Signals consumed during one non-blocking poll.
consumed_count
property
¶
Return the number of signals consumed by this poll.
AgentSignalPollPoint
¶
Bases: StrEnum
Places where orchestration may poll durable signals without waiting.
ContextExposurePolicy(include_pii_values=False, include_sensitive_values=False, include_sensitive_schema_metadata=False, include_sensitive_context_metadata=False)
dataclass
¶
Policy for LLM-facing context and schema metadata exposure.
can_expose_value(field)
¶
Return whether a sensitive value may cross the model boundary.
Source code in core/spakky-agent/src/spakky/agent/safety.py
CredentialRef(id, provider=None)
dataclass
¶
Reference to a credential outside LLM-facing context.
__post_init__()
¶
Reject blank credential references.
DataSensitivity
¶
Bases: StrEnum
Canonical sensitivity classes carried by descriptors.
EvidenceExposurePolicy(include_pii_values=False, include_sensitive_values=False, include_sensitive_metadata=True)
dataclass
¶
Policy for evidence payload exposure before append-only capture.
can_expose_value(field)
¶
Return whether a sensitive value may be stored in evidence payloads.
Source code in core/spakky-agent/src/spakky/agent/safety.py
MaskingPolicy
¶
Bases: StrEnum
Deterministic text masking strategies for sensitive values.
PII
¶
Bases: StrEnum
PII categories that can be declared with typing.Annotated.
RedactionPolicy
¶
Bases: StrEnum
Boundary action used when a value must not be exposed.
SecretField(redaction=RedactionPolicy.REFERENCE_ONLY, label=None, metadata=dict())
dataclass
¶
typing.Annotated metadata for values that must never be model text.
sensitivity
property
¶
Return the normalized sensitivity class.
__post_init__()
¶
guard_text(value)
¶
to_metadata()
¶
Serialize marker metadata without including the secret value.
Source code in core/spakky-agent/src/spakky/agent/safety.py
SecretRef(id, credential=None)
dataclass
¶
Opaque reference to a secret value stored outside model context.
SensitiveField(category, masking=MaskingPolicy.REDACT, redaction=RedactionPolicy.REDACT, label=None, metadata=dict())
dataclass
¶
typing.Annotated metadata for deterministic sensitive-field handling.
sensitivity
property
¶
Return the normalized sensitivity class.
category_name
property
¶
Return the stable public category name.
__post_init__()
¶
guard_text(value)
¶
Return deterministic model/evidence-safe text for this field.
to_metadata()
¶
Serialize marker metadata without including the sensitive value.
Source code in core/spakky-agent/src/spakky/agent/safety.py
SensitiveFieldDescriptor(path, field)
dataclass
¶
Path-bound sensitive metadata extracted from Annotated types.
to_metadata()
¶
Serialize descriptor metadata without leaking the field value.
StreamingGuardFailureMode
¶
Bases: StrEnum
Final audit behavior when a streaming guard missed a raw candidate.
StreamingRedactionAudit(status, detected_count, redacted_count, missed_matches, buffer_size, emitted_char_count, original_char_count)
dataclass
¶
Final aggregate audit for a bounded streaming redaction session.
missed_count
property
¶
Return the number of raw candidates still present after streaming.
to_evidence_payload()
¶
Serialize audit evidence without raw streamed content.
Source code in core/spakky-agent/src/spakky/agent/safety.py
to_error_payload()
¶
Serialize a typed error payload for stream consumers.
Source code in core/spakky-agent/src/spakky/agent/safety.py
StreamingRedactionAuditStatus
¶
Bases: StrEnum
Final aggregate streaming redaction audit status.
StreamingRedactionMatch(pattern_name, start, end, metadata=dict())
dataclass
¶
Sanitized final-audit match location for a missed redaction candidate.
to_payload()
¶
Serialize a match without the sensitive value itself.
Source code in core/spakky-agent/src/spakky/agent/safety.py
StreamingRedactionPolicy(patterns, buffer_size=64, emit_chunk_size=None, failure_mode=StreamingGuardFailureMode.RAISE)
dataclass
¶
Bounded buffering policy balancing stream latency and redaction correctness.
__post_init__()
¶
Reject policies that would make the guard unbounded or silent.
Source code in core/spakky-agent/src/spakky/agent/safety.py
StreamingRedactionResult(chunks, audit=None, error=None)
dataclass
¶
Output produced by a bounded streaming redaction step.
StreamingRedactionSession(policy)
¶
Stateful bounded redactor for model token streams.
Source code in core/spakky-agent/src/spakky/agent/safety.py
push(chunk)
¶
Redact one token chunk and emit only the safe bounded prefix.
Source code in core/spakky-agent/src/spakky/agent/safety.py
finish()
¶
Flush the remaining buffer and run the mandatory final audit.
Source code in core/spakky-agent/src/spakky/agent/safety.py
StreamingSensitivePattern(name, pattern, replacement=REDACTED_VALUE, metadata=dict())
dataclass
¶
Caller-supplied deterministic pattern used by streaming redaction.
__post_init__()
¶
Reject blank names and invalid pattern syntax before streaming starts.
Source code in core/spakky-agent/src/spakky/agent/safety.py
redact(value)
¶
Return redacted text and the number of replacements applied.
find_matches(value)
¶
Return sanitized match locations without exposing raw text.
Source code in core/spakky-agent/src/spakky/agent/safety.py
AgentState(id, agent_type, status, transition=None, reason=None, current_activity=None, input_ref=None, output_ref=None, pending_signal_count=0, last_event_cursor=None, recovery_marker=None, metadata=dict(), created_at=None, updated_at=None)
dataclass
¶
Materialized state for a long-running agent execution.
__post_init__()
¶
Reject state snapshots that cannot represent a real queue count.
AgentStateReason
¶
Bases: StrEnum
Structured reason that refines an externally observable lifecycle state.
AgentStateTransition
¶
Bases: StrEnum
State transition vocabulary accepted by durable agent orchestration.
AgentStatus
¶
Bases: StrEnum
Externally observable lifecycle states for an agent execution.
AgentToolCatalog(descriptors=())
dataclass
¶
Deterministic catalog of descriptors discovered from an Agent class.
__post_init__()
¶
Reject duplicate identity or schema names before model lookup.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
by_identity(identity)
¶
Lookup a descriptor by typed identity.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
by_schema_name(schema_name)
¶
Lookup a descriptor by model-facing schema name.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
AgentToolBoundInvocation(args=(), kwargs=dict())
dataclass
¶
Python-call-ready tool invocation arguments.
AgentToolDefinition(name, schema_name, description=None, metadata=AgentToolMetadata())
dataclass
¶
Method-level metadata attached by @agent_tool before owner discovery.
__post_init__()
¶
Reject definitions that would make catalog lookup ambiguous.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
AgentToolDescriptor(identity, owner, callable, schema, description=None, metadata=AgentToolMetadata())
dataclass
¶
AgentToolIdentity(owner_module, owner_qualname, name)
dataclass
¶
AgentToolMetadata(permissions=(), effects=ToolEffects(), idempotency=Idempotency.UNKNOWN, data_access=DataAccess.NONE, externality=Externality.LOCAL, timeout=TimeoutPolicy(), result_budget=ResultBudget(), evidence=EvidenceCapture.NONE, approval=ToolApprovalRequirement.DERIVED)
dataclass
¶
Typed approval, idempotency, and evidence metadata for a descriptor.
AgentToolSchemaHandle(name, input_schema_name, output_schema_name, input_schema=dict(), output_schema=dict(), input_sensitive_fields=(), output_sensitive_fields=())
dataclass
¶
Stable schema names and generated JSON schemas owned by a descriptor.
__post_init__()
¶
Reject blank schema handles.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
input_schema_for(policy=None)
¶
Return model-facing input schema under the requested exposure policy.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
output_schema_for(policy=None)
¶
Return model-facing output schema under the requested exposure policy.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
DataAccess
¶
Bases: StrEnum
Data access level declared by a tool.
EvidenceCapture
¶
Bases: StrEnum
Evidence capture strategy for tool results.
Externality
¶
Bases: StrEnum
External side-effect boundary declared by a tool.
Idempotency
¶
Bases: StrEnum
Action idempotency declared by a tool.
ResultBudget(max_bytes=None)
dataclass
¶
Optional result-size budget for model-facing tool output.
__post_init__()
¶
Reject result budgets that cannot constrain output.
TimeoutPolicy(seconds=None)
dataclass
¶
Optional timeout boundary for a tool invocation.
__post_init__()
¶
Reject non-positive timeout policies at definition time.
ToolApprovalRequirement
¶
Bases: StrEnum
Human approval requirement at the tool boundary.
ToolEffects(data_access=DataAccess.NONE, externality=Externality.LOCAL, destructive=False, network=False)
dataclass
¶
Typed effect metadata used to derive display risk outside core.
read_only()
classmethod
¶
write_state()
classmethod
¶
external_side_effect()
classmethod
¶
Declare a tool that crosses an external side-effect boundary.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
destructive_action()
classmethod
¶
Declare a tool that may irreversibly mutate local or external state.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
ToolPermission(name)
dataclass
¶
Typed permission marker attached to a tool descriptor.
__post_init__()
¶
Reject permission names that cannot be matched deterministically.
ToolResumeAction
¶
Bases: StrEnum
Resume action allowed by stored tool idempotency metadata.
ToolResumeMetadata(idempotency=Idempotency.UNKNOWN)
dataclass
¶
Stored idempotency metadata used when resuming an incomplete action.
from_metadata(metadata)
classmethod
¶
Build resume metadata from a tool descriptor metadata object.
action_for_completed_boundary()
¶
Return the resume action for an already completed action boundary.
action_for_incomplete_boundary()
¶
Return the resume action for an incomplete action boundary.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
ToolRisk(axes=())
dataclass
¶
Derived typed risk axes for policy and evidence annotations.
requires_approval_candidate
property
¶
Return whether the risk is strong enough to suggest HITL approval.
__post_init__()
¶
Reject duplicate axes so risk comparisons stay deterministic.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
from_metadata(metadata)
classmethod
¶
Derive risk axes from source tool metadata.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
ToolRiskAxis
¶
Bases: StrEnum
Derived risk axes exposed for policy and UI decisions.
AgentYield(kind, payload)
dataclass
¶
Typed stream item returned from an agent execute generator.
AgentYieldKind
¶
Bases: StrEnum
Canonical public vocabulary yielded by agent execution.
Approval(id, prompt, allowed_decisions, metadata)
dataclass
¶
Approval request surfaced to the inbound adapter.
Cancel(reason=None, requested_by=None, metadata=dict())
dataclass
¶
Cancellation acknowledgement surfaced to the caller.
Error(code, message, retryable=False, metadata=dict())
dataclass
¶
Recoverable or terminal execution error surfaced to the caller.
Evidence(evidence, metadata=dict())
dataclass
¶
Evidence item surfaced to the inbound adapter.
Final(output, metadata)
dataclass
¶
Final output carried by a generator stream.
Progress(message, current_step=None, metadata=dict())
dataclass
¶
Agent progress update intended for direct inbound adapter consumption.
Token(text, metadata=dict())
dataclass
¶
Incremental model token intended for streaming clients.
Tool(name, call_id=None, arguments=dict(), result=None, metadata=dict())
dataclass
¶
Tool call or tool result surfaced by agent execution.
begin_agent_cancellation(state, signal)
¶
Materialize receipt of a CANCEL signal as CANCELLING state.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
complete_agent_cancellation(state, report)
¶
Resolve CANCELLING state into CANCELLED or FAILED cleanup outcome.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
run_agent_cancellation_cleanup(*, state, signal, tasks)
async
¶
Invoke model stream/tool/delegate cleanup hooks for a CANCEL signal.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
materialize_agent_approval_decision_state(current, outcome)
¶
Apply a typed approval decision outcome to an existing state snapshot.
Source code in core/spakky-agent/src/spakky/agent/approval.py
parse_agent_approval_decision_signal(signal, *, request=None)
¶
Parse an approval decision signal into a typed workflow outcome.
Source code in core/spakky-agent/src/spakky/agent/approval.py
plan_agent_tool_approval(*, descriptor, approval_id, agent_state_id, agent_type, prompt=None, call_id=None, metadata=None)
¶
Plan whether a tool invocation should proceed or wait for approval.
Source code in core/spakky-agent/src/spakky/agent/approval.py
plan_agent_resume(state, evidence, signals=())
¶
Restore the next resume action using only persisted state and evidence.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
consume_pending_agent_signals(repository, state_id, *, poll_point=AgentSignalPollPoint.SAFE_BOUNDARY, accepted_signals=None, max_signals=None)
¶
Consume currently pending signals without sleeping or waiting for new input.
The repository remains responsible for durable queue ordering. This helper consumes only the eligible prefix of the pending queue so later signals never overtake an earlier unaccepted signal.
Source code in core/spakky-agent/src/spakky/agent/signal_consumption.py
agent_tool(*, name=None, schema_name=None, description=None, permissions=(), effects=None, idempotency=Idempotency.UNKNOWN, data_access=None, externality=None, timeout=None, result_budget=None, evidence=EvidenceCapture.NONE, approval=ToolApprovalRequirement.DERIVED)
¶
Attach typed agent-tool metadata to a method object.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
bind_agent_tool_invocation(function, payload)
¶
Bind a structured model payload to a tool function signature.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
discover_agent_tools(owner)
¶
Discover @agent_tool methods in deterministic class-definition order.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
실행¶
Agent execution metadata contracts.
RecoveryStrategy
¶
Bases: StrEnum
Recovery strategy requested by an agent execution contract.
StreamingExposureMode
¶
Bases: StrEnum
Streaming output guard profile exposed by agent execution.
AgentSignalKind
¶
Bases: StrEnum
Inbound stimulus kinds that an agent may accept while running.
AgentExecutionLimits(timeout_seconds=None)
dataclass
¶
Bounded execution limits declared outside infrastructure capabilities.
__post_init__()
¶
Reject limits that would fail later at bootstrap.
AgentExecutionSpec(name=None, objective=None, accepted_signals=(), recovery=RecoveryStrategy.NONE, streaming_exposure_mode=StreamingExposureMode.BALANCED, timeout_seconds=None, limits=AgentExecutionLimits(), delegation_allowed=False, metadata=dict())
dataclass
¶
Declarative execution semantics that cannot be inferred from DI alone.
__post_init__()
¶
Reject execution specs that would fail later at bootstrap.
Source code in core/spakky-agent/src/spakky/agent/execution.py
Agent(spec=AgentExecutionSpec(), *, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Pod
UseCase-equivalent Pod stereotype for agentic workflow components.
validate_bootstrap()
¶
Re-run definition validation during application bootstrap.
required_persistence_repository_types()
¶
Return repository ports required by this Agent's durable path.
Source code in core/spakky-agent/src/spakky/agent/execution.py
State¶
Agent lifecycle state contracts.
AgentStatus
¶
Bases: StrEnum
Externally observable lifecycle states for an agent execution.
AgentStateTransition
¶
Bases: StrEnum
State transition vocabulary accepted by durable agent orchestration.
AgentStateReason
¶
Bases: StrEnum
Structured reason that refines an externally observable lifecycle state.
AgentState(id, agent_type, status, transition=None, reason=None, current_activity=None, input_ref=None, output_ref=None, pending_signal_count=0, last_event_cursor=None, recovery_marker=None, metadata=dict(), created_at=None, updated_at=None)
dataclass
¶
Materialized state for a long-running agent execution.
__post_init__()
¶
Reject state snapshots that cannot represent a real queue count.
Signal¶
Non-blocking consumption helpers for durable agent signals.
AgentSignalPollPoint
¶
Bases: StrEnum
Places where orchestration may poll durable signals without waiting.
AgentSignalConsumptionBatch(state_id, poll_point, signals)
dataclass
¶
Signals consumed during one non-blocking poll.
consumed_count
property
¶
Return the number of signals consumed by this poll.
consume_pending_agent_signals(repository, state_id, *, poll_point=AgentSignalPollPoint.SAFE_BOUNDARY, accepted_signals=None, max_signals=None)
¶
Consume currently pending signals without sleeping or waiting for new input.
The repository remains responsible for durable queue ordering. This helper consumes only the eligible prefix of the pending queue so later signals never overtake an earlier unaccepted signal.
Source code in core/spakky-agent/src/spakky/agent/signal_consumption.py
Evidence¶
Agent evidence contracts.
AgentEvidenceKind
¶
Bases: StrEnum
Kinds of append-only evidence captured by agent execution.
AgentEvidence(id, agent_state_id, kind, payload=dict(), summary=None, digest=None, manifest_ref=None, reference=None, sensitive_fields=(), created_at=None)
dataclass
¶
Append-only artifact captured during an agent execution.
AgentEvidenceCandidate(kind, payload=dict(), summary=None, digest=None, manifest_ref=None, reference=None, sensitive_fields=())
dataclass
¶
Append-only evidence candidate before repository id assignment.
tool_result(*, tool_identity, tool_schema_name, result, capture, sensitive_fields=(), exposure_policy=None, summary=None)
classmethod
¶
Create evidence metadata for a captured tool result.
Source code in core/spakky-agent/src/spakky/agent/evidence.py
model_decision(*, model, decision, summary=None)
classmethod
¶
Create evidence metadata for a model decision.
Source code in core/spakky-agent/src/spakky/agent/evidence.py
tool_decision(*, tool_identity, decision, summary=None)
classmethod
¶
Create evidence metadata for a tool-routing decision.
Source code in core/spakky-agent/src/spakky/agent/evidence.py
context_optimization(*, action, stage, signals=(), summary=None)
classmethod
¶
Create before/after evidence for a context optimization action.
Source code in core/spakky-agent/src/spakky/agent/evidence.py
to_evidence(*, evidence_id, agent_state_id, created_at=None)
¶
Assign repository identity while preserving append-only contents.
Source code in core/spakky-agent/src/spakky/agent/evidence.py
Context¶
Typed context contracts for agent model input assembly.
ContextPackRole
¶
Bases: StrEnum
Semantic role of a context pack inside a model request.
ContextFreshness
¶
Bases: StrEnum
Freshness classification for context rot and budget decisions.
ContextSensitivity
¶
Bases: StrEnum
Deterministic sensitivity metadata carried before model input.
ContextRotSymptom
¶
Bases: StrEnum
Typed context rot symptoms observed before model input assembly.
ContextOptimizationActionKind
¶
Bases: StrEnum
Optimization actions that can be selected from context health signals.
ContextOptimizationEvidenceStage
¶
Bases: StrEnum
Where an optimization action evidence item sits in the agent flow.
ContextTokenBudget(max_tokens=None, estimated_tokens=None, reserved_output_tokens=None)
dataclass
¶
Token budget allocated to one context pack.
ContextHealthSignal(id, symptom, manifest_ref=None, pack_id=None, evidence_ref=None, score=None, observed_at=None, metadata=dict())
dataclass
¶
Observed context rot signal used to choose optimization actions.
evidence_payload()
¶
Return JSON-compatible signal metadata for append-only evidence.
Source code in core/spakky-agent/src/spakky/agent/context.py
ContextOptimizationAction(id, kind, signal_refs=tuple(), target_pack_ids=tuple(), manifest_ref=None, digest_ref=None, delegation_ref=None, result_evidence_ref=None, reason=None, metadata=dict())
dataclass
¶
Selected optimization action derived from context health signals.
evidence_payload()
¶
Return JSON-compatible action metadata without raw context contents.
Source code in core/spakky-agent/src/spakky/agent/context.py
IAgentContextHandler
¶
Bases: ABC
Select context optimization actions from health signals and manifests.
select_optimization_actions(signals, manifest)
abstractmethod
¶
Return optimization actions without mutating raw evidence.
Source code in core/spakky-agent/src/spakky/agent/context.py
ContextPack(id, content, source, role, freshness=ContextFreshness.UNKNOWN, relevance=None, token_budget=ContextTokenBudget(), sensitivity=ContextSensitivity.INTERNAL, sensitive_fields=(), metadata=dict())
dataclass
¶
LLM-facing context unit derived from state, signal, or evidence.
guarded_content(policy=None)
¶
Return deterministic model-safe content for this context pack.
Source code in core/spakky-agent/src/spakky/agent/context.py
message_metadata(policy=None)
¶
Return non-content metadata for provider-neutral model messages.
Source code in core/spakky-agent/src/spakky/agent/context.py
ContextManifestEntry(pack_id, source, role, origin_ref, evidence_ref=None, digest_ref=None, sensitive_fields=(), metadata=dict())
dataclass
¶
One audited pack entry inside a context manifest.
ContextManifest(id, entries, origin_ref=None, evidence_refs=tuple(), created_at=None, metadata=dict())
dataclass
¶
Auditable composition record for model input context packs.
ContextDigest(id, context_identity, source_manifest_ref, digest, derived_from_pack_ids=tuple(), compression_evidence_ref=None, algorithm=None, summary=None, created_at=None, metadata=dict())
dataclass
¶
Derived compression evidence for a context identity.
Recovery¶
Action-boundary recovery contracts for durable agent execution.
AgentActionKind
¶
Bases: StrEnum
Recoverable external action classes in an agent execution.
AgentActionBoundaryStage
¶
Bases: StrEnum
Checkpoint side recorded around an action boundary.
AgentResumeAction
¶
Bases: StrEnum
Orchestration action selected from persisted checkpoint evidence.
AgentActionBoundaryCheckpoint(action_id, action_kind, stage, idempotency=Idempotency.UNKNOWN, metadata=dict())
dataclass
¶
Serializable checkpoint recorded before or after one external action.
__post_init__()
¶
Reject checkpoints that cannot be correlated after restart.
before_model_call(action_id, *, idempotency=Idempotency.UNKNOWN, metadata=None)
classmethod
¶
Create the checkpoint recorded before a model call is attempted.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
after_model_call(action_id, *, idempotency=Idempotency.UNKNOWN, metadata=None)
classmethod
¶
Create the checkpoint recorded after a model call completes.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
before_tool_call(action_id, *, idempotency, metadata=None)
classmethod
¶
Create the checkpoint recorded before a tool call is attempted.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
after_tool_call(action_id, *, idempotency, metadata=None)
classmethod
¶
Create the checkpoint recorded after a tool call completes.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
before_approval_wait(action_id, *, metadata=None)
classmethod
¶
Create the checkpoint recorded before waiting for approval.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
after_approval_wait(action_id, *, metadata=None)
classmethod
¶
Create the checkpoint recorded after an approval wait resolves.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
to_evidence_candidate(*, summary=None)
¶
Represent this checkpoint as append-only evidence.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
AgentResumeBoundary(action_id, action_kind, stage, idempotency, evidence_id)
dataclass
¶
Last action boundary reconstructed from append-only evidence.
AgentResumePlan(state, action, boundary=None, signals=())
dataclass
¶
plan_agent_resume(state, evidence, signals=())
¶
Restore the next resume action using only persisted state and evidence.
Source code in core/spakky-agent/src/spakky/agent/recovery.py
Approval¶
Human-in-the-loop approval workflow contracts.
AgentApprovalBoundaryKind
¶
Bases: StrEnum
Action boundaries where orchestration may require human approval.
AgentApprovalPlanAction
¶
Bases: StrEnum
Approval plan outcome before an action boundary is executed.
AgentApprovalRequest(id, agent_state_id, boundary, prompt, risk, action_ref, allowed_decisions=DEFAULT_APPROVAL_DECISIONS, metadata=dict())
dataclass
¶
Approval request materialized at a risky action boundary.
__post_init__()
¶
Reject approval requests that cannot be matched by a signal.
Source code in core/spakky-agent/src/spakky/agent/approval.py
from_tool_descriptor(*, approval_id, agent_state_id, descriptor, prompt=None, call_id=None, metadata=None)
classmethod
¶
Build an approval request from a risky tool descriptor.
Source code in core/spakky-agent/src/spakky/agent/approval.py
to_state(*, agent_type)
¶
Materialize the approval wait as interrupted lifecycle state.
Source code in core/spakky-agent/src/spakky/agent/approval.py
to_yield()
¶
Expose this approval request to an inbound adapter stream.
Source code in core/spakky-agent/src/spakky/agent/approval.py
to_metadata()
¶
Return JSON-compatible metadata for state, yield, and evidence.
Source code in core/spakky-agent/src/spakky/agent/approval.py
AgentApprovalPlan(action, request=None, state=None, yield_item=None)
dataclass
¶
Plan for an action boundary before executing it.
requires_approval
property
¶
Return whether orchestration must wait for a HITL decision.
AgentApprovalDecisionOutcome(request_id, decision, status, transition, reason=None, modified_payload=dict(), comment=None)
dataclass
¶
Typed result of an approval decision signal.
plan_agent_tool_approval(*, descriptor, approval_id, agent_state_id, agent_type, prompt=None, call_id=None, metadata=None)
¶
Plan whether a tool invocation should proceed or wait for approval.
Source code in core/spakky-agent/src/spakky/agent/approval.py
parse_agent_approval_decision_signal(signal, *, request=None)
¶
Parse an approval decision signal into a typed workflow outcome.
Source code in core/spakky-agent/src/spakky/agent/approval.py
materialize_agent_approval_decision_state(current, outcome)
¶
Apply a typed approval decision outcome to an existing state snapshot.
Source code in core/spakky-agent/src/spakky/agent/approval.py
Cancellation¶
Cancellation lifecycle and cleanup contracts for agent execution.
AgentCancellationCleanupCallable = Callable[[AgentCancellationRequest], Awaitable[AgentCancellationCleanupResult]]
¶
Async hook shape invoked for model stream/tool/delegate cancellation cleanup.
AgentCancellationTargetKind
¶
Bases: StrEnum
Running execution target that can receive a cancellation cleanup hook.
AgentCancellationCleanupStatus
¶
Bases: StrEnum
Outcome of one cancellation cleanup hook.
AgentCancellationRequest(state_id, signal_id, target_kind, target_ref, reason=None, requested_by=None, metadata=dict())
dataclass
¶
Cancellation request passed to a model stream, tool, or delegate hook.
__post_init__()
¶
Reject requests that cannot be traced back to state/signal/target.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
from_signal(*, state, signal, target_kind, target_ref, metadata=None)
classmethod
¶
Build a hook request from the durable CANCEL signal payload.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
to_payload()
¶
Serialize the request into append-only evidence metadata.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
AgentCancellationCleanupResult(target_kind, target_ref, status, reason=None, error_code=None, message=None, metadata=dict())
dataclass
¶
Result returned by one cancellation cleanup hook.
failed_cleanup
property
¶
Return whether this hook prevents a clean CANCELLED terminal state.
__post_init__()
¶
Reject outcomes that cannot be correlated with the cleanup target.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
succeeded(*, target_kind, target_ref, reason=None, metadata=None)
classmethod
¶
Record a cleanup hook that released its target.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
failed(*, target_kind, target_ref, error_code, message, metadata=None)
classmethod
¶
Record a cleanup hook that could not release its target.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
skipped(*, target_kind, target_ref, reason, metadata=None)
classmethod
¶
Record a cleanup target that was already inactive or unavailable.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
to_payload()
¶
Serialize this hook outcome into evidence/state metadata.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
AgentCancellationCleanupTask(target_kind, target_ref, cleanup, metadata=dict())
dataclass
¶
One cleanup hook registered for a running cancellation target.
__post_init__()
¶
Reject hooks that cannot be identified in cleanup evidence.
run(*, state, signal)
async
¶
Invoke the hook and verify that it reports the same target.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
AgentCancellationCleanupReport(state_id, signal_id, outcomes=())
dataclass
¶
Aggregate cleanup evidence for one CANCEL signal.
cleanup_succeeded
property
¶
Return whether all cleanup hooks completed without failure.
failed_outcomes
property
¶
Return the hook outcomes that force FAILED terminal state.
__post_init__()
¶
Reject reports that cannot be attached to state and signal evidence.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
to_payload()
¶
Serialize the report for state metadata and evidence payloads.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
to_evidence_candidate(*, summary=None)
¶
Represent cancellation cleanup as append-only evidence.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
run_agent_cancellation_cleanup(*, state, signal, tasks)
async
¶
Invoke model stream/tool/delegate cleanup hooks for a CANCEL signal.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
begin_agent_cancellation(state, signal)
¶
Materialize receipt of a CANCEL signal as CANCELLING state.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
complete_agent_cancellation(state, report)
¶
Resolve CANCELLING state into CANCELLED or FAILED cleanup outcome.
Source code in core/spakky-agent/src/spakky/agent/cancellation.py
Delegation¶
Agent-to-agent delegation contracts.
DelegationReturnPolicy
¶
Bases: StrEnum
How a child agent result should be projected back to the parent.
AgentDelegateTarget(agent_type, agent_name=None, metadata=dict())
dataclass
¶
First-class delegate target represented by another @Agent component.
__post_init__()
¶
Reject delegate targets that cannot identify an agent component.
Source code in core/spakky-agent/src/spakky/agent/delegation.py
DelegationBudget(max_steps=None, max_tokens=None, timeout_seconds=None, deadline_at=None, metadata=dict())
dataclass
¶
Budget metadata attached to a delegation packet.
__post_init__()
¶
Reject delegation budgets that cannot be enforced consistently.
Source code in core/spakky-agent/src/spakky/agent/delegation.py
DelegationContextSlice(summary=None, evidence_refs=(), manifest_ref=None, metadata=dict())
dataclass
¶
Minimal parent context projected for a child agent.
DelegationExpectedOutput(description=None, schema=dict(), metadata=dict())
dataclass
¶
Expected child output description and optional JSON schema.
DelegationPacket(id, parent_agent_state_id, target, task, context=DelegationContextSlice(), constraints=(), expected_output=DelegationExpectedOutput(), budget=DelegationBudget(), allowed_capabilities=(), return_policy=DelegationReturnPolicy.SUMMARY_AND_EVIDENCE, metadata=dict())
dataclass
¶
Task packet passed from a parent agent to a delegate agent.
__post_init__()
¶
Reject delegation packets without parent linkage or task identity.
Source code in core/spakky-agent/src/spakky/agent/delegation.py
DelegationResult(id, packet_id, target, summary, output=None, evidence_refs=(), metadata=dict(), created_at=None)
dataclass
¶
Child agent result projected back to the parent execution.
__post_init__()
¶
Reject delegated results that cannot be linked to a packet.
Source code in core/spakky-agent/src/spakky/agent/delegation.py
to_parent_evidence(*, evidence_id, parent_agent_state_id)
¶
Represent a delegated result as append-only parent evidence.
Source code in core/spakky-agent/src/spakky/agent/delegation.py
to_parent_yield(*, evidence_id, parent_agent_state_id)
¶
Expose the delegated result on the parent's AgentYield stream.
Source code in core/spakky-agent/src/spakky/agent/delegation.py
Safety¶
Deterministic sensitive-data contracts for agent boundaries.
DataSensitivity
¶
Bases: StrEnum
Canonical sensitivity classes carried by descriptors.
PII
¶
Bases: StrEnum
PII categories that can be declared with typing.Annotated.
MaskingPolicy
¶
Bases: StrEnum
Deterministic text masking strategies for sensitive values.
RedactionPolicy
¶
Bases: StrEnum
Boundary action used when a value must not be exposed.
StreamingGuardFailureMode
¶
Bases: StrEnum
Final audit behavior when a streaming guard missed a raw candidate.
StreamingRedactionAuditStatus
¶
Bases: StrEnum
Final aggregate streaming redaction audit status.
ContextExposurePolicy(include_pii_values=False, include_sensitive_values=False, include_sensitive_schema_metadata=False, include_sensitive_context_metadata=False)
dataclass
¶
Policy for LLM-facing context and schema metadata exposure.
can_expose_value(field)
¶
Return whether a sensitive value may cross the model boundary.
Source code in core/spakky-agent/src/spakky/agent/safety.py
EvidenceExposurePolicy(include_pii_values=False, include_sensitive_values=False, include_sensitive_metadata=True)
dataclass
¶
Policy for evidence payload exposure before append-only capture.
can_expose_value(field)
¶
Return whether a sensitive value may be stored in evidence payloads.
Source code in core/spakky-agent/src/spakky/agent/safety.py
CredentialRef(id, provider=None)
dataclass
¶
Reference to a credential outside LLM-facing context.
__post_init__()
¶
Reject blank credential references.
SecretRef(id, credential=None)
dataclass
¶
Opaque reference to a secret value stored outside model context.
SensitiveField(category, masking=MaskingPolicy.REDACT, redaction=RedactionPolicy.REDACT, label=None, metadata=dict())
dataclass
¶
typing.Annotated metadata for deterministic sensitive-field handling.
sensitivity
property
¶
Return the normalized sensitivity class.
category_name
property
¶
Return the stable public category name.
__post_init__()
¶
guard_text(value)
¶
Return deterministic model/evidence-safe text for this field.
to_metadata()
¶
Serialize marker metadata without including the sensitive value.
Source code in core/spakky-agent/src/spakky/agent/safety.py
SecretField(redaction=RedactionPolicy.REFERENCE_ONLY, label=None, metadata=dict())
dataclass
¶
typing.Annotated metadata for values that must never be model text.
sensitivity
property
¶
Return the normalized sensitivity class.
__post_init__()
¶
guard_text(value)
¶
to_metadata()
¶
Serialize marker metadata without including the secret value.
Source code in core/spakky-agent/src/spakky/agent/safety.py
SensitiveFieldDescriptor(path, field)
dataclass
¶
Path-bound sensitive metadata extracted from Annotated types.
to_metadata()
¶
Serialize descriptor metadata without leaking the field value.
StreamingSensitivePattern(name, pattern, replacement=REDACTED_VALUE, metadata=dict())
dataclass
¶
Caller-supplied deterministic pattern used by streaming redaction.
__post_init__()
¶
Reject blank names and invalid pattern syntax before streaming starts.
Source code in core/spakky-agent/src/spakky/agent/safety.py
redact(value)
¶
Return redacted text and the number of replacements applied.
find_matches(value)
¶
Return sanitized match locations without exposing raw text.
Source code in core/spakky-agent/src/spakky/agent/safety.py
StreamingRedactionPolicy(patterns, buffer_size=64, emit_chunk_size=None, failure_mode=StreamingGuardFailureMode.RAISE)
dataclass
¶
Bounded buffering policy balancing stream latency and redaction correctness.
__post_init__()
¶
Reject policies that would make the guard unbounded or silent.
Source code in core/spakky-agent/src/spakky/agent/safety.py
StreamingRedactionMatch(pattern_name, start, end, metadata=dict())
dataclass
¶
Sanitized final-audit match location for a missed redaction candidate.
to_payload()
¶
Serialize a match without the sensitive value itself.
Source code in core/spakky-agent/src/spakky/agent/safety.py
StreamingRedactionAudit(status, detected_count, redacted_count, missed_matches, buffer_size, emitted_char_count, original_char_count)
dataclass
¶
Final aggregate audit for a bounded streaming redaction session.
missed_count
property
¶
Return the number of raw candidates still present after streaming.
to_evidence_payload()
¶
Serialize audit evidence without raw streamed content.
Source code in core/spakky-agent/src/spakky/agent/safety.py
to_error_payload()
¶
Serialize a typed error payload for stream consumers.
Source code in core/spakky-agent/src/spakky/agent/safety.py
StreamingRedactionResult(chunks, audit=None, error=None)
dataclass
¶
Output produced by a bounded streaming redaction step.
StreamingRedactionSession(policy)
¶
Stateful bounded redactor for model token streams.
Source code in core/spakky-agent/src/spakky/agent/safety.py
push(chunk)
¶
Redact one token chunk and emit only the safe bounded prefix.
Source code in core/spakky-agent/src/spakky/agent/safety.py
finish()
¶
Flush the remaining buffer and run the mandatory final audit.
Source code in core/spakky-agent/src/spakky/agent/safety.py
guard_json_value(value, sensitive_fields, policy)
¶
Redact JSON-compatible values according to path-bound descriptors.
Source code in core/spakky-agent/src/spakky/agent/safety.py
schema_with_sensitive_metadata(schema, sensitive_fields, policy)
¶
Return a JSON schema copy with policy-approved sensitivity extensions.
Source code in core/spakky-agent/src/spakky/agent/safety.py
Tooling¶
Agent tool descriptor discovery contracts.
Idempotency
¶
Bases: StrEnum
Action idempotency declared by a tool.
ToolResumeAction
¶
Bases: StrEnum
Resume action allowed by stored tool idempotency metadata.
DataAccess
¶
Bases: StrEnum
Data access level declared by a tool.
Externality
¶
Bases: StrEnum
External side-effect boundary declared by a tool.
EvidenceCapture
¶
Bases: StrEnum
Evidence capture strategy for tool results.
ToolApprovalRequirement
¶
Bases: StrEnum
Human approval requirement at the tool boundary.
ToolRiskAxis
¶
Bases: StrEnum
Derived risk axes exposed for policy and UI decisions.
ToolPermission(name)
dataclass
¶
Typed permission marker attached to a tool descriptor.
__post_init__()
¶
Reject permission names that cannot be matched deterministically.
ToolEffects(data_access=DataAccess.NONE, externality=Externality.LOCAL, destructive=False, network=False)
dataclass
¶
Typed effect metadata used to derive display risk outside core.
read_only()
classmethod
¶
write_state()
classmethod
¶
external_side_effect()
classmethod
¶
Declare a tool that crosses an external side-effect boundary.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
destructive_action()
classmethod
¶
Declare a tool that may irreversibly mutate local or external state.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
TimeoutPolicy(seconds=None)
dataclass
¶
Optional timeout boundary for a tool invocation.
__post_init__()
¶
Reject non-positive timeout policies at definition time.
ResultBudget(max_bytes=None)
dataclass
¶
Optional result-size budget for model-facing tool output.
__post_init__()
¶
Reject result budgets that cannot constrain output.
ToolResumeMetadata(idempotency=Idempotency.UNKNOWN)
dataclass
¶
Stored idempotency metadata used when resuming an incomplete action.
from_metadata(metadata)
classmethod
¶
Build resume metadata from a tool descriptor metadata object.
action_for_completed_boundary()
¶
Return the resume action for an already completed action boundary.
action_for_incomplete_boundary()
¶
Return the resume action for an incomplete action boundary.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
AgentToolSchemaHandle(name, input_schema_name, output_schema_name, input_schema=dict(), output_schema=dict(), input_sensitive_fields=(), output_sensitive_fields=())
dataclass
¶
Stable schema names and generated JSON schemas owned by a descriptor.
__post_init__()
¶
Reject blank schema handles.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
input_schema_for(policy=None)
¶
Return model-facing input schema under the requested exposure policy.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
output_schema_for(policy=None)
¶
Return model-facing output schema under the requested exposure policy.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
AgentToolIdentity(owner_module, owner_qualname, name)
dataclass
¶
AgentToolMetadata(permissions=(), effects=ToolEffects(), idempotency=Idempotency.UNKNOWN, data_access=DataAccess.NONE, externality=Externality.LOCAL, timeout=TimeoutPolicy(), result_budget=ResultBudget(), evidence=EvidenceCapture.NONE, approval=ToolApprovalRequirement.DERIVED)
dataclass
¶
Typed approval, idempotency, and evidence metadata for a descriptor.
ToolRisk(axes=())
dataclass
¶
Derived typed risk axes for policy and evidence annotations.
requires_approval_candidate
property
¶
Return whether the risk is strong enough to suggest HITL approval.
__post_init__()
¶
Reject duplicate axes so risk comparisons stay deterministic.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
from_metadata(metadata)
classmethod
¶
Derive risk axes from source tool metadata.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
AgentToolDefinition(name, schema_name, description=None, metadata=AgentToolMetadata())
dataclass
¶
Method-level metadata attached by @agent_tool before owner discovery.
__post_init__()
¶
Reject definitions that would make catalog lookup ambiguous.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
AgentToolDescriptor(identity, owner, callable, schema, description=None, metadata=AgentToolMetadata())
dataclass
¶
AgentToolBoundInvocation(args=(), kwargs=dict())
dataclass
¶
Python-call-ready tool invocation arguments.
AgentToolCatalog(descriptors=())
dataclass
¶
Deterministic catalog of descriptors discovered from an Agent class.
__post_init__()
¶
Reject duplicate identity or schema names before model lookup.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
by_identity(identity)
¶
Lookup a descriptor by typed identity.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
by_schema_name(schema_name)
¶
Lookup a descriptor by model-facing schema name.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
agent_tool(*, name=None, schema_name=None, description=None, permissions=(), effects=None, idempotency=Idempotency.UNKNOWN, data_access=None, externality=None, timeout=None, result_budget=None, evidence=EvidenceCapture.NONE, approval=ToolApprovalRequirement.DERIVED)
¶
Attach typed agent-tool metadata to a method object.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
discover_agent_tools(owner)
¶
Discover @agent_tool methods in deterministic class-definition order.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
get_agent_tool_definition(function)
¶
Return decorator metadata attached to a function object.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
bind_agent_tool_invocation(function, payload)
¶
Bind a structured model payload to a tool function signature.
Source code in core/spakky-agent/src/spakky/agent/tooling.py
Yield¶
Agent streaming yield contracts.
TextDelta = Token
module-attribute
¶
Backward-compatible token-yield payload alias.
Message = Progress
module-attribute
¶
Backward-compatible progress-yield payload alias.
AgentYieldKind
¶
Bases: StrEnum
Canonical public vocabulary yielded by agent execution.
AgentYield(kind, payload)
dataclass
¶
Typed stream item returned from an agent execute generator.
Token(text, metadata=dict())
dataclass
¶
Incremental model token intended for streaming clients.
Progress(message, current_step=None, metadata=dict())
dataclass
¶
Agent progress update intended for direct inbound adapter consumption.
Tool(name, call_id=None, arguments=dict(), result=None, metadata=dict())
dataclass
¶
Tool call or tool result surfaced by agent execution.
Evidence(evidence, metadata=dict())
dataclass
¶
Evidence item surfaced to the inbound adapter.
Approval(id, prompt, allowed_decisions, metadata)
dataclass
¶
Approval request surfaced to the inbound adapter.
Error(code, message, retryable=False, metadata=dict())
dataclass
¶
Recoverable or terminal execution error surfaced to the caller.
Cancel(reason=None, requested_by=None, metadata=dict())
dataclass
¶
Cancellation acknowledgement surfaced to the caller.
Final(output, metadata)
dataclass
¶
Final output carried by a generator stream.
Model Interface¶
Provider-neutral agent model port.
ModelMessageRole
¶
Bases: StrEnum
Roles accepted by provider-neutral model messages.
ModelMessage(role, content, metadata=dict())
dataclass
¶
Provider-neutral model message.
JsonSchemaConstraint(schema, strict=True)
dataclass
¶
JSON schema constraint shared by structured output and tool calling.
StructuredOutputSpec(constraint, output_type_name=None)
dataclass
¶
Structured output contract requested from a model adapter.
ModelToolChoice
¶
Bases: StrEnum
Provider-neutral tool calling strategy requested from a model adapter.
ModelToolSpec(name, parameters, description=None, metadata=dict())
dataclass
¶
LLM-facing tool descriptor normalized by agent tooling.
ToolCallingSpec(tools, choice=ModelToolChoice.AUTO)
dataclass
¶
Tool calling contract requested from a model adapter.
SamplingOptions(temperature=None, top_p=None, max_tokens=None)
dataclass
¶
Portable model sampling options.
StreamingOptions(include_usage=True, include_progress=True)
dataclass
¶
Portable model streaming options.
ModelRequest(messages, context=tuple(), context_manifest=None, context_digest=None, structured_output=None, tool_calling=None, sampling=SamplingOptions(), streaming=StreamingOptions(), metadata=dict())
dataclass
¶
Provider-neutral request passed to an agent model adapter.
assemble_messages(policy=None)
¶
Assemble prompt messages from typed context packs without concatenation.
Source code in core/spakky-agent/src/spakky/agent/interfaces/model.py
ModelUsage(input_tokens=None, output_tokens=None, total_tokens=None)
dataclass
¶
Token accounting reported by a model adapter.
ModelToolCall(name, arguments, call_id=None, metadata=dict())
dataclass
¶
Tool invocation candidate emitted by a model adapter.
guarded(sensitive_fields, policy=None)
¶
Return a copy with sensitive argument values deterministically guarded.
Source code in core/spakky-agent/src/spakky/agent/interfaces/model.py
ModelError(code, message, retryable=False, metadata=dict())
dataclass
¶
Provider-neutral model failure payload.
ModelResponse(content, structured_output=None, tool_calls=tuple(), usage=ModelUsage(), metadata=dict())
dataclass
¶
Provider-neutral non-streaming model response.
guarded(sensitive_fields, policy=None)
¶
Return a copy with sensitive output payloads deterministically guarded.
Source code in core/spakky-agent/src/spakky/agent/interfaces/model.py
ModelStreamEventKind
¶
Bases: StrEnum
Provider-neutral streaming event kinds emitted by a model adapter.
ModelStreamEvent(kind, token_delta=None, tool_call=None, structured_output=None, error=None, usage=None, metadata=dict())
dataclass
¶
Provider-neutral model streaming event.
guarded(sensitive_fields, policy=None)
¶
Return a copy with sensitive streaming payloads guarded.
Source code in core/spakky-agent/src/spakky/agent/interfaces/model.py
Persistence ports for durable agent state, signal, and evidence.
IAgentStateRepository
¶
Bases: ABC
Materialized state repository for long-running agent executions.
get(state_id)
abstractmethod
¶
get_or_none(state_id)
abstractmethod
¶
save(state)
abstractmethod
¶
list_by_status(status)
abstractmethod
¶
Return states matching an externally observable lifecycle status.
list_resume_candidates()
abstractmethod
¶
Return active or interrupted states that may resume after restart.
IAgentSignalRepository
¶
IAgentEvidenceRepository
¶
Types¶
Shared JSON-compatible type aliases for agent contracts.
JsonPrimitive = bool | float | int | str | None
¶
Scalar JSON value accepted by agent public contracts.
JsonValue = JsonPrimitive | Mapping[str, JsonValue] | Sequence[JsonValue]
¶
Recursive JSON-compatible value used at model, signal, and evidence boundaries.
JsonObject = Mapping[str, JsonValue]
¶
JSON object payload used by public agent contracts.
Plugin¶
Plugin initialization entry point for spakky-agent.
initialize(app)
¶
Initialize spakky-agent core contracts.
The package intentionally registers no persistence implementation; production repositories must arrive through feature contributions.
Source code in core/spakky-agent/src/spakky/agent/main.py
Bootstrap validation for Agent Pod instances.
AgentBootstrapValidationPostProcessor()
¶
Bases: IPostProcessor, IContainerAware
Validate Agent metadata during application bootstrap.
Initialize without assuming application context injection happened.
Source code in core/spakky-agent/src/spakky/agent/post_processor.py
set_container(container)
¶
post_process(pod)
¶
Fail startup when an Agent contract is no longer valid.