Skip to main content
Use Prefect when the agent helps design or run a collection workflow, but scheduled execution needs durable state and retries.

Prerequisites

  • Python 3.10+
  • A Twexapi API key
  • A Prefect deployment or local flow runner
  • Storage for state such as next_cursor, last_success_at, and selected endpoint path

Pattern

  • Use MCP during planning and ad-hoc collection.
  • Persist the selected endpoint path, query parameters, and pagination state.
  • Run scheduled collection through Prefect tasks.
  • Use Twexapi REST directly for deterministic scheduled runs.

Flow skeleton

MCP planning prompt

Handoff payload

Ask the planning agent to return this payload, then store it in Prefect variables or your own config.

State to persist

Deployment recipe

1

Plan with MCP

Ask an agent to use explore and return the exact method, relative path, and parameters.
2

Codify the route

Store the selected endpoint in Prefect variables or your own config.
3

Run with REST

Use deterministic REST calls inside Prefect tasks.
4

Persist state

Save next_cursor, row counts, and last successful run time after every page.

Error handling

Testing checklist

  • Run the flow locally with count=5.
  • Verify logs include the selected path and request parameters.
  • Verify state persists after each successful page.
  • Verify retries do not duplicate rows because tweet_id or user_id is used as a primary key.