Build a Scheduled Agent: Automate Any Task with AI-Generated Code
A step-by-step tutorial on building a Scheduled Agent in GenMB — from writing a plain-English description to reading your first successful run log.
Ambuj Agrawal
Founder
What Is a Scheduled Agent?
A Scheduled Agent is an AI-generated Python script that runs on a cron schedule in the cloud. You describe what you want it to do. GenMB writes the code, deploys it, and runs it on your schedule. You never touch a server, a Docker container, or a Cloud Scheduler configuration.
This tutorial walks through building a practical agent: one that monitors a website for new content, uses AI to summarize what it finds, and sends the summary to a Slack channel every morning.
Step 1: Describe the Agent
The description is your specification. Be concrete about data sources, actions, and outputs. Vague descriptions produce vague code.
Too vague:
"Monitor a website and send updates"
Good:
"Every weekday morning at 8am, fetch the latest 5 posts from https://news.ycombinator.com/rss, use AI to write a 2-sentence summary for each post, and send the summaries as a formatted message to my Slack channel using the SLACK_WEBHOOK_URL environment variable."
This description tells GenMB: the source URL, the fetch method (RSS), the AI operation (summarize), the output format (2 sentences per post), the delivery mechanism (Slack webhook), and where the credential lives (env var). The generated code will handle all of this.
Step 2: What GenMB Generates
After you submit the description, GenMB sends it to the AI and generates a complete Python script. Here's what the generated code looks like conceptually:
```python
import httpx
import os
import xml.etree.ElementTree as ET
async def run():
# Fetch RSS feed
async with httpx.AsyncClient() as client:
resp = await client.get("https://news.ycombinator.com/rss")
# Parse the 5 most recent items
root = ET.fromstring(resp.text)
items = root.findall(".//item")[:5]
posts = []
for item in items:
title = item.find("title").text
link = item.find("link").text
# Use built-in AI proxy to summarize
ai_url = os.environ["GENMB_AI_URL"]
async with httpx.AsyncClient() as client:
ai_resp = await client.post(ai_url, json={
"prompt": f"Summarize this in 2 sentences: {title}",
"max_tokens": 100
})
summary = ai_resp.json()["text"]
posts.append(f"*{title}*\n{summary}\n{link}")
# Send to Slack
message = "\n\n".join(posts)
slack_webhook = os.environ["SLACK_WEBHOOK_URL"]
async with httpx.AsyncClient() as client:
await client.post(slack_webhook, json={"text": message})
return {"posts_sent": len(posts)}
`
The code is stored in a linked app in your GenMB account. You can open it in the code editor to review or modify before deploying.
Step 3: Add Secrets
The generated code references SLACK_WEBHOOK_URL as an environment variable. Before deploying, add it as a secret in the agent configuration panel:
- Open the agent settings
- Find the Secrets section
- Click "Add secret"
- Name:
SLACK_WEBHOOK_URL, Value: your Slack webhook URL - Save
Secrets are encrypted at rest and injected as environment variables at runtime. They never appear in logs, code output, or the code editor view.
Step 4: Set the Schedule
In the Cron Schedule field, enter: 0 8 * * 1-5
This runs the agent at 8:00 AM every Monday through Friday. The format is standard Unix cron: minute, hour, day-of-month, month, day-of-week.
Other useful patterns:
0 */6 * * *— every 6 hours0 9 * * *— every day at 9am*/30 * * * *— every 30 minutes
Step 5: Run Manually to Test
Before waiting for the scheduled run, click "Run now" to trigger an immediate execution. The status indicator changes to "running" and the output panel populates in real time.
A successful first run looks like this in the logs:
`
[2026-03-14 08:00:01] Starting run
[2026-03-14 08:00:02] Fetching RSS from news.ycombinator.com
[2026-03-14 08:00:03] Parsed 5 items
[2026-03-14 08:00:05] Summarized post 1/5
[2026-03-14 08:00:07] Summarized post 2/5
...
[2026-03-14 08:00:14] Sent to Slack
[2026-03-14 08:00:14] Run complete
`
And the structured result: {"posts_sent": 5}
Check your Slack channel — the summaries should be there.
Step 6: Reading Run History
Every execution is stored in the Run History panel with:
- Status: success, failed, or running
- Trigger: scheduled or manual
- Duration: how long the run took (useful for staying under the 5-minute timeout)
- Logs: full stdout output
- Result: the dict returned by
run()
If a run fails, click on it to see the full error output and traceback. Fix the issue in the code editor, save, then click "Run now" to verify the fix before the next scheduled run.
What Else Can You Build?
This tutorial covered one pattern (fetch → AI process → deliver), but Scheduled Agents support far more:
Data sync: Pull records from an external CRM API and upsert them into your app's Firestore database every hour. Use a "last synced" timestamp stored in Firestore to only fetch changes.
Monitoring: Check the status of your deployed apps or external services every 5 minutes. Send a Slack alert if any return errors.
Report generation: Every Monday morning, query your database for the past week's metrics, format them with AI into a narrative summary, and email it to your team.
Social posting: Fetch content from RSS feeds or your database, use AI to write platform-appropriate copy, and post to social APIs via HTTP.
Web scraping: Use the pre-installed Playwright browser to scrape competitor pricing pages, extract structured data with BeautifulSoup, and store changes in Firestore for trend analysis.
The pattern is always the same: describe the task in plain English, let GenMB generate the code, add any credentials as secrets, set the schedule, test manually, and let it run.
Scheduled Agents are available on the Business plan. Head to the Automations section to create your first one.
Ambuj Agrawal
Founder
Award-winning AI author and speaker. Building the future of app development at GenMB.
Follow on LinkedIn