Architecture
The agent system follows a hierarchical structure:Root Agent
The root agent coordinates between specialized sub-agents:packages/agents/defi-portfolio/src/agents/agent.ts:6-19
Agent Types
Strategy Sentinel Agent
Monitors and manages vault strategies, including:- Real-time monitoring of vault and strategy states
- Risk assessment and liquidation prevention
- Price-based decision making for leverage strategies
- Automated rebalancing and harvesting
- Target weight management between strategies
Yield Simulator Agent
Generates yield for the vault by:- Accruing interest to the mock pool
- Simulating yield generation for testing
Chat Agent
User-facing assistant for:- Checking balances and vault information
- Preparing deposit and withdrawal transactions
- Managing token approvals
- Providing public vault metrics
Key Responsibilities
Monitoring & Analytics
Monitoring & Analytics
Agents continuously monitor:
- Vault total assets and managed balance
- Strategy-level deposited and borrowed amounts
- User share balances and withdrawable amounts
- Real-time token prices from CoinGecko
- Leverage ratios and LTV (Loan-to-Value)
- APY calculations based on TVL growth
Risk Management
Risk Management
Automated risk controls include:
- Liquidation risk detection
- Automated deleveraging when LTV exceeds thresholds
- Price volatility monitoring
- Strategy pause/unpause based on market conditions
- Leverage parameter adjustments (maxDepth, borrowFactor)
Portfolio Optimization
Portfolio Optimization
Optimization strategies:
- Target weight management (default: 80% Leverage, 20% Aave)
- Rebalancing to maintain target allocations
- Harvesting profits from strategies
- Dynamic allocation based on market conditions
User Interactions
User Interactions
User-facing capabilities:
- Deposit preparation with approval checks
- Withdrawal transaction generation
- Balance and share conversions
- Public vault information access
Agent Framework
All agents are built using the @iqai/adk (Agent Development Kit) which provides:- LlmAgent: Base class for creating LLM-powered agents
- createTool: Function for defining agent tools with schemas
- ToolContext: Context management for stateful operations
- AgentBuilder: Fluent API for building agent hierarchies
Tool Architecture
Each agent has access to specialized tools defined with Zod schemas:packages/agents/defi-portfolio/src/agents/sub-agents/strategy-sentinel-agent/tools.ts:17-45
Decision Making Principles
All agents follow these core principles:- Data-Driven: All decisions based on on-chain data from tools
- Safety First: Prefer capital preservation over yield
- Rule-Based: Use simulation and risk calculations, not assumptions
- Transparent: All actions explained with tool output references
- Secure: Strict privacy boundaries for user data
Next Steps
Explore each agent in detail:- Strategy Sentinel Agent - Portfolio management and risk
- Chat Agent - User interactions
- Yield Simulator Agent - Yield generation