elicitor 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.
Files changed (92) hide show
  1. elicitor-0.1.0/LICENSE +21 -0
  2. elicitor-0.1.0/PKG-INFO +283 -0
  3. elicitor-0.1.0/README.md +254 -0
  4. elicitor-0.1.0/data/travel/backstories.jsonl +60 -0
  5. elicitor-0.1.0/data/travel/catalog.jsonl +200 -0
  6. elicitor-0.1.0/data/travel/personas.jsonl +60 -0
  7. elicitor-0.1.0/data/travel/prompts/backstory.txt +15 -0
  8. elicitor-0.1.0/data/travel/prompts/imagine.txt +14 -0
  9. elicitor-0.1.0/data/travel/prompts/judge.txt +17 -0
  10. elicitor-0.1.0/data/travel/prompts/pair.txt +21 -0
  11. elicitor-0.1.0/data/travel/prompts/phrase.txt +13 -0
  12. elicitor-0.1.0/data/travel/prompts/plan.txt +12 -0
  13. elicitor-0.1.0/data/travel/prompts/simulate.txt +19 -0
  14. elicitor-0.1.0/data/travel/prompts/styles.toml +9 -0
  15. elicitor-0.1.0/data/travel/prompts/update.txt +19 -0
  16. elicitor-0.1.0/data/travel/schema.toml +129 -0
  17. elicitor-0.1.0/experiments/demo.toml +35 -0
  18. elicitor-0.1.0/pyproject.toml +82 -0
  19. elicitor-0.1.0/setup.cfg +4 -0
  20. elicitor-0.1.0/src/elicitor/__init__.py +22 -0
  21. elicitor-0.1.0/src/elicitor/__main__.py +3 -0
  22. elicitor-0.1.0/src/elicitor/analysis/__init__.py +1 -0
  23. elicitor-0.1.0/src/elicitor/analysis/descriptive.py +176 -0
  24. elicitor-0.1.0/src/elicitor/analysis/figures.py +101 -0
  25. elicitor-0.1.0/src/elicitor/analysis/judge_report.py +647 -0
  26. elicitor-0.1.0/src/elicitor/analysis/report.py +382 -0
  27. elicitor-0.1.0/src/elicitor/analysis/stats.py +107 -0
  28. elicitor-0.1.0/src/elicitor/answer_model.py +79 -0
  29. elicitor-0.1.0/src/elicitor/backstories.py +87 -0
  30. elicitor-0.1.0/src/elicitor/belief.py +81 -0
  31. elicitor-0.1.0/src/elicitor/calibration.py +203 -0
  32. elicitor-0.1.0/src/elicitor/catalog.py +42 -0
  33. elicitor-0.1.0/src/elicitor/cli.py +319 -0
  34. elicitor-0.1.0/src/elicitor/datagen.py +40 -0
  35. elicitor-0.1.0/src/elicitor/demo.py +115 -0
  36. elicitor-0.1.0/src/elicitor/episode.py +152 -0
  37. elicitor-0.1.0/src/elicitor/experiments/__init__.py +1 -0
  38. elicitor-0.1.0/src/elicitor/experiments/config.py +159 -0
  39. elicitor-0.1.0/src/elicitor/experiments/health.py +144 -0
  40. elicitor-0.1.0/src/elicitor/experiments/runner.py +308 -0
  41. elicitor-0.1.0/src/elicitor/experiments/store.py +210 -0
  42. elicitor-0.1.0/src/elicitor/jsonl.py +20 -0
  43. elicitor-0.1.0/src/elicitor/judge.py +476 -0
  44. elicitor-0.1.0/src/elicitor/llm/__init__.py +10 -0
  45. elicitor-0.1.0/src/elicitor/llm/cache.py +73 -0
  46. elicitor-0.1.0/src/elicitor/llm/client.py +389 -0
  47. elicitor-0.1.0/src/elicitor/llm/mock.py +117 -0
  48. elicitor-0.1.0/src/elicitor/llm/providers.py +218 -0
  49. elicitor-0.1.0/src/elicitor/llm/roles.py +240 -0
  50. elicitor-0.1.0/src/elicitor/metrics.py +70 -0
  51. elicitor-0.1.0/src/elicitor/personas.py +96 -0
  52. elicitor-0.1.0/src/elicitor/phrasing.py +101 -0
  53. elicitor-0.1.0/src/elicitor/questions.py +83 -0
  54. elicitor-0.1.0/src/elicitor/recommender.py +91 -0
  55. elicitor-0.1.0/src/elicitor/resources.py +33 -0
  56. elicitor-0.1.0/src/elicitor/rng.py +17 -0
  57. elicitor-0.1.0/src/elicitor/schema.py +142 -0
  58. elicitor-0.1.0/src/elicitor/selectors/__init__.py +64 -0
  59. elicitor-0.1.0/src/elicitor/selectors/eig.py +90 -0
  60. elicitor-0.1.0/src/elicitor/selectors/eig_mc.py +97 -0
  61. elicitor-0.1.0/src/elicitor/selectors/entropy.py +27 -0
  62. elicitor-0.1.0/src/elicitor/selectors/fixed.py +24 -0
  63. elicitor-0.1.0/src/elicitor/selectors/random.py +24 -0
  64. elicitor-0.1.0/src/elicitor/session.py +214 -0
  65. elicitor-0.1.0/src/elicitor/simulator/__init__.py +42 -0
  66. elicitor-0.1.0/src/elicitor/simulator/llm.py +57 -0
  67. elicitor-0.1.0/src/elicitor/simulator/oracle.py +52 -0
  68. elicitor-0.1.0/src/elicitor/updaters/__init__.py +37 -0
  69. elicitor-0.1.0/src/elicitor/updaters/llm.py +65 -0
  70. elicitor-0.1.0/src/elicitor/updaters/rule.py +173 -0
  71. elicitor-0.1.0/src/elicitor.egg-info/PKG-INFO +283 -0
  72. elicitor-0.1.0/src/elicitor.egg-info/SOURCES.txt +90 -0
  73. elicitor-0.1.0/src/elicitor.egg-info/dependency_links.txt +1 -0
  74. elicitor-0.1.0/src/elicitor.egg-info/entry_points.txt +2 -0
  75. elicitor-0.1.0/src/elicitor.egg-info/requires.txt +9 -0
  76. elicitor-0.1.0/src/elicitor.egg-info/top_level.txt +1 -0
  77. elicitor-0.1.0/tests/test_belief.py +113 -0
  78. elicitor-0.1.0/tests/test_cli.py +34 -0
  79. elicitor-0.1.0/tests/test_eig.py +204 -0
  80. elicitor-0.1.0/tests/test_episode_and_runner.py +167 -0
  81. elicitor-0.1.0/tests/test_llm_components.py +211 -0
  82. elicitor-0.1.0/tests/test_llm_layer.py +387 -0
  83. elicitor-0.1.0/tests/test_m5.py +284 -0
  84. elicitor-0.1.0/tests/test_m6.py +209 -0
  85. elicitor-0.1.0/tests/test_m7.py +309 -0
  86. elicitor-0.1.0/tests/test_question_types.py +201 -0
  87. elicitor-0.1.0/tests/test_recommender.py +86 -0
  88. elicitor-0.1.0/tests/test_rule_and_oracle.py +104 -0
  89. elicitor-0.1.0/tests/test_runner_resume_and_analysis.py +286 -0
  90. elicitor-0.1.0/tests/test_schema_and_data.py +65 -0
  91. elicitor-0.1.0/tests/test_selectors.py +70 -0
  92. elicitor-0.1.0/tests/test_session.py +215 -0
