Skip to main content
Use agent.allocation to check what assets were available to your agent when this invocation started. It is the session’s allocated slice of the wallet - what the agent may spend, not the whole wallet (a wallet can be shared across sessions).

Reading the Allocation

The allocation is an invocation-start snapshot and is Polymarket-enriched. It is a field with no await and no success/data wrapper. Constructing the invocation fails rather than substituting a default balance if the allocation cannot be built.
  • balances - fungible inventory the session holds outright: cash, spot tokens, staking positions, and Polymarket pUSD cash.
  • positions - open market exposures: Hyperliquid perpetuals (signed sizes) and Polymarket outcome-token positions. The two are distinguished by whether polymarketMetadata is present (present = Polymarket position; absent/None = Hyperliquid perp).
Python and TypeScript expose the same balances and positions fields on agent.allocation.

AllocationBalance Fields

  • network (string): Network identifier (e.g., “ethereum:137”)
  • assetKey (string): Canonical asset key
  • tokenAddress (string): Token contract address
  • tokenId (string | null): Token ID for NFTs/ERC1155 (null for fungible tokens)
  • symbol (string | null): Token symbol
  • decimals (number): Token decimals
  • amountRaw (string): Quantity held in raw base units
  • marketValueUsd (string | null): Current market value in USD
  • hyperliquidMetadata ({ collateral: true }, optional): present only on the Hyperliquid perp-margin USDC balance (deployable collateral, total basis - includes locked margin, excludes unrealized PnL; equity = collateral + Σ positions’ unrealizedPnlUsd, free margin ≈ equity − Σ marginUsed). Absent on everything else (EVM/Solana tokens, HL spot/staking) - read network to distinguish those.
Polymarket pUSD cash appears here like any other cash balance. Polymarket outcome-token positions live in positions (see below), not in balances.

AllocationPosition Fields

Open market exposures - both Hyperliquid perpetuals and Polymarket outcome-token positions. Distinguish the two by whether polymarketMetadata is present.
  • network (string): Network identifier
  • assetKey (string): Canonical asset key
  • coin (string): For HL perps, the perp coin (e.g., “BTC”); for Polymarket positions, the outcome label (e.g., “Yes”)
  • size (string): For HL perps, the signed position size - long > 0, short < 0; for Polymarket positions, the shares held (decimal string)
  • averageEntryPrice (string | null): Average entry price
  • markPriceUsd (string | null): Current mark price in USD (Hyperliquid perp mark; Polymarket share mark for valuation)
  • unrealizedPnlUsd (string | null): Unrealized PnL in USD
  • polymarketMetadata (object, optional): Enriched Polymarket data - present only for Polymarket positions; absent/None for Hyperliquid perps. Fields:
    • question (string): Market question text
    • outcome (string): Outcome name (e.g., “Yes”, “No”)
    • marketValueUsd (string): Position value in USD
    • priceUsd (string): Current price per share
    • averagePriceUsd (string): Average entry price
    • pnlUsd (string): Profit/loss in USD
    • pnlPercent (string): Profit/loss percentage
    • pnlRealizedUsd (string): Realized PnL in USD
    • pnlRealizedPercent (string): Realized PnL percentage
    • isRedeemable (boolean): Whether the position can be redeemed
    • isNegativeRisk (boolean): Whether this is a negative risk market
    • imageUrl (string): Market image URL
    • endDate (string): Market end date
    • contractAddress (string): Polymarket contract address
    • tokenId (string | null): Outcome token ID
    • decimals (number): Token decimals
    • conditionId (string): Market condition ID
    • formattedShares (string): Human-readable share count
    • shares (string): Raw share count
    • initialValue (string): Initial position value

Example

Notes

  • The snapshot does not mutate during an invocation. Track effects in local variables when a later step depends on an earlier action; the next trigger receives a fresh snapshot containing committed top-ups and transaction effects.
  • Amounts (amountRaw) and sizes are strings to preserve precision for large numbers.
  • Polymarket positions always include enriched polymarketMetadata (question, outcome, PNL, etc.). It is absent/None for Hyperliquid perps, so its presence is how you tell the two kinds of position apart.
  • Both Hyperliquid perps and Polymarket positions appear in allocation.positions. For live Hyperliquid state, read directly from the platform methods (see below).

See Also

  • Wallets & Asset Allocation - How assets are allocated to sessions
  • Memory - Persist strategy state across runs, never portfolio mirrors
  • Hyperliquid - Hyperliquid agents use platform-specific balance methods for live state