Skip to main content

Overview

Agent automation enables continuous monitoring and management of your DeFi protocols without manual intervention. MetaVault AI uses node-cron to schedule periodic agent tasks.

Installation

MonitoringService Class

The MonitoringService class manages automated agent execution using cron jobs.
src/crons/automation.ts

Cron Expression Patterns

Cron expressions use the following format:

Common Patterns

Monitoring Cycle Implementation

The monitoring cycle executes a series of agent tasks to assess vault health.
src/crons/automation.ts

Yield Generation Automation

Automate yield accrual to the pool:
src/crons/automation.ts

Telegram Notifications

Send monitoring summaries to Telegram:
src/crons/automation.ts

Initializing the Service

Start the monitoring service in your main application:
src/index.ts

Keep Alive Pattern

Keep the Node.js process running for continuous monitoring:
src/index.ts

Advanced Scheduling

Multiple Cron Jobs

Conditional Execution

Time-Based Logic

Error Handling

Retry Logic

Circuit Breaker

Monitoring Service Logs

Expected console output:

Environment Configuration

.env

Best Practices

1. Graceful Shutdown

Always handle shutdown signals to stop cron jobs cleanly:

2. Avoid Overlapping Executions

Prevent concurrent executions of the same job:

3. Logging and Observability

Log all cron executions with timestamps:

4. Test Cron Expressions

Use crontab.guru to validate cron expressions before deployment.

Next Steps

Building Agents

Learn how to build agents for automation

Tools & Functions

Create tools that agents use in automated tasks

ADK-TS Integration

Understand the ADK-TS integration patterns

Deployment

Deploy your automated agents to production