Backend & Data
Guide to Scheduled Agents, Data Insights, and Data Connectors for building powerful server-side automation.
Scheduled Agents require a Business plan. Data Insights requires Pro. Data Connectors are available on all plans.
Scheduled Agents
Scheduled Agents are AI-generated Python scripts that run on a cron schedule in the cloud. Describe what you want the agent to do — GenMB generates the code, deploys it to a shared GKE worker pool, and runs it on your configured schedule. Each run is logged with output, status, duration, and trigger type.
Business Plan Required — 3 Agent Limit
Scheduled Agents are a Business plan feature. You can create up to 3 agents per account. Each agent runs in a shared worker pool with a 5-minute execution timeout per run.AI-generated code
Describe what the agent should do in plain English. GenMB generates a complete Python script with an async def run() entry point and all required imports.
Cron scheduling
Standard cron expressions for any schedule — every 15 minutes, hourly, daily, weekdays only. Managed by Cloud Scheduler.
HTTP & API calls
Make authenticated requests to any external API. Pre-installed httpx client with async support. Headers, auth tokens, and request bodies all supported.
Playwright web automation
Scrape websites, fill forms, extract structured data, and take screenshots using Playwright. Full browser automation available in every agent.
Built-in AI proxy
Call AI models for reasoning, summarization, classification, or content generation via the GENMB_AI_URL environment variable. No API key needed.
Persistent state
Read and write to Firestore between runs. Store counters, last-run state, processed IDs, or any structured data that needs to persist across executions.
Secrets management
Add encrypted environment variables in the agent settings. Injected at runtime — credentials never appear in logs or code output.
Run history
Every execution is logged with status (success/failed/running), trigger type (scheduled/manual), duration, stdout output, and structured result.
5-minute execution timeout
Each agent run has a hard timeout of 300 seconds. Design your agents to complete within this window. For longer tasks, break them into smaller agents chained via Firestore state, or use webhook triggers to coordinate multi-step processes.Setting Up a Scheduled Agent
Creating a Scheduled Agent takes a few minutes. Describe what you want it to do, configure the schedule, add any secrets, and deploy.
Describe what the agent should do
AI generates Python code
async def run() entry point. The code includes all imports, error handling, and logging. You can view and edit the code in the linked app in the GenMB code editor before deploying.Build and deploy to scheduler
generating → building → deploying → running states. This typically takes under 60 seconds.Monitor run history
Agent Code & Capabilities
Every agent is a Python script with a single entry point: async def run(). GenMB generates this code based on your description and deploys it as-is. You can open the linked app in the code editor to view or modify it at any time.
Making HTTP API calls
import httpx, os
async def run():
api_key = os.environ["MY_API_KEY"]
async with httpx.AsyncClient() as client:
resp = await client.get(
"https://api.example.com/data",
headers={"Authorization": f"Bearer {api_key}"}
)
data = resp.json()
return {"records": len(data)}Using the built-in AI proxy
import httpx, os
async def run():
ai_url = os.environ["GENMB_AI_URL"]
async with httpx.AsyncClient() as client:
resp = await client.post(ai_url, json={
"prompt": "Summarize this in 3 bullet points: ...",
"max_tokens": 300
})
return {"summary": resp.json()["text"]}Persistent state with Firestore
from google.cloud import firestore
import os
async def run():
db = firestore.Client()
state_ref = db.collection("agent_state").document(os.environ["AGENT_ID"])
state = state_ref.get().to_dict() or {}
last_processed = state.get("last_id", 0)
# ... process new items since last_processed ...
state_ref.set({"last_id": new_last_id}, merge=True)
return {"processed": count}Pre-installed packages
Agents have access to:httpx, playwright, google-cloud-firestore, google-cloud-storage, beautifulsoup4, pandas, pydantic, and standard library modules. Mention any additional packages in your description and GenMB will include them in the generated requirements.txt.Schedule & Trigger
Agents run on a cron schedule managed by Cloud Scheduler. You can also trigger a run manually at any time for testing, or configure a webhook trigger for event-driven execution.
Common Cron Expressions
| Expression | Meaning |
|---|---|
| */15 * * * * | Every 15 minutes |
| 0 */6 * * * | Every 6 hours |
| 0 9 * * 1-5 | Weekdays at 9:00 AM |
| 0 0 * * * | Every day at midnight |
| 0 8 * * 1 | Every Monday at 8:00 AM |
| 30 17 1 * * | First of every month at 5:30 PM |
Manual trigger
Click "Run now" in the agent panel to trigger an immediate run outside the schedule. The run appears in history tagged as manual. Useful for testing after code changes.
Webhook trigger
Each agent has a unique webhook URL. POST to it to trigger an on-demand run. Useful for event-driven execution from external systems or other agents.
Secrets & Environment
Agents need credentials to call external APIs, send emails, or access third-party services. Add these as encrypted secrets — they are injected as environment variables at runtime and never stored in plaintext or logged.
| Variable | Description |
|---|---|
| AGENT_ID | Unique identifier for this agent — use as a Firestore document key for per-agent state |
| GENMB_CALLBACK_URL | URL for posting run results back to GenMB (called automatically by the runner) |
| GENMB_AGENT_TOKEN | Auth token for authenticating callback requests to the GenMB API |
| GENMB_AI_URL | Endpoint for the built-in AI proxy — call for text generation, summarization, classification |
| YOUR_SECRET_NAME | Any secret you add in the agent configuration panel — available as os.environ["YOUR_SECRET_NAME"] |
Never hardcode credentials
Do not include API keys, passwords, or tokens in your agent description or directly in the code editor. Always add them as secrets in the configuration panel. Credentials in code descriptions are visible in your account and may appear in generated code comments.Run History & Monitoring
Every agent execution is recorded in the Run History panel. Use it to debug failures, verify outputs, and understand execution patterns over time.
Status
success, failed, or running. Failed runs include the full error output and traceback.
Trigger type
scheduled (automatic) or manual (triggered via Run now or webhook).
Duration
Wall clock time for the run. Compare against the 300-second timeout.
Logs & output
Full stdout captured during execution. Print statements appear here.
Structured result
The dict returned by run() is stored as the run result for programmatic inspection.
Distributed lock
A per-agent lock prevents concurrent runs. If a run is still active when the next schedule fires, the new run is skipped and logged.
Use structured return values
Return a dict fromrun() with meaningful keys — e.g. {"emails_sent": 3, "errors": 0}. This makes run history scannable at a glance without reading full logs.Data Insights
Data Insights lets you query your app's data using natural language. Ask questions in plain English and get answers with visualization suggestions — no SQL or database knowledge required.
Pro plan required
Data Insights is a Pro feature. Free-tier users have access to the basic database browser for manual data exploration.Ask questions like "What were our top 5 products last month?" or "Show me daily signups for the past 30 days." GenMB translates your question into a database query automatically.
After each query, GenMB suggests the best visualization — bar chart, line graph, pie chart, or table. Click to add the visualization to your app. Data Insights works with your app's database (Firestore or PostgreSQL) and understands your schema to generate appropriate queries.
Data Connectors
Data Connectors provide a secure backend proxy for connecting your app to external data sources. REST APIs, databases, and third-party services are accessed through an authenticated proxy so your credentials are never exposed.
All requests flow through GenMB's backend proxy with HMAC token authentication. Your API keys and credentials are never exposed in client-side code. Schema caching improves performance by storing API response schemas, reducing latency for repeated queries.
Use connectors to pull data from CRMs, payment processors, analytics platforms, or any REST API into your GenMB app.
Rate limits
Each app is limited to 60 requests per minute per connector. Design your app to cache connector responses when possible and avoid unnecessary repeated calls.Specify the external API endpoint
Configure authentication and headers
Test with a sample request
Use in your app
Best Practices
Follow these guidelines to build reliable, maintainable backend automation.
Start simple, iterate
Begin with a minimal agent that does one thing — fetches data from an API and logs it. Verify it runs cleanly, then add complexity: processing, AI reasoning, output delivery. Debugging a 20-line agent is much easier than a 200-line one.Use idempotent operations whenever possible. If your agent processes records, store a "last processed ID" in Firestore and skip anything already handled. This makes reruns after failures safe and prevents duplicate actions.
Add explicit error handling and meaningful log output. A failed run with print("Starting fetch from API") and print(f"Fetched {len(items)} items") is much faster to debug than a silent failure.
Chain agents for long workflows
For workflows that exceed the 5-minute timeout — say, scraping 500 pages and generating AI summaries for each — split into two agents. Agent 1 collects URLs and stores them in Firestore. Agent 2 processes one batch per run. Use a Firestore queue pattern with a status field to track progress.Scheduled Agents can use Data Connectors to pull external data, process it with AI via the built-in proxy, and store results in your app's database for Data Insights queries. This combination creates a powerful end-to-end data pipeline — external source → agent transform → database → insight visualization.
FAQs
What are Scheduled Agents?▾
What can a Scheduled Agent do?▾
How do I pass credentials to my agent?▾
What happens if my agent fails?▾
Can I edit the generated agent code?▾
How does Data Insights work?▾
What are Data Connectors?▾
Is my external data secure with Connectors?▾
Ready to build?
Create your first app for free — no credit card required.