Docs/Backend Agents
DocsBackend & Data
Business

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.

1

Describe what the agent should do

Use plain English. Be specific about data sources, actions, and outputs. For example: "Every morning at 9am, fetch the top 5 posts from Hacker News, summarize each one using AI, and send the summaries to my Slack channel." The more concrete your description, the better the generated code.
2

AI generates Python code

GenMB generates a complete Python script with an 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.
3

Build and deploy to scheduler

The pipeline runs automatically: code is uploaded to GCS, a Cloud Scheduler job is created for your cron expression, and the agent transitions through generating → building → deploying → running states. This typically takes under 60 seconds.
4

Monitor run history

Open the Run History panel to view every execution — status, logs, output, duration, and whether it was triggered manually or by the scheduler. Use "Run now" to trigger a manual test run at any time.

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

ExpressionMeaning
*/15 * * * *Every 15 minutes
0 */6 * * *Every 6 hours
0 9 * * 1-5Weekdays at 9:00 AM
0 0 * * *Every day at midnight
0 8 * * 1Every 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.

The Cloud Scheduler job is automatically paused when you pause or disable the agent. Re-enabling resumes the schedule from the next occurrence — no runs are backfilled for the paused period.

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.

VariableDescription
AGENT_IDUnique identifier for this agent — use as a Firestore document key for per-agent state
GENMB_CALLBACK_URLURL for posting run results back to GenMB (called automatically by the runner)
GENMB_AGENT_TOKENAuth token for authenticating callback requests to the GenMB API
GENMB_AI_URLEndpoint for the built-in AI proxy — call for text generation, summarization, classification
YOUR_SECRET_NAMEAny 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 from run() 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.

Use Data Insights for ad-hoc exploration first, then add the most useful visualizations permanently to your app's dashboard.

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.
1

Specify the external API endpoint

Enter the base URL for the external API you want to connect to, along with the authentication method (API key, OAuth, or custom headers).
2

Configure authentication and headers

Add any required headers or credentials. These are stored securely on the server and never exposed in browser code.
3

Test with a sample request

Send a test request to verify authentication and response format before deploying to production.
4

Use in your app

Reference the connector in your app code. GenMB generates the correct client-side calls that route through the secure backend proxy.

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?
Scheduled Agents are AI-generated Python scripts that run on a cron schedule. Describe what you want the agent to do in plain English — GenMB generates the Python code, deploys it to a GKE worker pool, and runs it on your configured schedule. No infrastructure to manage.
What can a Scheduled Agent do?
Practically anything a Python script can do: make HTTP requests to external APIs, scrape websites with Playwright, call AI models for reasoning or content generation, read and write to Firestore for persistent state, upload and download files from GCS, send emails or Slack messages, and process data. Pre-installed packages include httpx, playwright, google-cloud-firestore, google-cloud-storage, and more.
How do I pass credentials to my agent?
Add secrets in the agent configuration panel. Secrets are encrypted at rest and injected as environment variables at runtime — your agent accesses them via os.environ. Never hardcode credentials in your agent description or code.
What happens if my agent fails?
The run is logged as failed with the full error output, traceback, and duration. The next scheduled run will attempt again automatically. Use the "Run now" button to test manually after investigating and fixing the issue. The distributed lock is released on failure so subsequent runs are not blocked.
Can I edit the generated agent code?
Yes. Each agent is linked to an app in the GenMB code editor. Open it to view the generated Python code, make edits, and save — changes take effect on the next run. The code editor supports full version history so you can roll back if needed.
How does Data Insights work?
Type a question in plain English about your app's data. GenMB translates it into a database query, executes it, and returns results with visualization suggestions. Pro feature.
What are Data Connectors?
Data Connectors provide a secure backend proxy for connecting to external APIs and data sources. Your credentials are protected with HMAC authentication and never exposed in client code.
Is my external data secure with Connectors?
Yes. All external requests flow through GenMB's backend proxy with HMAC authentication, schema caching, and rate limiting. API keys are stored securely and never exposed in browser code.

Ready to build?

Create your first app for free — no credit card required.