user-robotAutomation and Scripting

Automate AIP workflows from Python scripts, shell pipelines, or CI jobs. Use this guide when you need repeatable patterns for consistent output formats, resource promotion, and scheduling hooks that teammates can reuse across environments.

circle-info

For a full capability breakdown, refer to the AIP matrixarrow-up-right. Scheduling is available via SDK and REST API. CLI scheduling commands are under development.

circle-info

CLI automations can target resources by ID or unique name. When scripting loops, prefer IDs or add --select handling so partial name matches do not prompt for input mid-run.

circle-info

The CLI-focused sections double as a no-code playbook for data developers. Python snippets are optional and aimed at engineering teams extending these patterns in code.

Choose the Right Output Format

When to use: Tailor CLI output for downstream systems, docs, or logs before integrating into scripts.

# JSON for automation
aip agents get analytics-agent --view json > agent.json

# Markdown for docs
aip agents run analytics-agent --input "Create summary" --view md > REPORT.md

# Plain text for logs
aip agents run analytics-agent --input "Quick check" --view plain

Script Resource Promotion

When to use: Promote agents and tools between sandboxes, staging, and production with audit trails.

Use the export/import workflows from the Configuration management guidearrow-up-right as the source of truth. When you automate them, wrap the commands so your CI job can back up or promote resources in one run:

The script centralises resource selection for CI but defers ordering, validation, and import strategy to the configuration guide’s checklist.

Automate Prompt Iteration

When to use: Batch-run prompts for evaluation, regression testing, or manual review.

Extend the configuration guide’s rapid-iteration loop with automation steps that enforce reproducibility. Example nightly job:

This focuses on the scripting concerns—file paths, idempotent edits, and artifact capture—while the linked configuration guide covers the manual review and promotion steps.

Run Agents in CI

When to use: Block deployments until sanity checks pass or surface usage metrics in pipelines.

Store credentials in your CI secret manager and inject them as environment variables before executing.

Python Automation Pattern

When to use: Embed agent calls inside existing Python services, notebooks, or ETL jobs.

The renderer="silent" option suppresses streaming UI output so your script can capture the final text response directly.

Schedule Runs

When to use: Run the same agent input on a recurring timetable. Schedules execute automatically in the Asia/Jakarta (WIB) timezone.

Schedules require an agent_id, input, and a schedule. In the SDK you can pass a cron string or a structured config. For REST, send the structured schedule object shown below (cron strings are SDK-only). Cron strings use five fields: minute hour day_of_month month day_of_week. Each field supports *, ranges (e.g., 2-4), lists (0,6), and steps (*/N). The API returns a schedule_id for updates, deletes, and run history.

You can also use the agent facade for schedule operations; it infers agent_id from the Agent instance:

Schedule Configuration

Field
Format
Examples
Description

minute

0-59, *, */N, ranges, lists

0, */15, 30

Minute of the hour

hour

0-23, *, */N, ranges, lists

9, */2, 0

Hour of the day (WIB)

day_of_month

1-31, *, ranges, lists

1, 15, *

Day of the month

month

1-12, *, */N, ranges, lists

1, */3, *

Month of the year

day_of_week

0-6, *, */N, ranges, lists

0-4, 0,6, *

Day of week (0=Mon, 6=Sun)

circle-info

All schedules run in Asia/Jakarta (WIB) timezone. Plan your cron expressions accordingly.

Schedule Run History

Retrieve execution history for scheduled runs, including status, duration, and output. Run history is scoped to an agent; use schedule_id to narrow results, and a run_id to fetch output. These APIs return scheduled runs only.

List runs to filter by schedule, status, or paginate through history.

Get run results to fetch full output and metadata for a specific run.

Run status values:

Status
Description

started

Run has started execution

success

Run completed successfully

failed

Run encountered an error

cancelled

Run was cancelled

aborted

Run was aborted

unavailable

Run result is unavailable

Common automation failures

Symptom
Likely cause
Fix

Cron job exits with command not found

aip not on the scheduler PATH.

Prefix with the full path or source the profile before invoking the CLI.

CI run fails with 401 Unauthorized

Expired or missing API key in the runner environment.

Rotate credentials and inject them via secrets or environment variables per job.

Scripts hang on interactive prompts

CLI fuzzy search triggered by unfiltered lists.

Pass IDs, use --select, add a filter flag (--name, --type, etc.), or force --simple when you need non-interactive output.

SDK automation times out intermittently

Backend slow or default timeout too low.

Increase Client(timeout=...) or add retry logic with exponential backoff.

Automation Tips

When to use: Sense-check your automation plan before scaling or handing it off to new team members.

  1. Use JSON everywhere — it is the most resilient format for piping into tests or dashboards.

  2. Keep exports in Git — treat agent/tool JSON like infrastructure-as-code and review changes via pull requests.

  3. Log run IDs — responses include X-Run-ID; store it to trace streaming output later.

  4. Fail fast in CI — run set -euo pipefail (Bash) or equivalent constructs to surface agent errors quickly.

Last updated