← All articles
Practical guideWorkflow testing

Regression tests for an AI agent that writes to a database and posts to Slack

Test what the agent did to the world, not what it said: the rows it wrote, the messages it posted and how many times. Run the same scenario on every pull request and fail the build when the final state changes.

In this article
Conceptual illustration · AgentTwin journal

Illustrative test design

Illustrative test design: one required record for the request, one required notification for that record, and unrelated state left unchanged.
Check the effects, not only the reply. Illustrative test design; this image is not a run result.

Test what the agent did to the world, not what it said: the rows it wrote, the messages it posted and how many times. Run the same scenario on every pull request, and fail the build when the final state changes.

Five steps

  1. Unit-test the tools. Test save_record and post_slack for validation, retries and idempotency. Use a real throwaway database (Postgres in a container, rolled back per test), because a mock can't catch bad SQL or a constraint violation.
  2. Assert on final state. After the workflow runs, check how many rows exist and with which values, and how many Slack messages were posted and to which channel.
  3. Replay failures, not just success. A timeout after a write, a duplicate webhook, a 500 on the second call. These are where double writes and double messages come from.
  4. Keep each failure as a regression. A scenario that found a bug becomes a permanent test, so the bug can't return unnoticed.
  5. Run it in CI on every pull request.

With AgentTwin

npx agenttwin runs your real code against twins of the services it calls, including real Postgres and Redis inside the sandbox, then compares every service's final state with a clean run. npx agenttwin check install writes a GitHub workflow so each pull request gets a check showing what the branch does to Stripe, Slack and your database.

Related: Write better workflow assertions and How to reset a multi-service test environment between runs.

Continue readingA practical checklist for evaluating workflow testing tools →
Evaluate one workflow

Can your workflow pass the same check after a failure?

Bring the entry point, dependency operations and result you need to preserve. Discuss whether AgentTwin supports the test, what preparation is needed and the scope and costs before proceeding.

Discuss your workflow Try the sample first →← Back to all articles