Skip to content
shimmer/docs
Run and compare

Write a Python harness

Connect your agent to the test runner with one small Python function.

On this page

A harness is the small adapter between Shimmer test cases and your agent. The runner imports a module, finds its ShimmerTest classes, and runs each class’s suite.

Define a test

Create harness.py in your Python project:

python
from shimmer import ShimmerTest, UserMessage
from support_bot import SupportBot


class TestRefunds(ShimmerTest):
    suite = "refunds"

    def run(self, messages: list[UserMessage]) -> None:
        bot = SupportBot()
        for message in messages:
            bot.reply(message.text)

suite is the exact name of a suite in your Shimmer org. Each harness can define one class per suite.

messages holds every user message from the case’s baseline trace, in order, so one call replays a whole multi-turn conversation. Each case gets a new instance of your class. The return value is ignored: Shimmer uses the collected trace to inspect and evaluate the result.

Your agent must produce LangSmith-instrumented activity during run. See LangSmith for an example using traceable and wrap_openai.

Run the harness

Run from a directory where harness can be imported:

terminal
LANGSMITH_TRACING=local shimmer suites run --path harness

Without a suite name, every suite defined in the harness runs. Add one to run a single suite:

terminal
LANGSMITH_TRACING=local shimmer suites run refunds --path harness

--path is a Python module or package name, not a filesystem path. For tests/harness.py in an importable package, use --path tests.harness. A package path also searches its submodules, so you can keep one test class per file.

Run cases in parallel

The runner executes cases in separate processes, up to one per CPU by default. Set --workers to change the limit:

terminal
LANGSMITH_TRACING=local shimmer suites run --path harness --workers 8

Because each process imports your harness, define test classes at module level in an importable module. --workers 1 runs every case in the CLI process, which lets you use a debugger.

Call an asynchronous agent

The runner calls run synchronously and does not await its result. Adapt an async agent inside run:

python
import asyncio

from shimmer import ShimmerTest, UserMessage
from support_bot import SupportBot


class TestRefunds(ShimmerTest):
    suite = "refunds"

    def run(self, messages: list[UserMessage]) -> None:
        bot = SupportBot()
        for message in messages:
            asyncio.run(bot.reply_async(message.text))

Use the same harness in CI

Commit the harness to your agent’s repository, then point the Shimmer GitHub Action at the same module:

yaml
permissions:
  contents: read
  id-token: write

steps:
  - name: Run Shimmer suite
    uses: getshimmer/run-tests@v1
    with:
      harness: harness
      test-suite: refunds
    env:
      LANGSMITH_TRACING: local

This example shows the job permissions and Shimmer step. Connect your repository to your Shimmer org so the Action can authenticate with GitHub OIDC. Install your agent’s dependencies before this step and provide its model and tool credentials in the step’s environment. The Action runs your harness on the GitHub runner and sends the results to your Shimmer org.