scenario
library documentation.
1. Installation
First, you need to install thescenario
library in your project. Choose your language below.
bash uv add langwatch-scenario
2. Configure Environment Variables
We recommend creating a.env
file in the root of your project to manage your environment variables.
.env
LANGWATCH_API_KEY
in your LangWatch project settings.
3. Create a Basic Scenario
Here’s how to create and run a simple scenario to test an agent. First, you need to create an agent adapter that implements your agent logic. For detailed information about agent integration patterns, see the agent integration guide.4. Grouping Your Sets and Batches
While optional, we strongly recommend setting stable identifiers for your scenarios, sets, and batches for better organization and tracking in LangWatch.id
: A unique and stable identifier for your scenario. If not provided, it’s often generated from thename
, which can be brittle if you rename the test.setId
: Groups related scenarios into a test suite. This corresponds to the “Simulation Set” in the UI.batchId
: Groups all scenarios that were run together in a single execution (e.g., a single CI job). You can use a CI environment variable likeprocess.env.GITHUB_RUN_ID
for this.