Why Schedule This Agent?
Unlike incident response agents that react to alerts, cost optimization benefits from proactive, scheduled analysis:- Consistent monitoring: Runs automatically on the same schedule every month
- No input needed: Gathers data directly from your infrastructure using tools
- Actionable reports: Identifies specific resources and potential savings
- No alert fatigue: Generates insights on your schedule, not random alert timing
Creating A Scheduled Cost Optimization Agent
Let’s create an agent that runs on the 1st of every month, analyzes your AWS infrastructure, and generates a report of cost optimization opportunities. After installing Unpage, create the agent by running:$EDITOR. Paste the following agent definition:
Description: What the agent does
Thedescription explains the agent’s purpose. For scheduled agents, this helps you
remember what each agent does when reviewing your list of agents.
Schedule: When the agent runs
Theschedule section defines when the agent runs automatically. Unpage supports multiple cron formats:
Standard 5-field format (minute precision):
"0 9 1 * *"- Monthly on the 1st at 9 AM"0 9 * * 1"- Weekly on Mondays at 9 AM"0 0 * * *"- Daily at midnight"0 */6 * * *"- Every 6 hours"*/2 * * * * *"- Every 2 seconds (6-field format)
Prompt: What the agent should do
Theprompt contains detailed instructions for the agent. Since scheduled agents receive
no input payload, the prompt must specify:
- How to get data: Use graph and metrics tools to discover resources
- What to analyze: Clear criteria for identifying cost optimization opportunities
- Output format: Structure for the report
- What action to take: Create a PagerDuty incident with findings
Tools: What the agent can access
Thetools section grants permissions to specific infrastructure tools:
- Graph tools: Discover and query infrastructure resources
- Metrics tools: Analyze resource utilization over time
- AWS tools: Get detailed information about EC2 instances and volumes
- PagerDuty tools: Create incidents to deliver the report
aws_*) to grant access to all tools from a plugin.
To see all available tools:
Setting Up Your Infrastructure Graph
For the agent to discover AWS resources, you need to build your infrastructure knowledge graph:unpage graph build --interval 3600 to rebuild every hour.
See the knowledge graph documentation for details.
Running The Scheduler
To start the scheduler and have your agent run automatically on its schedule:- Loads all agents with schedule configurations
- Sets up cron jobs for each scheduled agent
- Runs agents automatically according to their schedules
- Logs output of each agent run
Testing Before Scheduling
Before relying on the schedule, test your agent manually:Example Output
When your scheduled agent runs, it will analyze your infrastructure and create a PagerDuty incident with findings like:Production Deployment
For production use, run the scheduler as a persistent service:Using systemd (Linux)
Create/etc/systemd/system/unpage-scheduler.service:
Using Docker
More Scheduled Agent Ideas
Once you have the scheduler running, consider adding more scheduled agents:Security Audits
Unused Resource Cleanup
Performance Trend Analysis
Compliance Checks
Best Practices
When creating scheduled agents:- Test thoroughly: Run manually several times before relying on the schedule
- Start conservative: Begin with weekly or monthly schedules, not daily
- Set clear outputs: Have agents create incidents or send notifications with findings
- Monitor execution: Check logs regularly to ensure agents are working as expected
- Include timestamps: Have agents log when they started and what period they analyzed
- Handle failures gracefully: Design prompts to continue even if some data is unavailable
- Document expectations: Note in prompts what data sources are required

