Skip to main content

MockWorld Tests Quickstart

Test AI agents that can’t be tested traditionally. Assert on outcomes, not reasoning paths.

1. Get your API key

Sign up at app.mokra.ai and copy your API key.
export MOKRA_API_KEY=mk_live_xxxxxxxxxxxxxxxx

2. Install the SDK

gem install mockworld

3. Create a MockWorld and run your agent

require 'mockworld'

# Create a world with the services your agent uses
world = mockworld(name: "Refund test", services: ["stripe", "shopify"])

# Run your agent inside the world
world.run do
  # Your agent code here
  # All HTTP calls are automatically intercepted
  agent.process_refund("order-1234")
end

4. See what happened

world.observe
Output:
╭─────────────────────────────────────────────────────────────╮
│  MockWorld: Refund test                                     │
│  Duration: 1.2s | Requests: 3                               │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  GET  shopify/admin/api/2024-01/orders/1234.json            │
│  → Retrieved order #1234 ($150.00, paid)                    │
│                                                             │
│  POST stripe/v1/refunds                                     │
│  → Created refund of $150.00                                │
│                                                             │
│  POST sendgrid/v3/mail/send                                 │
│  → Sent email to customer@example.com                       │
│                                                             │
╰─────────────────────────────────────────────────────────────╯
Plain English. Not raw traces.

5. Assert on outcomes

world.assert("a refund was created")
world.assert("refund amount is $150")
world.assert("customer was notified via email")
Output:
✓ a refund was created
✓ refund amount is $150
✓ customer was notified via email

Full example

require 'mockworld'

# 1. Create a MockWorld
world = mockworld(name: "Customer refund flow", services: ["stripe", "shopify", "sendgrid"])

# 2. Run your agent
world.run do
  # Agent runs autonomously
  # We don't control how many steps it takes
  agent.invoke("Process refund for upset customer Ana, order #1234")
end

# 3. See what the agent did
world.observe

# 4. Assert on outcomes (not paths)
world.assert("exactly one refund was created")
world.assert("refund amount matches order total")
world.assert("customer received confirmation email")
world.assert("no duplicate refunds")

Why this matters

Run 1: Agent takes 3 steps → creates refund → ✓ Pass Run 2: Agent takes 7 steps → creates refund → ✓ Pass Run 3: Agent takes 5 steps → creates refund → ✓ Pass Same test. Different paths. All passing. Because we test outcomes, not steps.

The three primitives

PrimitiveWhat it does
world.runWraps agent execution. All HTTP calls intercepted and routed to mock servers.
world.observeShows what the agent did in plain English.
world.assertVerifies outcomes regardless of execution path.

Next steps