Commit 2b94014
committed
perf(skill): parallel eval, parallel compile reads, query_wiki cap
Three findings from the performance review on b6607ec:
1. `run_eval` was awaiting ~30 LLM calls sequentially (20 trigger
graders + 10 coverage graders). Each prompt is independent — same
`desc`/`content` inputs, results accumulated in eval_set order — so
`asyncio.gather` is correctness-preserving. Wrap in a
`Semaphore(EVAL_CONCURRENCY=8)` to bound simultaneous requests under
provider rate limits. Expected wall-clock cut for `openkb skill eval`
is roughly 4-15x depending on provider latency, with the floor set
by the semaphore.
2. The compile agent had `parallel_tool_calls=False`, forcing every
read tool (`list_wiki_dir`, `read_wiki_file`, `get_page_content`)
into its own turn. The early phase of compile is naturally a
read-fan-out (survey directories, read N summaries, follow
`full_text` pointers to source page-ranges). Allowing parallel tool
calls lets the model batch independent reads, saving roughly 5-10
outer turns per compile (~20-40s at Opus-class latencies). Writes
serialise naturally because each `write_skill_file` depends on
accumulated reads.
3. `query_wiki` is a nested `Runner.run(max_turns=50)` inside the outer
compile (`max_turns=80`). The docstring's "narrow follow-ups only"
was the only enforcement; a pathological run could spawn many nested
calls. Added a per-compile counter via closure: after
`QUERY_WIKI_MAX_CALLS=3` invocations, the tool returns an error
string steering the agent back to direct file reads. Bounds tail
latency without breaking the common case (legitimate cross-document
sub-questions still get answered).
Prompt-caching for `grade_coverage` (the fourth finding in the review)
was deferred: the openai-agents SDK takes `instructions` as a plain
string with no hook for emitting Anthropic `cache_control` markers.
OpenAI's automatic prefix caching already applies because the system
prompt is byte-stable across the 10 coverage calls; closing the
Anthropic gap is SDK-level work, not application-level.
Tests pass (463; unrelated trafilatura env failure in test_url_ingest
not touched).1 parent b6607ec commit 2b94014
2 files changed
Lines changed: 76 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
106 | 113 | | |
107 | 114 | | |
108 | 115 | | |
| |||
112 | 119 | | |
113 | 120 | | |
114 | 121 | | |
| 122 | + | |
| 123 | + | |
115 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
116 | 134 | | |
117 | 135 | | |
118 | 136 | | |
| |||
141 | 159 | | |
142 | 160 | | |
143 | 161 | | |
144 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
145 | 170 | | |
146 | 171 | | |
147 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
48 | 54 | | |
49 | 55 | | |
50 | 56 | | |
| |||
366 | 372 | | |
367 | 373 | | |
368 | 374 | | |
369 | | - | |
370 | | - | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
371 | 408 | | |
372 | 409 | | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
386 | 421 | | |
387 | 422 | | |
388 | 423 | | |
| |||
0 commit comments