A complete example that runs six scenarios against a real agent on Solana, showing howDocumentation Index
Fetch the complete documentation index at: https://docs.altheia.xyz/llms.txt
Use this file to discover all available pages before exploring further.
guard() behaves when an action is allowed, denied, paused, or revoked.
Source on GitHub
examples/orca-swap-agent in the SDK repo.What it does
- Loads your operator key, agent PDA, and API key from
.env. - Constructs an Orca Whirlpools swap (SOL → USDC).
- Wraps the swap in
altheia.guard(). - Runs six scenarios with an Enter prompt between each so you can watch.
The six scenarios
| # | Setup | Expected |
|---|---|---|
| 1 | Swap 0.05 SOL → USDC, under all caps. | Allowed. Lands on-chain. |
| 2 | Swap 1 SOL → USDC, over per-tx cap. | Denied with over_per_tx_cap. |
| 3 | Swap 0.05 SOL repeatedly until rolling 24h cap is hit. | Denied with over_per_day_cap. |
| 4 | Swap on a non-allowlisted program. | Denied with scope_violation. |
| 5 | Pause the agent in the dashboard, then try a swap. | Denied with agent_paused. |
| 6 | Revoke the agent, then try a swap. | Denied with agent_revoked. SDK does not retry. |
Setup
The guard call (verbatim from the example)
failureMode: "closed" means: if the Altheia backend is unreachable, halt instead of letting the agent swing free. For production agents that move funds, this is the right default.
What you should see
Scenario 1 lands a real tx on devnet. The audit chronicle picks up the signature within a few seconds. Scenarios 2–6 don’t touch the chain at all — the SDK’s pre-flight stops them before any signature is requested. Open the agent in the dashboard while you run the example and you’ll see every denial show up in the chronicle with a reason code.SDK reference
All methods on
Altheia.