---
title: "Test agents by the end state · Agent Wranglers"
url: https://agentwranglers.se/playbook/ai-features/agents-in-products/agent-scenario-tests
updated: 2026-10-20
licence: "All rights reserved"
---

# Test agents by the end state

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Recommended
- Chapter: [Agents in products](https://agentwranglers.se/playbook/ai-features/agents-in-products)
- Rule: Test an agent with scenarios that check the final state and the actions it must never take, not the exact sequence of steps.
- How: Write at least 20 scenarios per agent, each with a starting state, a user request, fake tools and the expected end state. Assert on what changed, such as one return created, and on what must not happen, such as no refund without approval. Agents reach the same goal by different paths, so step-by-step asserts fail for no reason. Run each scenario at least three times, as in [run each case several times](https://agentwranglers.se/playbook/ai-features/evals-and-quality/repeat-eval-runs).
- Check: CI runs the scenario set on every prompt, tool or model change. It fails when a scenario misses its end state or calls a forbidden tool in any run.

Example:

```ts
test('return request creates one return and no refund', async () => {
  const tools = fakeTools({ orders: [{ id: 'A-1042', customerId: 'u1', status: 'delivered' }] });
  const status = await runAgent(newRun({ userId: 'u1', request: 'I want to return order A-1042', tools }));
  expect(status).toBe('done');
  expect(tools.returns.created).toHaveLength(1);
  expect(tools.calls.map(call => call.name)).not.toContain('issue_refund');
});
```

```python
def test_return_request_creates_one_return_and_no_refund():
    tools = fake_tools(orders=[{"id": "A-1042", "customer_id": "u1", "status": "delivered"}])
    status = run_agent(new_run(user_id="u1", request="I want to return order A-1042", tools=tools))
    assert status == "done"
    assert len(tools.returns.created) == 1
    assert "issue_refund" not in [call.name for call in tools.calls]
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers ai features playbook: https://agentwranglers.se/playbook/ai-features/agents-in-products/agent-scenario-tests`.

- Previous: [Let runs pause and resume](https://agentwranglers.se/playbook/ai-features/agents-in-products/resumable-agent-runs)
- [Agents in products](https://agentwranglers.se/playbook/ai-features/agents-in-products)
