simulhausen 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,22 @@
1
+ simulhausen
2
+ Copyright 2026 Ilya Lubenets
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ This product includes material adapted from LangWatch Scenario
7
+ (https://github.com/langwatch/scenario, published on PyPI as
8
+ `langwatch-scenario`), Copyright LangWatch, licensed under the Apache License,
9
+ Version 2.0:
10
+
11
+ - The public API (`run`, the `user` / `agent` / `message` / `proceed` /
12
+ `judge` / `succeed` / `fail` script steps, `UserSimulatorAgent`,
13
+ `JudgeAgent`, `AgentAdapter`, `AgentInput`, `ScenarioState`,
14
+ `ScenarioResult`, `configure`) follows Scenario's design.
15
+ - The user simulator and judge prompts in `src/simulhausen/prompts.py` are
16
+ adapted from Scenario's `user_simulator_agent.py`, `judge_agent.py` and
17
+ `_judge/criterion_verdicts.py`; some of the judge rules are close to
18
+ verbatim. They were modified for agno structured output, the
19
+ `goal_achieved` stop signal and fenced untrusted evidence.
20
+
21
+ The implementation itself is independent and copies no other upstream code.
22
+ LangWatch Scenario ships no NOTICE file of its own.
@@ -0,0 +1,359 @@
1
+ Metadata-Version: 2.4
2
+ Name: simulhausen
3
+ Version: 0.1.0
4
+ Summary: Local simulation testing for agno agents: an LLM plays the user, an LLM judge grades the dialogue criterion by criterion.
5
+ Keywords: agents,agno,llm,testing,simulation,evaluation,llm-as-a-judge,pytest
6
+ Author: Ilya Lubenets
7
+ Author-email: Ilya Lubenets <lubenets.ilya.igorevich@gmail.com>
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ License-File: NOTICE
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Framework :: Pytest
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Topic :: Software Development :: Testing
22
+ Classifier: Typing :: Typed
23
+ Requires-Dist: agno>=3.0,<4
24
+ Requires-Dist: pydantic>=2.10
25
+ Requires-Dist: rich>=13
26
+ Requires-Python: >=3.12
27
+ Project-URL: Homepage, https://github.com/ormeilu/simulhausen
28
+ Project-URL: Repository, https://github.com/ormeilu/simulhausen
29
+ Project-URL: Issues, https://github.com/ormeilu/simulhausen/issues
30
+ Project-URL: Changelog, https://github.com/ormeilu/simulhausen/blob/main/CHANGELOG.md
31
+ Description-Content-Type: text/markdown
32
+
33
+ # simulhausen
34
+
35
+ [![PyPI](https://img.shields.io/pypi/v/simulhausen)](https://pypi.org/project/simulhausen/)
36
+ [![Python](https://img.shields.io/pypi/pyversions/simulhausen)](https://pypi.org/project/simulhausen/)
37
+ [![CI](https://github.com/ormeilu/simulhausen/actions/workflows/ci.yml/badge.svg)](https://github.com/ormeilu/simulhausen/actions/workflows/ci.yml)
38
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/ormeilu/simulhausen/blob/main/LICENSE)
39
+
40
+ Simulation testing for [agno](https://github.com/agno-agi/agno) agents that runs entirely on your side.
41
+ An LLM plays the user and holds a multi-turn dialogue with your agent, team or workflow. Then an LLM judge
42
+ grades the result against your criteria, one verdict and one reason per criterion.
43
+
44
+ The API follows [LangWatch Scenario](https://github.com/langwatch/scenario), minus the cloud: no LangWatch
45
+ account, no tracing backend, no litellm. The user simulator and the judge are plain agno agents on whatever
46
+ model you configure, and the reports land in your terminal, in a JSON file and in a markdown comment for your
47
+ pull request.
48
+
49
+ ```python
50
+ import simulhausen as sim
51
+
52
+ result = await sim.run(
53
+ name="refund: duplicated charge",
54
+ description="The user was charged twice for order 1042 and wants the extra charge refunded.",
55
+ agents=[
56
+ sim.agno_adapter(lambda: support_agent),
57
+ sim.UserSimulatorAgent(),
58
+ sim.JudgeAgent(criteria=[
59
+ "The agent looks the order up before promising anything",
60
+ "The agent does not invent a refund amount",
61
+ ]),
62
+ ],
63
+ )
64
+ assert result.success, result.failure_summary()
65
+ ```
66
+
67
+ ## Install
68
+
69
+ ```bash
70
+ uv add --dev simulhausen
71
+ ```
72
+
73
+ or `pip install simulhausen`. Python 3.12+ and agno 3.x. The pytest plugin registers itself on install.
74
+
75
+ ## Quick start
76
+
77
+ Configure the model for the simulator and the judge once, in `conftest.py`. Keep model construction inside the
78
+ fixture, so collecting tests never needs credentials:
79
+
80
+ ```python
81
+ # conftest.py
82
+ import pytest
83
+
84
+ import simulhausen as sim
85
+
86
+
87
+ @pytest.fixture(scope="session", autouse=True)
88
+ def configure_simulations() -> None:
89
+ from agno.models.openai import OpenAIChat
90
+
91
+ sim.configure(model=OpenAIChat(id="gpt-4.1-mini"), max_turns=8)
92
+ ```
93
+
94
+ Then write scenarios as ordinary async tests:
95
+
96
+ ```python
97
+ # test_support.py
98
+ import pytest
99
+
100
+ import simulhausen as sim
101
+
102
+
103
+ def _support_agent():
104
+ from myapp.agents import support_agent # lazy: imported only when the test runs
105
+
106
+ return support_agent
107
+
108
+
109
+ def _no_lookup_yet(state: sim.ScenarioState) -> None:
110
+ assert not state.has_tool_call("lookup_order"), state.tool_call_names()
111
+
112
+
113
+ @pytest.mark.simulation
114
+ async def test_refund_asks_for_order_number() -> None:
115
+ result = await sim.run(
116
+ name="refund: missing order number",
117
+ description="The user wants a refund but does not say which order it is about.",
118
+ agents=[
119
+ sim.agno_adapter(_support_agent, user_id="user-42"),
120
+ sim.UserSimulatorAgent(),
121
+ sim.JudgeAgent(criteria=["The agent asks for the order number before anything else"]),
122
+ ],
123
+ script=[
124
+ sim.user("i want my money back"),
125
+ sim.agent(),
126
+ _no_lookup_yet,
127
+ sim.judge(),
128
+ ],
129
+ )
130
+ assert result.success, result.failure_summary()
131
+ ```
132
+
133
+ `agno_adapter` takes the agent itself or a factory, and forwards extra keyword arguments to `arun`
134
+ (`session_state=...`, `user_id=...`). The whole scenario runs in one agno session. A runnable version lives in
135
+ [`examples/`](https://github.com/ormeilu/simulhausen/tree/main/examples).
136
+
137
+ ## Scripts
138
+
139
+ Without `script`, a run is `[proceed()]` followed by the judge's verdict. With a script you decide what happens
140
+ and in which order:
141
+
142
+ | Step | What it does |
143
+ |---|---|
144
+ | `user("text")` | user message with fixed text |
145
+ | `user()` | user message written by the simulator |
146
+ | `agent()` | call the agent under test |
147
+ | `agent("text")` | inject an agent reply without calling the agent |
148
+ | `message(role, "text")` | append any message as is, to seed earlier context |
149
+ | `proceed(turns=None, on_turn=..., on_step=...)` | simulator and agent talk on their own (see below) |
150
+ | `judge()` | final verdict on the judge's criteria; later steps still run |
151
+ | `judge(criteria=[...], additional_context=...)` | checkpoint: fails the scenario on the spot if a criterion fails, goes on otherwise |
152
+ | `succeed(reasoning)` / `fail(reasoning)` | end the scenario right here |
153
+ | any callable | gets the `ScenarioState`; sync or async; raise `AssertionError` to fail |
154
+
155
+ `proceed()` stops at the first of these: `turns` turns played, `max_turns` reached, the simulator reporting the
156
+ goal as achieved, or the judge concluding it has seen enough. The judge is not consulted before `min_turns`
157
+ agent turns. If it concludes while some criteria are still inconclusive and turns remain, the dialogue goes on
158
+ to collect the missing evidence.
159
+
160
+ When a script has a judge with criteria but no `judge()` step, the judge runs after the last step. It also runs
161
+ again there if the dialogue went on after its last verdict, so the final verdict always covers the whole
162
+ dialogue; a new final verdict replaces the previous one, while checkpoint verdicts accumulate.
163
+ `additional_context` gives the judge evidence the dialogue cannot show, such as a database row the agent was
164
+ supposed to write.
165
+
166
+ ## Verdicts and statuses
167
+
168
+ The judge answers per criterion: `passed`, `failed` or `inconclusive`, each with a restated requirement and its
169
+ reasoning. A criterion phrased as a prohibition ("the agent must not X") passes when X did not happen.
170
+ `inconclusive` means the evidence was not there, for example because the dialogue ended before the moment the
171
+ criterion depends on.
172
+
173
+ Every result gets one of three statuses:
174
+
175
+ - `PASS`: every criterion passed and no assertion failed.
176
+ - `FAIL`: a criterion failed, a script assertion failed, the judge score was below threshold, or `fail()` ran.
177
+ - `WARN`: the scenario could not be verified. Either the harness broke (`SimulationHarnessError`: the judge or
178
+ the simulator returned no structured output, the model backend kept failing), or some criteria came back
179
+ inconclusive and none failed.
180
+
181
+ WARN is kept out of the pass rate on purpose. A broken judge says nothing about your agent, and counting it as
182
+ a failure turns the pass rate into a measure of helper-LLM reliability. `pass_rate = PASS / (PASS + FAIL)`, and
183
+ the WARN count is reported next to it. Harness errors are still raised, so a plain pytest run fails on them.
184
+
185
+ `ScenarioResult` carries `verdicts`, `passed_criteria`, `failed_criteria`, `inconclusive_criteria`, the judge's
186
+ `reasoning`, `messages`, `tool_calls`, `turns`, `total_time` and `agent_time`.
187
+
188
+ For an overall quality gate on top of the criteria, `JudgeAgent(criteria, score_threshold=7)` also grades the
189
+ whole dialogue 1-10 with agno's `JudgeScorer`. Calibrate the threshold on known good and bad runs first.
190
+
191
+ ## Checking tools
192
+
193
+ `agno_adapter` collects every `ToolExecution` of the run, including those of team members, so assertions work
194
+ for teams too:
195
+
196
+ ```python
197
+ state.has_tool_call("lookup_order") # ran cleanly at least once
198
+ state.tool_call_names() # names in call order, with repeats
199
+ state.has_tool_calls_in_order(["search", "lookup_order"]) # subsequence; other calls may sit between
200
+ state.last_tool_call("lookup_order") # the ToolExecution, or None
201
+ ```
202
+
203
+ Only clean executions count: a call that errored, was rejected or is paused waiting for confirmation does not
204
+ satisfy `has_tool_call`. That matches `agno.scorer.ToolCallScorer`.
205
+
206
+ The judge sees the same evidence: the transcript, the RAG references the agent retrieved (with source URLs) and
207
+ a capped summary of tool executions, errors included. Each block is fenced with a random per-call tag and the
208
+ judge is told never to follow instructions inside them.
209
+
210
+ ## Writing scenarios that hold up
211
+
212
+ One scenario checks one behaviour from one starting state. When it fails, the name alone should tell you what
213
+ broke.
214
+
215
+ - `name` is the outcome in a few words, readable in a PR comment: `refund: asks for the order number`.
216
+ - `description` is for the simulator: starting conditions, the user's goal, how they behave. It is not a
217
+ criterion.
218
+ - Each criterion is a single observable requirement. "The answer is good" is not one.
219
+
220
+ Check in code whatever code can check: tool calls and their order, exact identifiers, an expected error, a call
221
+ that must not happen. Leave semantics to the judge: did the agent make something up, explain a limitation,
222
+ stick to what the tools returned.
223
+
224
+ Spell out the user messages that matter for the regression with `user("...")`. Use `user()` or `proceed()` only
225
+ where variety in the user's wording is part of what you test. Most regressions need one or two user/agent
226
+ pairs; every extra turn costs money and adds variance.
227
+
228
+ Do not paper over a reproducible failure with reruns. Look at `failure_summary()`, the tool evidence and the
229
+ transcript in the JSON report first: they tell an agent bug from a broken backend, a wrong assertion or a vague
230
+ criterion.
231
+
232
+ ## Running
233
+
234
+ Simulation tests call real models, so keep them out of the default run:
235
+
236
+ ```toml
237
+ [tool.pytest.ini_options]
238
+ addopts = "-m 'not simulation'"
239
+ asyncio_mode = "auto"
240
+ ```
241
+
242
+ ```bash
243
+ uv run pytest -m simulation # failures fail the run
244
+ uv run pytest -m simulation --sim-benchmark \
245
+ --sim-report reports/simulations.json \
246
+ --sim-report-md reports/simulations.md # always exits 0, writes reports
247
+ uv run pytest -m simulation -k refund -s --sim-debug # you type the user's messages
248
+ ```
249
+
250
+ Benchmark mode is for CI jobs that should stay green and post the outcome instead. After any run with
251
+ simulations, a rich table with every scenario, its verdicts, tools and dialogue is printed. With
252
+ `pytest-rerunfailures` only the last attempt is reported.
253
+
254
+ Parallel runs work with `pytest-xdist` (`-n 4`): each worker is its own process with its own event loop, and
255
+ the controller merges every worker's results into one report. Prefer that to `asyncio.gather` inside a test,
256
+ because agno agents and HTTP clients are usually process-wide singletons. When an agent's async clients bind to
257
+ the first event loop they see, run simulations on one session-scoped loop:
258
+
259
+ ```python
260
+ # conftest.py
261
+ def pytest_collection_modifyitems(items):
262
+ for item in items:
263
+ if item.get_closest_marker("simulation"):
264
+ item.add_marker(pytest.mark.asyncio(loop_scope="session"), append=False)
265
+ ```
266
+
267
+ ### Reports in pull requests
268
+
269
+ The markdown report starts with a hidden `<!-- simulhausen-report -->` marker and a headline such as
270
+ `๐ŸŸก 88% โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–‘ ยท PASS 154 / FAIL 21`. The emoji follows the pass rate (๐ŸŸข from 90% with no WARN, ๐ŸŸก from
271
+ 75%, ๐Ÿ”ด below), since one failure out of 175 is noise, not a regression. The bar shows passed, not verified and
272
+ failed scenarios out of all of them. On GitHub Actions:
273
+
274
+ ```yaml
275
+ - run: uv run pytest -m simulation --sim-benchmark --sim-report-md reports/simulations.md
276
+ - if: github.event_name == 'pull_request'
277
+ run: gh pr comment ${{ github.event.pull_request.number }} --body-file reports/simulations.md
278
+ env:
279
+ GH_TOKEN: ${{ github.token }}
280
+ ```
281
+
282
+ The report links the CI job when `CI_JOB_URL` (GitLab) or the `GITHUB_*` run variables are set.
283
+
284
+ ## Configuration
285
+
286
+ ```python
287
+ sim.configure(
288
+ model=..., # agno Model for the simulator and the judge (required)
289
+ parser_model=..., # optional agno Model that turns their answers into the schema
290
+ max_turns=10, # ceiling for proceed() and unscripted runs
291
+ min_turns=1, # the judge may not end the dialogue earlier
292
+ verbose=True, # log every message and verdict (logger "simulhausen")
293
+ debug=False, # ask for the user's messages on stdin
294
+ user_name="User", # labels in reports
295
+ agent_name="Agent",
296
+ )
297
+ ```
298
+
299
+ `run()` accepts `max_turns`, `min_turns`, `verbose` and `debug` per scenario. `UserSimulatorAgent` and
300
+ `JudgeAgent` accept their own `model` and `parser_model`, plus `system_prompt` to replace the built-in prompt
301
+ ([`simulhausen.prompts`](https://github.com/ormeilu/simulhausen/blob/main/src/simulhausen/prompts.py)). The simulator also takes a `persona`.
302
+
303
+ Set `parser_model` when your backend breaks structured output in thinking mode. Some vLLM setups with a
304
+ reasoning parser return empty or broken content when `response_format` meets reasoning; with a parser model,
305
+ agno sends `response_format` only to the parser call. The helper agents also retry an off-schema answer twice,
306
+ with a stricter instruction each time.
307
+
308
+ ## Custom adapters
309
+
310
+ `agno_adapter` covers agno agents, teams and workflows. It retries backend failures (a run that ended in
311
+ `RunStatus.error`, a proxy's HTML error page) and raises `SimulationBackendError` when they persist, while a
312
+ guardrail refusal (`InputCheckError`/`OutputCheckError`) counts as the agent's answer. For agents with
313
+ `output_schema`, pass `content_fn` to render the structured reply as text.
314
+
315
+ Anything else is a function or an `AgentAdapter` subclass:
316
+
317
+ ```python
318
+ async def call_my_api(input: sim.AgentInput) -> str:
319
+ return await my_client.chat(input.thread_id, input.last_new_user_message_str())
320
+
321
+ adapter = sim.function_adapter(call_my_api)
322
+
323
+
324
+ class MyAdapter(sim.AgentAdapter):
325
+ async def call(self, input: sim.AgentInput) -> sim.AgentTurn:
326
+ reply = await my_agent.respond(input.messages)
327
+ return sim.AgentTurn(content=reply.text, tools=reply.tool_executions)
328
+ ```
329
+
330
+ `AgentInput` has the whole transcript (`messages`), what changed since the agent last spoke (`new_messages`)
331
+ and the live `scenario_state`.
332
+
333
+ ## Compared with LangWatch Scenario
334
+
335
+ Ported: the script steps (`user`, `agent`, `message`, `proceed`, `judge` with inline criteria and
336
+ `additional_context`, `succeed`, `fail`), per-criterion `passed`/`failed`/`inconclusive` verdicts, the two-phase
337
+ judge (an argument-free continue/conclude decision, then the verdict), `min_turns`, simulator `persona` and
338
+ `system_prompt`, debug mode, `total_time`/`agent_time`.
339
+
340
+ Different: models are agno `Model` objects instead of litellm strings; the simulator reports `goal_achieved` so
341
+ unscripted dialogues end without filler; harness failures and inconclusive scenarios are WARN and stay out of
342
+ the pass rate; a script that ends without a judge verdict passes if its assertions passed; the judge also gets
343
+ RAG references and tool executions.
344
+
345
+ Not ported: anything that needs LangWatch (tracing, events, evaluators, remote traces), voice and realtime
346
+ agents, the red-team agents, the joblib cache and long-transcript discovery tools.
347
+
348
+ ## Development
349
+
350
+ ```bash
351
+ uv sync
352
+ just ci # ruff, ty, pytest with coverage
353
+ just precommit # every prek hook
354
+ ```
355
+
356
+ ## License
357
+
358
+ Apache-2.0, see [LICENSE](https://github.com/ormeilu/simulhausen/blob/main/LICENSE). simulhausen began as a local reimplementation of LangWatch Scenario
359
+ (Apache-2.0, Copyright LangWatch); its API and parts of its prompts follow Scenario. See [NOTICE](https://github.com/ormeilu/simulhausen/blob/main/NOTICE).