demo/src/agent.ts is a complete autonomous Drift trading agent. It reads GLOSSO.md at startup, discovers its tools, and executes a full trading cycle — price check, deposit, open position, monitor PnL, close — without any human prompting.
What the Agent Does
- Fetches live SOL price from Pyth Network
- Decides direction — long or short — based on a configurable signal
- Deposits collateral into Drift protocol
- Opens a SOL-PERP position with the deposited collateral
- Monitors PnL in real time
- Closes the position when the target is reached
- Logs every step to
~/.glosso/activity.log
maxRounds is hit. Every tool call and LLM reasoning step is visible in glosso monitor.
Run It
How It Works
The demo agent uses theai SDK with a tool-use loop:
GLOSSO.md in the system prompt tells the agent exactly which tools exist and how to call them. The agent reasons about its current state (balance, price, position) and decides what to do next.
Adding Policy
Before running the demo against a real account, you should set spend limits:Demo Tools
| Tool | What It Does |
|---|---|
glosso_balance | Check SOL balance |
glosso_price | Fetch SOL price from Pyth |
deposit_collateral | Deposit SOL into Drift |
open_perp_position | Open SOL-PERP long or short |
get_position | Check current position and unrealized PnL |
close_perp_position | Close the open position |
withdraw_collateral | Withdraw remaining collateral |
The demo is configured for devnet by default. Do not run it on mainnet without updating
GLOSSO_NETWORK=mainnet-beta in .env and setting appropriate policy limits.