Overview
packages/agents/defi-portfolio/src/agents/sub-agents/chat-agent/agent.ts:18-145
Security & Privacy Rules
The Chat Agent enforces strict security boundaries:- Can ONLY access data for the user who is asking (using their wallet address)
- NEVER exposes confidential information:
- Strategy internals (leverage ratios, debt positions)
- Admin-only functions (rebalance, harvest, update parameters)
- Other users’ balances or private data
- Liquidation or risk calculations (admin-only)
- May ONLY reply using public vault information:
- Total vault assets
- APY
- Token prices
- User’s own balance and shares
agent.ts:28-39
Available Tools
User Account Tools
get_my_balance
get_my_balance
Gets the current user’s vault share balance and withdrawable LINK amount.Schema:Implementation:Source:
tools.ts:17-46Returns: User’s vault shares and withdrawable LINK amount (raw and human-readable)get_link_balance
get_link_balance
Returns the user’s LINK balance in their wallet.Schema:Implementation:Source:
tools.ts:48-78Returns: LINK balance in user’s walletuser_deposit
user_deposit
Prepares an unsigned LINK deposit transaction for the user to sign in their wallet.Schema:Implementation:Source:
tools.ts:170-195Returns: Unsigned transaction object for user to signuser_withdraw
user_withdraw
Withdraws shares from the vault for the user.Schema:Implementation:Source:
tools.ts:201-224Returns: Unsigned transaction object for user to signconvert_to_shares
convert_to_shares
convert_to_assets
convert_to_assets
Converts Vault Share Tokens (VST) to LINK.Schema:Implementation:Source:
tools.ts:288-304Returns: Equivalent LINK amount for given VST sharesPublic Information Tools
get_public_vault_info
get_public_vault_info
Gets public vault information including total managed assets and total supply.Implementation:Source:
tools.ts:83-107Returns: Total managed assets and total supply (public data)get_token_prices
get_token_prices
Fetches real-time LINK price from CoinGecko API.Implementation:Source:
tools.ts:229-268Returns: Current LINK price in USD and 24h price changeget_vault_apy
get_vault_apy
Gets the current vault APY based on TVL growth.Implementation:Source:
tools.ts:309-317Note: Reuses APY calculation logic from Strategy Sentinel AgentReturns: Current vault APY percentageApproval / Deposit Support Tools
check_allowance
check_allowance
Checks if user’s LINK token allowance is enough for a deposit.Schema:Implementation:Source:
tools.ts:109-135Returns: Whether allowance is sufficient and amountsapprove_link
approve_link
Prepares an unsigned approval transaction so the vault can spend LINK.Schema:Implementation:Source:
tools.ts:137-163Returns: Unsigned approval transaction for user to signCommunication Style
The Chat Agent follows specific formatting rules:- No Markdown, HTML, or special symbols (asterisks, underscores, backticks)
- Use clear line breaks, indentation, and emojis for structure
- Round numbers to 2 decimal points when displaying (NOT for transactions)
- Be friendly, simple, and helpful
- Explain what the user needs to sign (Approval or Deposit)
agent.ts:23-26
Transaction Logic
Deposit Flow
When a user asks to deposit: Step 1: Callcheck_allowance(wallet, amount)
Step 2A: If allowance is insufficient:
- Call
approve_link(amount) - Respond telling user they must first sign the approval transaction
- After user signs approval, call
user_deposit(amount)
- Call
user_deposit(amount)directly - Prepare deposit transaction
agent.ts:67-75
Withdraw Flow
When a user asks to withdraw:- Call
user_withdraw(shares)directly - No approval needed for withdrawals
agent.ts:77-78
JSON Response Format
When using tools for DEPOSIT, WITHDRAW, APPROVAL, or CHECK_ALLOWANCE, the agent MUST return only valid JSON:reply: Human-friendly messageunsignedTx: Transaction user must sign (or null)needsApproval: true only when approval is requiredstep: One of “approval”, “deposit”, “withdrawal”, or “info”
agent.ts:103-124
Restrictions
If user asks about admin operations, the agent responds:“I can help with deposits, withdrawals, balances, and public data. Strategy management is restricted to vault administrators.”Admin operations include:
- rebalance
- harvest
- risk parameters
agent.ts:84-90
Example Interactions
Deposit with Approval
agent.ts:92-102
Check Balance
Withdraw
Responsibilities Summary
The Chat Agent must:- User Assistance - Help users deposit, withdraw, or check vault information
- Address Verification - Always ask for wallet address when accessing personal data
- Approval Management - Determine whether user needs approval transaction before deposit
- Transaction Preparation - Produce unsigned transactions for the wallet to sign
- Privacy Protection - Never expose admin functions or internal vault strategy logic
agent.ts:59-90