Overview
packages/agents/defi-portfolio/src/agents/sub-agents/strategy-sentinel-agent/agent.ts:22-180
Core Responsibilities
The Strategy Sentinel Agent must:- Continuously monitor strategy health by pulling all on-chain balances, prices, risk metrics, and vault states
- Detect risks early including high LTV, excessive leverage, low liquidation buffer, and rapid price changes
- Use simulation tools to validate any corrective action before recommending it
- Evaluate actions using strategy rules, not intuition
- Recommend corrective actions such as reducing leverage, rebalancing, harvesting yield, or pausing strategies
Available Tools
Read & Monitoring Tools
get_strategy_states
get_strategy_states
Fetches strategy addresses, their balances, and target BPS allocations from the Strategy Router.Implementation:Source:
tools.ts:48-81Returns: Array of strategy objects with addresses, balances, and target allocationsget_vault_state
get_vault_state
Reads the vault’s global state including total assets, supply, and managed balance.Implementation:Source:
tools.ts:17-45Returns: Object with totalAssets, totalSupply, and totalManaged (both raw and human-readable)get_user_balances
get_user_balances
Fetches vault share balance and withdrawable amount for a user.Schema:Returns: User’s shares and withdrawable assets (raw and human-readable)Source:
tools.ts:85-114get_token_prices
get_token_prices
Fetches real-time LINK and WETH prices from CoinGecko API (real market prices, not mock).Implementation:Source:
tools.ts:117-217Returns: USD prices for LINK and WETH, LINK/WETH ratio, and 24h price changesFallback: Falls back to CoinCap API if CoinGecko failsget_leverage_strategy_state
get_leverage_strategy_state
Gets comprehensive state of the leverage strategy including deposited amount, borrowed WETH, LTV, pause status, and leverage parameters.Implementation:Source:
tools.ts:220-265Returns: Deposited amount, borrowed WETH, net exposure, LTV, pause status, maxDepth, and borrowFactorget_vault_apy
get_vault_apy
Calculates the vault APY based on TVL growth over time.Implementation:Source:
tools.ts:268-334Returns: APY percentage, TVL, growth rate, and time deltaNote: Uses stateful context to track TVL changes over timeVault & Strategy Management Tools
vault_deposit
vault_deposit
Deposits LINK into the vault.Schema:Source:
tools.ts:342-357vault_withdraw
vault_withdraw
Withdraws shares from the vault.Schema:Source:
tools.ts:360-370rebalance_vault
rebalance_vault
Invokes the vault’s rebalance() function to reallocate funds according to target weights.Implementation:Source:
tools.ts:373-380harvest_strategy
harvest_strategy
Triggers harvest() to send back the profits into the vault.Implementation:Source:
tools.ts:383-390update_strategy_target_weights
update_strategy_target_weights
Updates target allocation weights for strategies (in basis points, must sum to 10000).Schema:Implementation:Source:
tools.ts:439-462Use case: Adjust portfolio allocation between leverage and Aave strategies based on market conditionsDefault weights: Leverage: 80%, Aave: 20%toggle_leverage_strategy_pause
toggle_leverage_strategy_pause
Pauses or unpauses the leverage strategy.Implementation:Source:
tools.ts:465-485Use case: Pause when market conditions are unfavorable or risk is too highupdate_leverage_params
update_leverage_params
Updates leverage strategy parameters (maxDepth and borrowFactor).Schema:Implementation:Source:
tools.ts:488-510Use case: Reduce values to decrease leverage risk when prices are volatileRisk Management Tools
check_liquidation_risk
check_liquidation_risk
Checks leverage strategy liquidation risk.Implementation:Source:
tools.ts:397-421Risk thresholds:- Safe: LTV < 70%
- Warning: 70% ≤ LTV < 80%
- Critical: LTV ≥ 80%
auto_deleverage
auto_deleverage
Repays debt to reduce liquidation risk.Implementation:Source:
tools.ts:424-436Note: Uses fixed deleverage amount of 10Decision Making Guidelines
Price-Based Decision Making
The agent ALWAYS checks LINK and WETH prices usingget_token_prices before making leverage strategy decisions.
Price monitoring logic:
- Monitor price movements and volatility to assess risk
- When LINK/WETH price ratio changes significantly (>10%):
- If prices are volatile or dropping rapidly → pause leverage strategy or reduce leverage params
- If prices are stable and favorable → can maintain or increase leverage
- Use price data to inform target weight adjustments between strategies
agent.ts:95-101
Leverage Strategy State Management
The agent regularly checks leverage strategy state usingget_leverage_strategy_state.
Management rules:
- Monitor LTV, borrowed amounts, and pause status
- When LTV exceeds 70% or prices are volatile → consider pausing or reducing leverage
- Adjust leverage parameters (maxDepth, borrowFactor) based on market conditions:
- High volatility → reduce maxDepth and borrowFactor
- Stable markets → can maintain or slightly increase
agent.ts:103-109
Target Weight Management
Default target weights:- Leverage: 80%
- Aave: 20%
- Market conditions favor one strategy over another
- Risk profile changes (e.g., reduce leverage strategy weight during high volatility)
- Price movements suggest reallocation is prudent
- Adjust target weights using
update_strategy_target_weights - Call
rebalance_vaultto execute the reallocation
agent.ts:111-118
Risk Detection
The agent detects risks early, including:- High LTV
- Excessive leverage
- Low buffer to liquidation
- Rapid price changes
- Divergence from target allocations
agent.ts:120-130
Behavioral Principles
The Strategy Sentinel Agent follows strict behavioral principles:- Be precise, risk-aware, and rule-driven
- Prefer safety over yield
- Explain reasoning based solely on tool outputs
- Chain multiple tools to reach correct conclusions
- Never assume or invent on-chain values
- Never perform an unsafe or unnecessary action
agent.ts:152-160