Agent Guardrails Docs

Program Reference

Anchor 0.30.1 Solana program that enforces agent policies on-chain. Program ID: ENzC6oJhL2bVELvRCZqN4JizFNPTCTfMR5Gz1YJb4u76

The program is deployed on Solana devnet.

Accounts

PermissionPolicy

PDA seeds: ["policy", owner, agent]. Size: 685 bytes. Stores all policy configuration, spend state, and pause metadata for a single agent.

FieldTypeDescription
ownerPubkeyWallet that created and controls the policy
agentPubkeyPublic key of the AI agent keypair
allowedProgramsVec<Pubkey> (max 10)Whitelisted program IDs for CPI
maxTxLamportsu64Per-transaction SOL cap in lamports
maxTxTokenUnitsu64Per-transaction token unit cap
dailyBudgetLamportsu64Rolling 24-hour budget in lamports
dailySpentLamportsu64Lamports spent in the current 24h window
lastResetTsi64Timestamp of the last budget window reset
sessionExpiryi64Unix timestamp when the agent session expires
isActiveboolWhether the agent is active (false when paused)
pausedByOption<Pubkey>Who triggered the kill switch (if paused)
pausedReason[u8; 64]UTF-8 encoded reason string (if paused)
squadsMultisigOption<Pubkey>Squads v4 multisig address for escalation
escalationThresholdu64Amount in lamports that triggers multisig escalation
authorizedMonitorsVec<Pubkey> (max 3)Keypairs authorized to call pause_agent
anomalyScoreu8Guardian Agent anomaly score (0–100)
bumpu8PDA bump seed

SpendTracker

PDA seeds: ["tracker", policy]. Tracks rolling spend counters, transaction frequency, and behavioral signals used by the monitoring pipeline.

FieldTypeDescription
policyPubkeyAssociated PermissionPolicy PDA
windowStarti64Start of the current 24h tracking window
txnCount24hu64Total transactions in the current 24h window
lamportsSpent24hu64Total lamports spent in the current 24h window
lastTxnTsi64Timestamp of the most recent transaction
lastTxnProgramPubkeyTarget program of the most recent transaction
uniqueDestinations24hu64Unique destination accounts in 24h (heuristic)
maxSingleTxnLamportsu64Largest single transaction in the current window
failedTxnCount24hu64Failed guarded_execute attempts in 24h
uniquePrograms24hu64Unique target programs invoked in 24h
lamportsSpent1hu64Lamports spent in the current 1h window
windowStart1hi64Start of the current 1h tracking window
consecutiveHighAmountCountu64Sequential transactions above 50% of per-tx limit
bumpu8PDA bump seed

Instructions

InstructionSignerDescription
initialize_policyOwnerCreates policy + tracker PDAs with initial configuration
update_policyOwnerModifies limits, allowed programs, monitors, or multisig settings
guarded_executeAgentCore CPI with 12-step validation pipeline
pause_agentOwner / MonitorActivates the kill switch, freezing all agent activity
resume_agentOwner onlyDeactivates the kill switch, re-enabling agent execution
rotate_agent_keyOwnerSwaps agent keypair atomically, migrating all state to new PDAs
close_policyOwnerPermanent deletion of policy + tracker, refunds remaining lamports
multisig_executeOwnerSquads-approved execution bypassing standard budget checks
escalate_to_squadsStub for future Squads proposal creation
update_anomaly_scoreMonitorSets the Guardian Agent anomaly score (0–100)
wrap_solOwner / AgentConverts SOL to wrapped SOL (wSOL) for SPL interactions
unwrap_solOwner / AgentConverts wrapped SOL (wSOL) back to native SOL

guarded_execute: 12-Step Flow

Every agent transaction passes through the following validation pipeline before the CPI is executed. If any step fails, the transaction is rejected and a GuardedTxnRejected event is emitted.

  1. Load policy + tracker PDAs and verify account ownership
  2. Kill switch check — reject if isActive is false (PolicyPaused)
  3. Session expiry check — reject if current timestamp exceeds sessionExpiry
  4. Program whitelist check — reject if target program is not in allowedPrograms
  5. Amount verification + parsing — validate amountHint against account balances
  6. Budget window roll — reset counters if 24h has elapsed since lastResetTs
  7. Daily budget check — reject if spend + amount exceeds dailyBudgetLamports
  8. Squads escalation check — escalate if amount exceeds escalationThreshold
  9. Emit GuardedTxnAttempted event with pre-execution metadata
  10. Execute CPI via invoke_signed to the target program
  11. Update spend counters on tracker and emit GuardedTxnExecuted
  12. Return success

Events

The program emits Anchor events that are indexed by Helius webhooks and forwarded to the server monitoring pipeline.

EventFieldsWhen Emitted
GuardedTxnAttemptedpolicy, agent, targetProgram, amountHint, timestampBefore CPI execution (step 9)
GuardedTxnExecutedpolicy, agent, targetProgram, amount, timestampAfter successful CPI execution (step 11)
GuardedTxnRejectedpolicy, agent, reason code, timestampOn validation failure (steps 2–8)
AgentPausedpolicy, pausedBy, reason, timestampWhen pause_agent is called
AgentResumedpolicy, resumedBy, timestampWhen resume_agent is called
EscalatedToSquadspolicy, squadsProposal, amountWhen transaction exceeds escalation threshold
AgentKeyRotatedoldPolicy, newPolicy, oldAgent, newAgent, timestampWhen rotate_agent_key completes
MultisigTxnExecutedpolicy, owner, targetProgram, amount, squadsProposal, timestampAfter successful multisig execution
PolicyClosedpolicy, owner, refundedLamports, timestampWhen close_policy completes

Error Codes

CodeNameMessage
6000PolicyPausedAgent is paused by kill switch
6001SessionExpiredAgent session has expired
6002ProgramNotWhitelistedTarget program is not in the allow list
6003AmountExceedsLimitTransaction amount exceeds per-tx limit
6004DailyBudgetExceededDaily spending budget has been exhausted
6005UnauthorizedPauserSigner is not authorized to pause this agent
6006ResumeRequiresOwnerOnly the policy owner can resume an agent
6007EscalatedToMultisigTransaction requires multisig approval
6008TooManyAllowedProgramsAllowed programs list exceeds maximum of 10
6009TooManyMonitorsAuthorized monitors list exceeds maximum of 3
6010SessionExpiryInPastSession expiry timestamp is in the past
6011TxLimitExceedsDailyBudgetPer-tx limit cannot exceed daily budget
6012AmountMismatchAmount hint does not match actual account delta
6013CpiExecutionFailedCross-program invocation returned an error
6014InsufficientLamportsInsufficient lamports for the transaction
6015UnauthorizedCallerSigner is not the expected owner or agent
6016InvalidWsolAccountwSOL account does not match expected address
6017InvalidInputAccountIndexInput account index is out of bounds
6018InputAccountIndexRequiredInput account index is required for this instruction
6019PolicyNotPausedPolicy must be paused before this action
6020NotYetImplementedThis feature is not yet implemented
6021SameAgentKeyNew agent key must differ from the current key
6022InvalidSquadsProposalSquads proposal account is invalid
6023MultisigMismatchProposal multisig does not match policy multisig
6024ProposalNotApprovedSquads proposal has not been approved
6025NoMultisigConfiguredNo multisig is configured on this policy