API Reference

Trust Reference

Complete reference for all TrustChain modules — attestation, context integrity, RAG trust, memory protection, hierarchy enforcement, and cross-runtime interoperability.

All TrustChain modules are available under agentcop.trust. Import individually or use TrustChainBuilder to compose them.

TrustChainBuilder

Fluent builder for composing TrustChain components. Produces a configured chain object ready to wrap an agent.

Constructor

ParameterTypeRequiredDescription
agent_idstringYesUnique identifier for the agent being protected
memory_backendstringNoURI for memory store. Defaults to memory:// (in-process)

Methods

MethodParametersReturnsDescription
with_attestation(**kwargs)See NodeAttestorselfEnable attestation with the given configuration
with_context_guard(**kwargs)See ContextGuardselfEnable context integrity checking
with_rag_trust(**kwargs)See RAGTrustLayerselfEnable RAG source validation
with_memory_guard(**kwargs)See MemoryGuardselfEnable memory integrity protection
with_hierarchy(**kwargs)See AgentHierarchyselfEnable agent hierarchy enforcement
build()TrustChainBuild and return the configured chain
from_env(agent_id)agent_id: stringTrustChainBuilderClass method. Read all configuration from environment variables

TrustChain

The composed chain object returned by TrustChainBuilder.build(). Wraps an agent with all configured protection layers.

Methods

MethodParametersReturnsDescription
run(agent, input)agent: Any, input: strAnyRun the agent through all TrustChain layers
export_audit()AuditBundleExport the complete audit trail for the most recent run
verify()boolVerify the integrity of the most recent run's chain

NodeAttestor

Signs each execution step with a cryptographic key. Produces an ordered chain of attestation records.

Constructor

ParameterTypeRequiredDescription
agent_idstringYesAgent identifier included in every record
signedboolNoEnable HMAC signing. Default: False
key_pathstringIf signed=TruePath to PEM key or raw bytes key file
algorithmstringNoSigning algorithm. Default: "HS256"

Methods

MethodParametersReturnsDescription
attach(agent)agent: AnyNoneInstrument the agent to produce attestation records
export_chain()list[AttestationRecord]Return all records from the current session
verify_chain(records)records: list[AttestationRecord]boolVerify signatures and ordering. Raises AttestationError on failure
attest(step, data)step: str, data: dictAttestationRecordManually attest a step. Used for custom integration points

Exceptions

ExceptionRaised when
AttestationErrorChain verification fails — missing record, invalid signature, or ordering violation

AttestationRecord

A single signed record in the attestation chain.

Fields

FieldTypeDescription
agent_idstringAgent that produced this record
stepstringStep type: tool_call, llm_response, memory_read, context_snapshot
sequenceintMonotonically increasing position in the chain
timestampstringISO 8601 timestamp
data_hashstringSHA-256 hash of the step's input/output data
signaturestring | nullHMAC signature. Null if signed=False
prev_hashstringHash of the previous record — creates the chain linkage

ContextGuard

Snapshots and verifies the agent's context window at specified execution points to detect context mutation.

Constructor

ParameterTypeRequiredDescription
agent_idstringYesAgent identifier
snapshot_onlist[string]NoEvents that trigger a snapshot. Default: ["tool_call", "llm_response"]
on_mutationstringNoAction on detected mutation: "raise", "log", "alert". Default: "raise"

Methods

MethodParametersReturnsDescription
wrap(agent)agent: AnyAnyWrap agent with context integrity checking
snapshot(context)context: dictContextSnapshotManually take a snapshot of the given context dict
verify(snapshot, context)snapshot: ContextSnapshot, context: dictboolVerify context matches snapshot. Raises ContextMutationError if not
integrity_log()list[IntegrityRecord]Return all snapshot/verify records from the current session

Exceptions

ExceptionRaised when
ContextMutationErrorContext does not match the most recent snapshot. Includes a diff of changed keys

RAGTrustLayer

Validates retrieved documents against a registry of trusted sources and known content hashes. Detects RAG poisoning attacks.

Constructor

ParameterTypeRequiredDescription
agent_idstringYesAgent identifier
on_untrustedstringNoAction for untrusted documents: "raise", "quarantine", "log". Default: "raise"

Methods

MethodParametersReturnsDescription
register_source(uri, trust_level)uri: string, trust_level: stringNoneRegister a trusted source URI prefix. trust_level: "high", "medium", "low"
register_document_hash(uri, sha256)uri: string, sha256: stringNoneRegister a known-good hash for a specific document
guard(fn)fn: callablecallableDecorator. Wraps a retrieval function with trust validation
validate(document, source_uri)document: str, source_uri: strTrustResultValidate a single document against the registry
quarantine_log()list[QuarantineRecord]Return all quarantined documents from the current session