elicitor-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jason Liu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,283 @@
1
+ Metadata-Version: 2.4
2
+ Name: elicitor
3
+ Version: 0.1.0
4
+ Summary: An LLM agent that chooses clarifying questions by expected information gain.
5
+ License-Expression: MIT
6
+ Project-URL: Repository, https://github.com/LhyJason/elicitor
7
+ Project-URL: Documentation, https://github.com/LhyJason/elicitor/blob/main/docs/SPEC.md
8
+ Project-URL: Issues, https://github.com/LhyJason/elicitor/issues
9
+ Keywords: llm,agent,preference elicitation,clarifying questions,information gain,bayesian,recommender
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Requires-Python: >=3.12
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: httpx>=0.27
21
+ Requires-Dist: matplotlib>=3.8
22
+ Requires-Dist: numpy>=1.26
23
+ Requires-Dist: pydantic>=2.7
24
+ Requires-Dist: scipy>=1.11
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=8; extra == "dev"
27
+ Requires-Dist: ruff>=0.6; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # Elicitor
31
+
32
+ An LLM agent that learns what a user wants by asking a few well-chosen questions. It keeps a
33
+ probability distribution over the user's preferences, picks each question by expected information
34
+ gain, updates the distribution from the free-text answer, and then recommends. Everything runs on
35
+ open models served locally or on a GPU cluster; no paid API is needed.
36
+
37
+ Inspired by an EECS 545 team project.
38
+
39
+ ```bash
40
+ pip install elicitor
41
+ elicitor demo # answer the agent's questions yourself; no LLM needed
42
+ ```
43
+
44
+ To use it from your own code, see [Use it in your own code](https://github.com/LhyJason/elicitor#use-it-in-your-own-code).
45
+ [Elicitor-Distill](https://github.com/LhyJason/elicitor-distill) replaces the agent's 32B updater
46
+ and the 70B judge with fine-tuned 0.6B to 4B models, so the LLM updater runs on a laptop GPU.
47
+
48
+ ## How it works
49
+
50
+ The domain is trip planning: 9 slots (climate, setting, pace, lodging, food, activity, transport,
51
+ plus budget and trip length as binned constraints), a 200-item synthetic catalog and 60 synthetic
52
+ users (12 for development, 48 for evaluation) with known ground truth and one of four answer
53
+ styles: direct, vague, rambling or indifferent.
54
+
55
+ One episode is a dialogue of at most K questions:
56
+
57
+ 1. **Belief.** One categorical distribution per slot, starting from the prior.
58
+ 2. **Question selection.** `fixed` (schema order), `random`, `max_entropy` (the slot with the
59
+ most uncertainty), `entropy_choice` (the same slot, asked as a choice between its likeliest
60
+ values), `eig` (the open, choice or yes/no question with the largest expected information gain
61
+ under an answer-noise model, computed exactly) and `eig_mc` (expected gain estimated by
62
+ sampling simulated answers from the LLM and running the updater on them).
63
+ 3. **Simulated user.** llama3.3 70B role-plays the persona in its answer style and is told to
64
+ answer only what was asked; how often it volunteers other slots is measured.
65
+ 4. **Belief update.** Either a keyword matcher (`rule`) or the LLM (`llm`, qwen3 32B), which
66
+ scores how well the answer fits each value; Bayes' rule is applied in code in both cases.
67
+ 5. **Recommendation.** The catalog is ranked by expected utility under the belief and scored
68
+ against the true preferences: regret, hit@k and constraint violations.
69
+
70
+ Question wording is a template by default; LLM rewording is one ablation. The full design and
71
+ every decision taken along the way are in [docs/SPEC.md](https://github.com/LhyJason/elicitor/blob/main/docs/SPEC.md).
72
+
73
+ ## Results
74
+
75
+ Full run: 12 arms × 48 evaluation personas × 5 replicates at K = 3, 5 and 8 (8,160 episodes),
76
+ 4.3 hours on 4 A40 GPUs, about 230,000 LLM calls (most served from the reply cache) with no failed
77
+ calls and no parse failures. Each metric is averaged over a persona's replicates first; arms are
78
+ compared with paired Wilcoxon tests over the 48 personas with Holm correction. The hypotheses
79
+ were frozen before the run (SPEC Q13). Complete tables:
80
+ [results_summary/m5_full/results.md](https://github.com/LhyJason/elicitor/blob/main/results_summary/m5_full/results.md).
81
+
82
+ At K = 5 (95 % bootstrap CIs in the full table):
83
+
84
+ | selector | updater | mass on truth | MAP accuracy | regret | violations |
85
+ |---|---|---|---|---|---|
86
+ | `fixed` | `llm` | 0.488 | 0.647 | 0.089 | 1.08 |
87
+ | `random` | `llm` | 0.511 | 0.654 | 0.101 | 0.73 |
88
+ | `max_entropy` | `llm` | 0.513 | 0.656 | 0.112 | 1.24 |
89
+ | `entropy_choice` | `llm` | 0.490 | 0.654 | 0.110 | 1.21 |
90
+ | `eig` | `llm` | 0.513 | 0.656 | 0.112 | 1.24 |
91
+ | `eig_mc` | `llm` | **0.541** | **0.668** | 0.110 | **0.34** |
92
+ | `eig` | `rule` | 0.507 | 0.569 | 0.119 | 1.20 |
93
+
94
+ Mass on truth is the mean probability the belief puts on the true value of each slot (the
95
+ primary metric); MAP accuracy is the share of slots whose most probable value is the true one;
96
+ violations count the constraint slots the top recommendation breaks (0 to 2).
97
+
98
+ ![Probability on the true value per turn, K = 5](https://raw.githubusercontent.com/LhyJason/elicitor/main/docs/figures/m5_full/curve_mass_on_truth_K5.png)
99
+
100
+ What held and what did not:
101
+
102
+ - **H1, principled selection beats fixed and random order: not supported.** `eig` beats `fixed`
103
+ only at K = 5 with the LLM updater (+0.026 mass on truth, Holm p < 0.001). At K = 8 the two are
104
+ identical, because both end up asking the same 8 of the 9 slots, and `random` is slightly ahead
105
+ of `eig` with either updater (+0.010). With nine slots of 3 to 5 values each, question order
106
+ has little room to matter.
107
+ - **H2, `eig` equals `max_entropy` under the measured answer noise: holds exactly.** The noise
108
+ per question type was measured on the development personas before the run: the LLM updater
109
+ reads the right value from 99 % of open answers, 97 % of choice answers and 85 % of yes/no
110
+ answers. With open questions the most reliable, the question with the largest expected gain is
111
+ always the open question on the most uncertain slot, so `eig` asked `max_entropy`'s questions in
112
+ every episode and every metric is identical. (In an earlier run with a rule-based user and the
113
+ opposite noise, 0.7 / 0.8 / 0.9, `eig` beat `max_entropy` by 0.057 at K = 5: its edge comes
114
+ entirely from the noise model.) Listing the options (`entropy_choice`) is worse at K = 3
115
+ (−0.03 with either updater) and at K = 5 with the LLM updater (−0.024).
116
+ - **`eig_mc` is the one selector that helps**, against the frozen prediction that it would not:
117
+ +0.027 mass on truth over `eig` at K = 5 and 0.90 fewer constraint violations (both Holm
118
+ p < 0.001). Regret and hit@1 do not change. It needs several LLM calls per candidate question,
119
+ so it was run at K = 5 only; why its questions do better has not been analysed.
120
+ - **H3, the LLM updater beats the keyword updater: not supported on the primary metric.** Mass
121
+ on truth does not differ for any selector. MAP accuracy does, for every selector: +0.04 to +0.08
122
+ at K = 3, +0.06 to +0.10 at K = 5, +0.11 to +0.13 at K = 8 (all Holm p < 0.01). The LLM updater
123
+ picks the right value more often without putting more probability on it. Split by answer
124
+ style (descriptive, 12 personas per style), the null on mass on truth is an average of
125
+ opposite effects: the LLM updater puts more mass on the truth for direct (+0.01 to +0.04) and
126
+ rambling answers (+0.01 to +0.06), about the same for vague ones, and less for indifferent ones
127
+ (−0.03 to −0.09, every CI below zero). So the predicted pattern, a gap that grows from direct to
128
+ vague answers, does not appear on mass on truth. It does appear on MAP accuracy: at K = 8 the
129
+ gain is +0.15 to +0.20 for vague and rambling answers, +0.08 to +0.14 for direct ones and about
130
+ +0.01 for indifferent ones. Tables:
131
+ [styles.csv](https://github.com/LhyJason/elicitor/blob/main/results_summary/m5_full/styles.csv).
132
+ - **H4, a better final belief goes with lower regret: holds, weakly, for mass on truth.** Across
133
+ the 240 episodes of each arm and budget, the Spearman correlation between final mass on truth
134
+ and regret is negative in 33 of 34 cases (−0.05 to −0.35; the exception is +0.10). MAP accuracy
135
+ is not related to regret (−0.19 to +0.25), which fits the LLM updater raising MAP accuracy
136
+ without lowering regret. Tables:
137
+ [correlations.csv](https://github.com/LhyJason/elicitor/blob/main/results_summary/m5_full/correlations.csv).
138
+ - **Phrasing:** LLM rewording of the questions changes nothing measurable (largest difference
139
+ −0.006 mass on truth, not significant).
140
+
141
+ Limits: the users are simulated by an LLM that knows its whole profile, there is one domain, the
142
+ belief treats slots as independent, and regret is measured on a synthetic catalog.
143
+
144
+ ### An LLM judge checked against the true utility
145
+
146
+ Because the catalog's utility is known, it can test what is usually used when it is not: an LLM
147
+ judge. The judge study runs no new dialogues. For each of the 48 evaluation personas (replicate 0
148
+ of the full run) it takes the items the agent recommended, the best catalog item and one random
149
+ item, 256 distinct (persona, item) units. Each unit is scored 0 to 10 by two judges, llama3.3 70B
150
+ (the simulator's model, the main judge) and qwen3 32B (the agent's model), in three presentations:
151
+ the item's attribute list, and a short trip plan written by either model. Two pairs of arms are
152
+ also compared head to head, in both orders. That is about 2,000 LLM calls, 42 minutes on 4 A40
153
+ GPUs, with no failed calls and no parse failures. The hypotheses were frozen before any judge
154
+ call (SPEC Q13); the tests are as above. Complete tables:
155
+ [results_summary/m7_judge/results.md](https://github.com/LhyJason/elicitor/blob/main/results_summary/m7_judge/results.md).
156
+
157
+ - **J1, the judge tracks utility: holds.** Spearman correlation 0.87 [0.83, 0.91] for the main
158
+ judge on the list, and 0.74 to 0.82 for the other judge and presentation combinations.
159
+ - **J2, the judge keeps the utility order: holds for two of three steps.** An item recommended at
160
+ K = 8 scores 2.1 points above one recommended at K = 3, which scores 2.0 above a random item
161
+ (both Holm p < 0.001). The best catalog item scores only 0.22 above the K = 8 recommendation
162
+ (Holm p = 0.15).
163
+ - **J3, the judge prefers `eig_mc`'s items for their constraints: not supported.** `eig_mc` + llm
164
+ scores 0.44 above `eig` + llm at K = 5 (CI −0.10 to +0.98, Holm p = 0.22). Head to head, judges
165
+ that gave the same verdict in both orders picked `eig_mc`'s item 21 times to 8. The judges do
166
+ weigh the slots unevenly although the rubric says every preference counts the same: a
167
+ least-squares fit gives budget a weight of 2.0 to 2.8 and food 0.4 to 0.7, against 1.11 for each
168
+ slot in the utility.
169
+ - **J4, a written plan scores higher than the list: not supported** (+0.12, Holm p = 0.22). Plans
170
+ make the main judge slightly less accurate: Spearman 0.79 and 0.82 against 0.87 for the list.
171
+ - **J5, each judge favours its own model's plans: not supported** (+0.09, p = 0.23).
172
+ - **J6, verdicts depend on the order: half holds.** The verdict changed when the two items were
173
+ swapped in 28 % of pairs (the frozen bar was 10 %), but the share of decisive verdicts for the
174
+ item shown first, 0.42, does not differ from 1/2 after Holm (p = 0.055 before, 0.22 after), so
175
+ J6 as frozen fails. When the verdict did not change with the order, it picked the item of higher
176
+ utility in 93 % and 94 % of pairs.
177
+ - **Leniency:** the main judge is strict: a random item averages 2.4 and the best item 6.8 out of
178
+ 10. On the list, the agent's model gives items of utility below 0.6 and the random items 0.6 to
179
+ 0.8 points more.
180
+
181
+ ![Mean judge score against true utility](https://raw.githubusercontent.com/LhyJason/elicitor/main/docs/figures/m7_judge/score_vs_utility.png)
182
+
183
+ ## Quick start
184
+
185
+ From a clone of the repo:
186
+
187
+ ```bash
188
+ pip install -e .
189
+ elicitor demo # you answer the questions; no LLM needed
190
+ elicitor run experiments/m1_no_llm.toml # no LLM needed; writes results/m1_no_llm/
191
+ elicitor run experiments/m2_mock.toml # every LLM code path on the mock backend
192
+ elicitor run experiments/m3_eig.toml # EIG vs the baselines, rule-based user, no LLM
193
+ ```
194
+
195
+ Run the experiments from the repo root; the demo runs from any folder. It asks up to five
196
+ questions chosen by `eig`, shows the belief after each answer and ends with the three best
197
+ catalog items.
198
+ `elicitor demo --selector max_entropy --budget 8` changes the agent; with
199
+ [Ollama](https://ollama.com) running locally and `ollama pull qwen3:4b`,
200
+ `elicitor demo --updater llm` uses the LLM updater.
201
+
202
+ Then, for any run folder:
203
+
204
+ ```bash
205
+ elicitor health results/m2_mock # progress and per-role LLM failure rates (also mid-run)
206
+ elicitor analyze results/m3_eig # tables, paired tests and curves in results/m3_eig/analysis/
207
+ ```
208
+
209
+ A run into an existing folder resumes; `--fresh` starts over (the LLM reply cache is kept).
210
+ `analyze --publish` writes the committed tables in `results_summary/` and figures in
211
+ `docs/figures/`, and refuses runs that are incomplete, cut short or made with the mock backend.
212
+
213
+ ## Use it in your own code
214
+
215
+ A `Session` is one dialogue that your code drives: it hands you the next question, you bring
216
+ back the user's answer.
217
+
218
+ ```python
219
+ from elicitor import Session
220
+
221
+ session = Session.from_config() # travel domain, `eig` + rule updater, no LLM
222
+ while (question := session.next_question()) is not None:
223
+ session.observe(input(question + "\n> "))
224
+ for rec in session.recommend(3):
225
+ print(rec.item.id, round(rec.expected_utility, 2), rec.item.attrs)
226
+ ```
227
+
228
+ `session.belief` is the current distribution per slot, `session.turns` the dialogue so far and
229
+ `session.stop_reason` why it ended (budget, confident or exhausted). `Session.from_config(path)`
230
+ takes any experiment file; `selector=`, `updater=`, `phraser=` and `budget=` override it. For
231
+ your own domain, pass a schema and a catalog:
232
+
233
+ ```python
234
+ from elicitor import Session, load_catalog, load_schema
235
+
236
+ session = Session(
237
+ load_schema("my_domain/schema.toml"),
238
+ catalog=load_catalog("my_domain/catalog.jsonl"),
239
+ selector="max_entropy",
240
+ budget=8,
241
+ )
242
+ ```
243
+
244
+ The LLM updater needs a client built from an `[llm]` table and the domain's prompt files:
245
+
246
+ ```python
247
+ from elicitor import Session
248
+ from elicitor.experiments.config import load_config
249
+ from elicitor.llm import build_client
250
+
251
+ config = load_config("experiments/demo.toml")
252
+ client = build_client(config.llm, config.prompts_dir, "llm_cache.sqlite")
253
+ session = Session.from_config(config, updater="llm", client=client)
254
+ ```
255
+
256
+ The travel domain's schema, catalog and prompts ship with the package. The prompts are written
257
+ for travel; a new domain needs its own `schema.toml` and prompt files (see `data/travel/`).
258
+
259
+ ## Running the full experiment
260
+
261
+ `experiments/m5_full.toml` is the run above. `cluster/` holds the Slurm scripts: copy
262
+ `cluster/local.env.example` to `cluster/local.env`, fill in your account and partition, then run
263
+ `cluster/submit.sh cluster/full.sbatch`. The job starts Ollama servers on the GPUs (qwen3:32b for
264
+ the agent, llama3.3 70B for the simulated user), runs the grid with resume, checks run health and
265
+ publishes the analysis. `elicitor calibrate` measures the answer noise per question type and
266
+ `elicitor make-backstories` writes the persona backstories; both results are frozen in the repo.
267
+ `cluster/submit.sh cluster/judge.sbatch experiments/m7_judge.toml` runs the judge study on the
268
+ finished run and publishes its tables.
269
+
270
+ ## Development
271
+
272
+ ```bash
273
+ python -m venv .venv
274
+ source .venv/bin/activate # Windows: .venv\Scripts\activate
275
+ pip install -e ".[dev]"
276
+ ruff check . && ruff format --check . && pytest
277
+ ```
278
+
279
+ CI runs the tests and the no-LLM and mock suites on Linux and Windows.
280
+
281
+ ## License
282
+
283
+ MIT, see [LICENSE](https://github.com/LhyJason/elicitor/blob/main/LICENSE).
@@ -0,0 +1,254 @@
1
+ # Elicitor
2
+
3
+ An LLM agent that learns what a user wants by asking a few well-chosen questions. It keeps a
4
+ probability distribution over the user's preferences, picks each question by expected information
5
+ gain, updates the distribution from the free-text answer, and then recommends. Everything runs on
6
+ open models served locally or on a GPU cluster; no paid API is needed.
7
+
8
+ Inspired by an EECS 545 team project.
9
+
10
+ ```bash
11
+ pip install elicitor
12
+ elicitor demo # answer the agent's questions yourself; no LLM needed
13
+ ```
14
+
15
+ To use it from your own code, see [Use it in your own code](https://github.com/LhyJason/elicitor#use-it-in-your-own-code).
16
+ [Elicitor-Distill](https://github.com/LhyJason/elicitor-distill) replaces the agent's 32B updater
17
+ and the 70B judge with fine-tuned 0.6B to 4B models, so the LLM updater runs on a laptop GPU.
18
+
19
+ ## How it works
20
+
21
+ The domain is trip planning: 9 slots (climate, setting, pace, lodging, food, activity, transport,
22
+ plus budget and trip length as binned constraints), a 200-item synthetic catalog and 60 synthetic
23
+ users (12 for development, 48 for evaluation) with known ground truth and one of four answer
24
+ styles: direct, vague, rambling or indifferent.
25
+
26
+ One episode is a dialogue of at most K questions:
27
+
28
+ 1. **Belief.** One categorical distribution per slot, starting from the prior.
29
+ 2. **Question selection.** `fixed` (schema order), `random`, `max_entropy` (the slot with the
30
+ most uncertainty), `entropy_choice` (the same slot, asked as a choice between its likeliest
31
+ values), `eig` (the open, choice or yes/no question with the largest expected information gain
32
+ under an answer-noise model, computed exactly) and `eig_mc` (expected gain estimated by
33
+ sampling simulated answers from the LLM and running the updater on them).
34
+ 3. **Simulated user.** llama3.3 70B role-plays the persona in its answer style and is told to
35
+ answer only what was asked; how often it volunteers other slots is measured.
36
+ 4. **Belief update.** Either a keyword matcher (`rule`) or the LLM (`llm`, qwen3 32B), which
37
+ scores how well the answer fits each value; Bayes' rule is applied in code in both cases.
38
+ 5. **Recommendation.** The catalog is ranked by expected utility under the belief and scored
39
+ against the true preferences: regret, hit@k and constraint violations.
40
+
41
+ Question wording is a template by default; LLM rewording is one ablation. The full design and
42
+ every decision taken along the way are in [docs/SPEC.md](https://github.com/LhyJason/elicitor/blob/main/docs/SPEC.md).
43
+
44
+ ## Results
45
+
46
+ Full run: 12 arms × 48 evaluation personas × 5 replicates at K = 3, 5 and 8 (8,160 episodes),
47
+ 4.3 hours on 4 A40 GPUs, about 230,000 LLM calls (most served from the reply cache) with no failed
48
+ calls and no parse failures. Each metric is averaged over a persona's replicates first; arms are
49
+ compared with paired Wilcoxon tests over the 48 personas with Holm correction. The hypotheses
50
+ were frozen before the run (SPEC Q13). Complete tables:
51
+ [results_summary/m5_full/results.md](https://github.com/LhyJason/elicitor/blob/main/results_summary/m5_full/results.md).
52
+
53
+ At K = 5 (95 % bootstrap CIs in the full table):
54
+
55
+ | selector | updater | mass on truth | MAP accuracy | regret | violations |
56
+ |---|---|---|---|---|---|
57
+ | `fixed` | `llm` | 0.488 | 0.647 | 0.089 | 1.08 |
58
+ | `random` | `llm` | 0.511 | 0.654 | 0.101 | 0.73 |
59
+ | `max_entropy` | `llm` | 0.513 | 0.656 | 0.112 | 1.24 |
60
+ | `entropy_choice` | `llm` | 0.490 | 0.654 | 0.110 | 1.21 |
61
+ | `eig` | `llm` | 0.513 | 0.656 | 0.112 | 1.24 |
62
+ | `eig_mc` | `llm` | **0.541** | **0.668** | 0.110 | **0.34** |
63
+ | `eig` | `rule` | 0.507 | 0.569 | 0.119 | 1.20 |
64
+
65
+ Mass on truth is the mean probability the belief puts on the true value of each slot (the
66
+ primary metric); MAP accuracy is the share of slots whose most probable value is the true one;
67
+ violations count the constraint slots the top recommendation breaks (0 to 2).
68
+
69
+ ![Probability on the true value per turn, K = 5](https://raw.githubusercontent.com/LhyJason/elicitor/main/docs/figures/m5_full/curve_mass_on_truth_K5.png)
70
+
71
+ What held and what did not:
72
+
73
+ - **H1, principled selection beats fixed and random order: not supported.** `eig` beats `fixed`
74
+ only at K = 5 with the LLM updater (+0.026 mass on truth, Holm p < 0.001). At K = 8 the two are
75
+ identical, because both end up asking the same 8 of the 9 slots, and `random` is slightly ahead
76
+ of `eig` with either updater (+0.010). With nine slots of 3 to 5 values each, question order
77
+ has little room to matter.
78
+ - **H2, `eig` equals `max_entropy` under the measured answer noise: holds exactly.** The noise
79
+ per question type was measured on the development personas before the run: the LLM updater
80
+ reads the right value from 99 % of open answers, 97 % of choice answers and 85 % of yes/no
81
+ answers. With open questions the most reliable, the question with the largest expected gain is
82
+ always the open question on the most uncertain slot, so `eig` asked `max_entropy`'s questions in
83
+ every episode and every metric is identical. (In an earlier run with a rule-based user and the
84
+ opposite noise, 0.7 / 0.8 / 0.9, `eig` beat `max_entropy` by 0.057 at K = 5: its edge comes
85
+ entirely from the noise model.) Listing the options (`entropy_choice`) is worse at K = 3
86
+ (−0.03 with either updater) and at K = 5 with the LLM updater (−0.024).
87
+ - **`eig_mc` is the one selector that helps**, against the frozen prediction that it would not:
88
+ +0.027 mass on truth over `eig` at K = 5 and 0.90 fewer constraint violations (both Holm
89
+ p < 0.001). Regret and hit@1 do not change. It needs several LLM calls per candidate question,
90
+ so it was run at K = 5 only; why its questions do better has not been analysed.
91
+ - **H3, the LLM updater beats the keyword updater: not supported on the primary metric.** Mass
92
+ on truth does not differ for any selector. MAP accuracy does, for every selector: +0.04 to +0.08
93
+ at K = 3, +0.06 to +0.10 at K = 5, +0.11 to +0.13 at K = 8 (all Holm p < 0.01). The LLM updater
94
+ picks the right value more often without putting more probability on it. Split by answer
95
+ style (descriptive, 12 personas per style), the null on mass on truth is an average of
96
+ opposite effects: the LLM updater puts more mass on the truth for direct (+0.01 to +0.04) and
97
+ rambling answers (+0.01 to +0.06), about the same for vague ones, and less for indifferent ones
98
+ (−0.03 to −0.09, every CI below zero). So the predicted pattern, a gap that grows from direct to
99
+ vague answers, does not appear on mass on truth. It does appear on MAP accuracy: at K = 8 the
100
+ gain is +0.15 to +0.20 for vague and rambling answers, +0.08 to +0.14 for direct ones and about
101
+ +0.01 for indifferent ones. Tables:
102
+ [styles.csv](https://github.com/LhyJason/elicitor/blob/main/results_summary/m5_full/styles.csv).
103
+ - **H4, a better final belief goes with lower regret: holds, weakly, for mass on truth.** Across
104
+ the 240 episodes of each arm and budget, the Spearman correlation between final mass on truth
105
+ and regret is negative in 33 of 34 cases (−0.05 to −0.35; the exception is +0.10). MAP accuracy
106
+ is not related to regret (−0.19 to +0.25), which fits the LLM updater raising MAP accuracy
107
+ without lowering regret. Tables:
108
+ [correlations.csv](https://github.com/LhyJason/elicitor/blob/main/results_summary/m5_full/correlations.csv).
109
+ - **Phrasing:** LLM rewording of the questions changes nothing measurable (largest difference
110
+ −0.006 mass on truth, not significant).
111
+
112
+ Limits: the users are simulated by an LLM that knows its whole profile, there is one domain, the
113
+ belief treats slots as independent, and regret is measured on a synthetic catalog.
114
+
115
+ ### An LLM judge checked against the true utility
116
+
117
+ Because the catalog's utility is known, it can test what is usually used when it is not: an LLM
118
+ judge. The judge study runs no new dialogues. For each of the 48 evaluation personas (replicate 0
119
+ of the full run) it takes the items the agent recommended, the best catalog item and one random
120
+ item, 256 distinct (persona, item) units. Each unit is scored 0 to 10 by two judges, llama3.3 70B
121
+ (the simulator's model, the main judge) and qwen3 32B (the agent's model), in three presentations:
122
+ the item's attribute list, and a short trip plan written by either model. Two pairs of arms are
123
+ also compared head to head, in both orders. That is about 2,000 LLM calls, 42 minutes on 4 A40
124
+ GPUs, with no failed calls and no parse failures. The hypotheses were frozen before any judge
125
+ call (SPEC Q13); the tests are as above. Complete tables:
126
+ [results_summary/m7_judge/results.md](https://github.com/LhyJason/elicitor/blob/main/results_summary/m7_judge/results.md).
127
+
128
+ - **J1, the judge tracks utility: holds.** Spearman correlation 0.87 [0.83, 0.91] for the main
129
+ judge on the list, and 0.74 to 0.82 for the other judge and presentation combinations.
130
+ - **J2, the judge keeps the utility order: holds for two of three steps.** An item recommended at
131
+ K = 8 scores 2.1 points above one recommended at K = 3, which scores 2.0 above a random item
132
+ (both Holm p < 0.001). The best catalog item scores only 0.22 above the K = 8 recommendation
133
+ (Holm p = 0.15).
134
+ - **J3, the judge prefers `eig_mc`'s items for their constraints: not supported.** `eig_mc` + llm
135
+ scores 0.44 above `eig` + llm at K = 5 (CI −0.10 to +0.98, Holm p = 0.22). Head to head, judges
136
+ that gave the same verdict in both orders picked `eig_mc`'s item 21 times to 8. The judges do
137
+ weigh the slots unevenly although the rubric says every preference counts the same: a
138
+ least-squares fit gives budget a weight of 2.0 to 2.8 and food 0.4 to 0.7, against 1.11 for each
139
+ slot in the utility.
140
+ - **J4, a written plan scores higher than the list: not supported** (+0.12, Holm p = 0.22). Plans
141
+ make the main judge slightly less accurate: Spearman 0.79 and 0.82 against 0.87 for the list.
142
+ - **J5, each judge favours its own model's plans: not supported** (+0.09, p = 0.23).
143
+ - **J6, verdicts depend on the order: half holds.** The verdict changed when the two items were
144
+ swapped in 28 % of pairs (the frozen bar was 10 %), but the share of decisive verdicts for the
145
+ item shown first, 0.42, does not differ from 1/2 after Holm (p = 0.055 before, 0.22 after), so
146
+ J6 as frozen fails. When the verdict did not change with the order, it picked the item of higher
147
+ utility in 93 % and 94 % of pairs.
148
+ - **Leniency:** the main judge is strict: a random item averages 2.4 and the best item 6.8 out of
149
+ 10. On the list, the agent's model gives items of utility below 0.6 and the random items 0.6 to
150
+ 0.8 points more.
151
+
152
+ ![Mean judge score against true utility](https://raw.githubusercontent.com/LhyJason/elicitor/main/docs/figures/m7_judge/score_vs_utility.png)
153
+
154
+ ## Quick start
155
+
156
+ From a clone of the repo:
157
+
158
+ ```bash
159
+ pip install -e .
160
+ elicitor demo # you answer the questions; no LLM needed
161
+ elicitor run experiments/m1_no_llm.toml # no LLM needed; writes results/m1_no_llm/
162
+ elicitor run experiments/m2_mock.toml # every LLM code path on the mock backend
163
+ elicitor run experiments/m3_eig.toml # EIG vs the baselines, rule-based user, no LLM
164
+ ```
165
+
166
+ Run the experiments from the repo root; the demo runs from any folder. It asks up to five
167
+ questions chosen by `eig`, shows the belief after each answer and ends with the three best
168
+ catalog items.
169
+ `elicitor demo --selector max_entropy --budget 8` changes the agent; with
170
+ [Ollama](https://ollama.com) running locally and `ollama pull qwen3:4b`,
171
+ `elicitor demo --updater llm` uses the LLM updater.
172
+
173
+ Then, for any run folder:
174
+
175
+ ```bash
176
+ elicitor health results/m2_mock # progress and per-role LLM failure rates (also mid-run)
177
+ elicitor analyze results/m3_eig # tables, paired tests and curves in results/m3_eig/analysis/
178
+ ```
179
+
180
+ A run into an existing folder resumes; `--fresh` starts over (the LLM reply cache is kept).
181
+ `analyze --publish` writes the committed tables in `results_summary/` and figures in
182
+ `docs/figures/`, and refuses runs that are incomplete, cut short or made with the mock backend.
183
+
184
+ ## Use it in your own code
185
+
186
+ A `Session` is one dialogue that your code drives: it hands you the next question, you bring
187
+ back the user's answer.
188
+
189
+ ```python
190
+ from elicitor import Session
191
+
192
+ session = Session.from_config() # travel domain, `eig` + rule updater, no LLM
193
+ while (question := session.next_question()) is not None:
194
+ session.observe(input(question + "\n> "))
195
+ for rec in session.recommend(3):
196
+ print(rec.item.id, round(rec.expected_utility, 2), rec.item.attrs)
197
+ ```
198
+
199
+ `session.belief` is the current distribution per slot, `session.turns` the dialogue so far and
200
+ `session.stop_reason` why it ended (budget, confident or exhausted). `Session.from_config(path)`
201
+ takes any experiment file; `selector=`, `updater=`, `phraser=` and `budget=` override it. For
202
+ your own domain, pass a schema and a catalog:
203
+
204
+ ```python
205
+ from elicitor import Session, load_catalog, load_schema
206
+
207
+ session = Session(
208
+ load_schema("my_domain/schema.toml"),
209
+ catalog=load_catalog("my_domain/catalog.jsonl"),
210
+ selector="max_entropy",
211
+ budget=8,
212
+ )
213
+ ```
214
+
215
+ The LLM updater needs a client built from an `[llm]` table and the domain's prompt files:
216
+
217
+ ```python
218
+ from elicitor import Session
219
+ from elicitor.experiments.config import load_config
220
+ from elicitor.llm import build_client
221
+
222
+ config = load_config("experiments/demo.toml")
223
+ client = build_client(config.llm, config.prompts_dir, "llm_cache.sqlite")
224
+ session = Session.from_config(config, updater="llm", client=client)
225
+ ```
226
+
227
+ The travel domain's schema, catalog and prompts ship with the package. The prompts are written
228
+ for travel; a new domain needs its own `schema.toml` and prompt files (see `data/travel/`).
229
+
230
+ ## Running the full experiment
231
+
232
+ `experiments/m5_full.toml` is the run above. `cluster/` holds the Slurm scripts: copy
233
+ `cluster/local.env.example` to `cluster/local.env`, fill in your account and partition, then run
234
+ `cluster/submit.sh cluster/full.sbatch`. The job starts Ollama servers on the GPUs (qwen3:32b for
235
+ the agent, llama3.3 70B for the simulated user), runs the grid with resume, checks run health and
236
+ publishes the analysis. `elicitor calibrate` measures the answer noise per question type and
237
+ `elicitor make-backstories` writes the persona backstories; both results are frozen in the repo.
238
+ `cluster/submit.sh cluster/judge.sbatch experiments/m7_judge.toml` runs the judge study on the
239
+ finished run and publishes its tables.
240
+
241
+ ## Development
242
+
243
+ ```bash
244
+ python -m venv .venv
245
+ source .venv/bin/activate # Windows: .venv\Scripts\activate
246
+ pip install -e ".[dev]"
247
+ ruff check . && ruff format --check . && pytest
248
+ ```
249
+
250
+ CI runs the tests and the no-LLM and mock suites on Linux and Windows.
251
+
252
+ ## License
253
+
254
+ MIT, see [LICENSE](https://github.com/LhyJason/elicitor/blob/main/LICENSE).