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 noawait 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 whetherpolymarketMetadatais present (present = Polymarket position; absent/None= Hyperliquid perp).
balances and positions fields on agent.allocation.
AllocationBalance Fields
network(string): Network identifier (e.g., “ethereum:137”)assetKey(string): Canonical asset keytokenAddress(string): Token contract addresstokenId(string | null): Token ID for NFTs/ERC1155 (null for fungible tokens)symbol(string | null): Token symboldecimals(number): Token decimalsamountRaw(string): Quantity held in raw base unitsmarketValueUsd(string | null): Current market value in USDhyperliquidMetadata({ 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) - readnetworkto distinguish those.
positions (see below), not in balances.
AllocationPosition Fields
Open market exposures - both Hyperliquid perpetuals and Polymarket outcome-token positions. Distinguish the two by whetherpolymarketMetadata is present.
network(string): Network identifierassetKey(string): Canonical asset keycoin(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 pricemarkPriceUsd(string | null): Current mark price in USD (Hyperliquid perp mark; Polymarket share mark for valuation)unrealizedPnlUsd(string | null): Unrealized PnL in USDpolymarketMetadata(object, optional): Enriched Polymarket data - present only for Polymarket positions; absent/Nonefor Hyperliquid perps. Fields:question(string): Market question textoutcome(string): Outcome name (e.g., “Yes”, “No”)marketValueUsd(string): Position value in USDpriceUsd(string): Current price per shareaveragePriceUsd(string): Average entry pricepnlUsd(string): Profit/loss in USDpnlPercent(string): Profit/loss percentagepnlRealizedUsd(string): Realized PnL in USDpnlRealizedPercent(string): Realized PnL percentageisRedeemable(boolean): Whether the position can be redeemedisNegativeRisk(boolean): Whether this is a negative risk marketimageUrl(string): Market image URLendDate(string): Market end datecontractAddress(string): Polymarket contract addresstokenId(string | null): Outcome token IDdecimals(number): Token decimalsconditionId(string): Market condition IDformattedShares(string): Human-readable share countshares(string): Raw share countinitialValue(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/Nonefor 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