Skip to main content
AgentContext is passed to your run and unwind functions. It has session data and all SDK methods.

Session Data

  • sessionId (number): Unique session identifier
  • sessionWalletAddress (string): Wallet address for this session
  • portfolio (object): What the session holds at the start of execution — portfolio.balances (cash/spot/staking inventory + Polymarket pUSD cash) and portfolio.positions (open Hyperliquid perps + Polymarket outcome-token positions)
  • executionMode (string): "auto" or "manual"
  • settings (object): Resolved settings (defaults merged with session overrides)

SDK Methods

  • log(): Send messages to users and log locally
  • memory: Key-value storage (shared=True for shared scope, omit for session)
  • platforms: Platform integrations (Polymarket, Hyperliquid)
  • swap: Cross-chain swap operations
  • sign_and_send(): Sign and broadcast transactions
  • sign_message(): Sign messages (EVM only)
  • transactions(): Get transaction history
  • clear_suggested_transactions(): Clear pending suggestions (manual mode)

Basic Usage

def run(agent: AgentContext) -> None:
    agent.log(f"Session: {agent.sessionId}")
    agent.log(f"Wallet: {agent.sessionWalletAddress}")
    agent.log(f"Balances: {len(agent.portfolio.balances)}")

Portfolio

agent.portfolio is captured at execution start. It is a field — no await, no success/data wrapper. See Positions for full details.
portfolio = agent.portfolio
for balance in portfolio.balances:
    agent.log(f"{balance.symbol}: {balance.amount_raw} (raw)")
for position in portfolio.positions:
    kind = "Polymarket" if position.polymarket_metadata else "Perp"
    agent.log(f"{kind} {position.coin}: size {position.size}")

See Also