simulation client that lets you:
- Run simulations - Execute multi-turn conversations against your AI agent
- Define tasks - Create custom task implementations to wrap your agent
- Use lifecycle hooks - Run setup/teardown scripts around scenarios (
beforeAll,beforeEach,before,after,afterEach,afterAll) - Control concurrency - Manage parallel execution for throughput
netra.simulation to run multi-turn simulations and test your AI agents programmatically.
Getting Started
Thesimulation client is available on the main Netra entry point after initialization.
runSimulation
Execute a multi-turn conversation simulation against a dataset. Your task function is called repeatedly for each turn until the conversation completes.Parameters (SimulationOptions)
Response: SimulationResult
Completed Item (ConversationResult)
Completed Item (ConversationResult)
Failed Item (ConversationResult)
Failed Item (ConversationResult)
BaseTask
Create a custom task by extending theBaseTask abstract class. Your implementation wraps your AI agent and handles the conversation flow.
Implementation Requirements
Hooks (Pre/Post Scripts)
Multi-turn datasets often share state across scenarios. Rather than merging scenarios or forcing sequential execution, use hooks to set up and tear down state around scenario runs. Hooks run entirely on the SDK side — script code never leaves your environment. Lightweight metadata (function name and description) is sent to the backend so the Netra UI can show which hooks are configured. In the Netra dashboard (multi-turn Scenario Run Details → Conversation tab), configured hooks appear in collapsible Pre-script / Post-script panels with each hook’sname and description. Item run status badges include Prescript Failed and Postscript Failed.
Hook points
Context passing
setupContext is the merge of beforeAll + beforeEach + item before. It is passed to BaseTask.run, item after, and afterEach. If a before hook fails mid-way, teardown still receives the furthest successfully built setupContext (so afterEach can clean up what beforeEach created). afterAll receives only the run-level sharedContext, but its results include setup/first-turn failures as well as conversation failures.
Prefer beforeEach / afterEach when the same setup/teardown applies to every scenario. Use item-keyed before / after for scenario-specific logic.
SimulationHooks
.description property on each hook function so the Netra UI can display it (truncated to 200 characters).
Example
Keys in
before / after must be real datasetItemId values from your dataset. A prescript_failed item is terminal (eval suppressed); other scenarios continue. A postscript_failed item is also terminal, but eval is not suppressed — conversation evaluations remain valid. Wrap teardown in try/catch so cleanup errors do not mark otherwise-successful items postscript_failed.Complete Example
Next Steps
- Dashboard Query - Query dashboard metrics
- Usage Utilities - Query traces and spans
- Simulation Overview - Learn about simulation testing
- Evaluation - Evaluate AI outputs
