agent.portfolio at the start of each run to decide what to do.
The Portfolio Field
agent.portfolio is a field (not a method) populated at the start of each execution. There is no await, no success/data wrapper — read it directly. It is always present and always Polymarket-enriched.
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).
agent.portfolio.balances, agent.portfolio.positions.
SessionBalance 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 unitsvalueUsd(string | null): Current marked value in USDassetClass("cash"|"spot"|"perp"|"staking"): What kind of holding this is
positions (see below), not in balances.
SessionPosition 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 USDunrealizedPnlUsd(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”)valueUsd(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
agent.portfoliois captured at execution start. After transactions, it does not refresh within the samerun— track changes you make in Memory if you need updated state mid-cycle.- 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
portfolio.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 — Track position deltas across transactions
- Hyperliquid — Hyperliquid agents use platform-specific balance methods for live state