Documentation Index
Fetch the complete documentation index at: https://docs.circuit.org/llms.txt
Use this file to discover all available pages before exploring further.
Use these patterns to handle failures gracefully — checking success before using data, logging errors for visibility in the UI, and matching specific error codes when you need different recovery logic per failure type.
Response Structure
All SDK methods return response objects:
{
success: bool
data: any | None
error: str | None
}
Checking Results
Always check success before using data:
result = agent.memory.get("key")
if result.success and result.data:
# Safe to use result.data
agent.log(f"Value: {result.data.value}")
else:
# Handle error
agent.log(f"Error: {result.error}", error=True)
Uncaught Exceptions
Uncaught exceptions in run or unwind are caught by the SDK. The execution is marked as failed and the error is logged. You don’t need to wrap SDK method calls in try/catch blocks unless you need to handle for a specific error.
def run(agent: AgentContext) -> None:
# This typo will be caught and logged automatically
agent.memmory.set("key", "value") # AttributeError
# No try/except needed
When to Use Try/Catch
Only use try/catch for your own logic that might throw (parsing, calculations with external data, custom recovery). Don’t use it for SDK method calls — just check .success instead.
Swap Error Codes
Swap methods (agent.swap.quote(), agent.swap.execute()) return typed error codes in the error field:
| Error Code | Cause | Solution |
|---|
QUOTE_TIMEOUT | Quote request timed out | Retry after a brief delay |
ALL_ENGINES_FAILED | Every routing engine returned an error | Check input parameters; the route may not be available |
NO_COMPATIBLE_ENGINES | No engine supports this token pair or route | Verify token addresses and network IDs |
ENGINE_API_ERROR | Upstream routing engine returned an error | Retry; if persistent, the engine may be temporarily down |
PRICE_IMPACT_TOO_HIGH | Price impact exceeds acceptable threshold | Reduce swap amount or increase slippage tolerance |
INSUFFICIENT_BALANCE | Wallet balance too low for this swap | Check positions before quoting |
INTERNAL_ERROR | Unexpected internal error | Log and retry; contact support if persistent |
Hyperliquid Error Codes
Hyperliquid methods (agent.platforms.hyperliquid.*) return error messages in the error field. See Hyperliquid: Common Errors for the full table.
Polymarket Error Codes
Polymarket methods (agent.platforms.polymarket.*) return typed error codes:
| Error Code | Cause | Solution |
|---|
ORDERBOOK_NOT_FOUND | No orderbook for the given token | Verify tokenId from Polymarket |
MARKET_NOT_FOUND | Market does not exist | Check that the market hasn’t been resolved or removed |
TOKEN_NOT_IN_MARKET | Token ID not associated with market | Use correct tokenId for the market |
INSUFFICIENT_LIQUIDITY | Not enough liquidity to fill order | Reduce order size or wait for more liquidity |
INSUFFICIENT_BALANCE | Wallet pUSD balance too low for this order | Check balances before placing orders |
ORDER_REJECTED | Order was rejected by the exchange | Check order parameters (size, side) |
UPSTREAM_API_ERROR | Polymarket API returned an error | Retry; check Polymarket status |
UPSTREAM_HTTP_ERROR | HTTP error from Polymarket | Retry with backoff |
UPSTREAM_INVALID_RESPONSE | Unexpected response format from Polymarket | Likely a temporary API issue; retry |
NETWORK_ERROR | Network connectivity issue | Retry with backoff |
CREDENTIALS_ERROR | Invalid or missing API credentials | Ensure session is active and wallet is valid |
INTERNAL_ERROR | Unexpected internal error | Log and retry; contact support if persistent |
Transaction Reverts
The server automatically waits for onchain confirmation after broadcasting a transaction. If the transaction was mined but reverted onchain, the response returns success: false with an error message. No SDK-side option is needed.
result = agent.sign_and_send({
"network": "ethereum:1",
"request": {
"to_address": "0x...",
"data": "0x...",
"value": "0",
},
})
if not result.success:
if result.error and "reverted" in result.error:
agent.log("Transaction reverted onchain", error=True)
else:
agent.log(f"Error: {result.error}", error=True)
This applies to all transacting methods: signAndSend, swap.execute, polymarket.marketOrder, and polymarket.redeemPositions.
General Error Patterns
| Error | Cause | Solution |
|---|
| ”Key not found” | Memory key doesn’t exist | Check if key exists first or handle missing keys |
| ”Invalid request” | Bad parameters to SDK method | Validate inputs before calling SDK methods |
| ”Transaction failed” | Insufficient balance/gas or revert | Check balances via getCurrentPositions() before transactions |
Tips
- Always check
success before using data
- Log errors with
error: true / error=True so they show up in the UI
- Return early on errors instead of continuing
- Validate inputs before making SDK calls
- Match against specific error codes when you need different handling per failure type
See Also
- Troubleshooting — Common issues and solutions for CLI, SDK, and platform-specific problems
- Logging — Log errors with
error: true so they appear in the UI