Exceptions

ExceptionRaised when
RAGPoisoningErrorRetrieved document comes from an unregistered source or fails hash verification

MemoryGuard

Protects agent persistent memory against poisoning via cryptographic snapshots and verified reads.

Constructor

ParameterTypeRequiredDescription
agent_idstringYesAgent identifier
backendstringNoStorage backend URI. Supports memory://, redis://, sqlite:///. Default: memory://

Methods

MethodParametersReturnsDescription
snapshot()stringTake a snapshot of the current memory state. Returns a snapshot ID
verify(snapshot_id)snapshot_id: stringboolVerify current memory matches the given snapshot. Raises MemoryPoisoningError if not
read_safe(key)key: stringAnyRead a memory entry after verifying it against the last snapshot
write(key, value)key: string, value: AnyNoneWrite to memory. Logged and included in next snapshot
audit_log()list[MemoryAuditEntry]Return all memory operations from the current session

Exceptions

ExceptionRaised when
MemoryPoisoningErrorMemory does not match the snapshot — a write occurred between the snapshot and the verify call

AgentHierarchy

Enforces who can instruct whom in a multi-agent system. Supports supervisor/worker relationships, veto rights, and quorum requirements.

Constructor

ParameterTypeRequiredDescription
strictboolNoRaise on hierarchy violations. Default: False (log only)

Methods

MethodParametersReturnsDescription
set_supervisor(agent_id, workers)agent_id: string, workers: list[string]NoneRegister an agent as supervisor of the given workers
grant_veto(agent_id, over)agent_id: string, over: list[string]NoneGrant veto rights over the listed agents' decisions
require_quorum(agent, actions, approvers, threshold)See parametersNoneRequire quorum approval for specific actions
enforce(strict)strict: boolNoneSet strict mode. When True, violations raise instead of logging
wrap(agent_id, agent)agent_id: string, agent: AnyAnyWrap an agent with hierarchy enforcement
check_permission(caller_id, callee_id)caller_id: string, callee_id: stringboolCheck whether caller is permitted to instruct callee

require_quorum parameters

ParameterTypeDescription
agentstringThe agent whose actions require quorum
actionslist[string]Tool/action names that require quorum
approverslist[string]Agent IDs whose approval counts toward quorum
thresholdintNumber of approvals required before action is permitted

Exceptions

ExceptionRaised when
HierarchyViolationErrorAn agent receives instructions from a non-registered supervisor (strict mode only)
QuorumNotMetErrorAn action requiring quorum is attempted without sufficient approvals

TrustInterop

Exports attestation records as portable signed claims verifiable by external runtimes, services, or auditors.

Constructor

ParameterTypeRequiredDescription
issuerstringYesClaim issuer identifier, e.g. "agentcop:production-agent"
public_key_urlstringNoURL where the public verification key can be fetched by external verifiers

Methods

MethodParametersReturnsDescription
export_claims(records)records: list[AttestationRecord]ClaimBundleExport records as a portable signed claim bundle
import_claims(json_str)json_str: stringClaimBundleClass method. Parse and import an external claim bundle

ClaimBundle

A portable signed bundle of attestation claims, exportable as JSON for cross-runtime verification.

Methods

MethodParametersReturnsDescription
to_json()stringSerialize to a signed JSON string
verify()boolVerify the bundle's signature. Raises TrustInteropError if invalid
issuerstringClaim issuer identifier
issued_atstringISO 8601 timestamp when the bundle was created
recordslist[dict]The attestation records included in the bundle

Exceptions

ExceptionRaised when
TrustInteropErrorBundle signature is invalid, issuer is unrecognized, or the bundle has been tampered with

Environment variables

VariableDefaultDescription
AGENTCOP_TRUST_SIGNEDfalseEnable signed attestation
AGENTCOP_TRUST_KEY_PATHPath to attestation signing key
AGENTCOP_TRUST_MEMORY_BACKENDmemory://Memory guard storage backend URI
AGENTCOP_TRUST_RAG_STRICTfalseRaise on untrusted RAG sources instead of logging
AGENTCOP_TRUST_HIERARCHY_STRICTfalseRaise on hierarchy violations instead of logging
AGENTCOP_TRUST_ON_VIOLATIONlogDefault action for all violations: raise, log, alert