aw.dispatch¶
Cheap-first dispatch to a skill: calibrated retrieval first, an LLM adjudicator only on ambiguity.
The chain decided in opsward ADR 0011 (misc/docs/decisions/0011-cheap-first-dispatch-no-router-agent.md
in thorwhalen/opsward): a route in the instructions and the host’s own skill listing are
the first two layers and belong to the host; this module is layers three and four, as code:
chain = skills_dispatch_chain(adjudicate=Adjudicator(ask=my_llm))
chain("open an issue for the client about the broken export") # -> 'ge-write-issue' or None
chain.trace("…") # which layer answered, the ranked candidates, the reason
ir_search()adaptsir.discover(lexical by default: the only mode fast enough for a hot path) to thesearch(query) -> [(candidate, score)]shape, with copies of one skill (name@base) collapsed to the best one.aw.routing.ConfidentRetrievalStrategyanswers only on a clear ranking and abstains until a boundary (floor, gap or relative gap) is configured.Adjudicatoris the escalation: an LLM shown the raw request and the top-k candidates with their descriptions, answering with one of them or none. Never the whole catalog, never a summary of the request.DispatchChainwires them and keeps the ranked list between the two, which a plainaw.routing.PriorityRoutercannot do.
ir is an optional dependency (pip install aw[ir]); everything here is testable with
a fake search and a fake ask.
Functions
|
A |
|
The skill a corpus record stands for: |
|
The ADR 0011 chain over the |
Classes
|
The escalation layer: an LLM picks one of the top-k candidates for the raw request, or none. |
|
Retrieval, then confident selection, then adjudication; with a trace of which layer answered. |
- class aw.dispatch.Adjudicator(ask=<function _default_ask>, describe=None, k=5, none_token='NONE')[source]¶
Bases:
objectThe escalation layer: an LLM picks one of the top-k candidates for the raw request, or none.
ask(prompt) -> stris the model call (default:aix.chat, viaaw.llm);describe(name)returns a candidate’s description so the model sees cards, not bare names. The model sees the user’s words verbatim: a summary is a lossy channel (opsward ADR 0011 §3).>>> adj = Adjudicator(ask=lambda p: 'ge-write-issue', describe={'ge-write-issue': 'Write an issue.'}.get) >>> adj('open an issue for the client', [('ge-write-issue', 9.0), ('ge', 8.9)]) 'ge-write-issue' >>> Adjudicator(ask=lambda p: 'NONE')('x', [('a', 1.0)]) is None True >>> Adjudicator(ask=lambda p: 'something-else')('x', [('a', 1.0)]) is None # not a candidate: no guess True
- class aw.dispatch.DispatchChain(search, floor=0.0, gap=0.0, rel_gap=None, adjudicate=None, k_adjudicate=5)[source]¶
Bases:
objectRetrieval, then confident selection, then adjudication; with a trace of which layer answered.
>>> table = {'clear': [('a', 10.0), ('b', 5.0)], 'close': [('a', 10.0), ('b', 9.8)], 'none': []} >>> chain = DispatchChain(search=table.get, rel_gap=0.9, adjudicate=Adjudicator(ask=lambda p: 'b')) >>> chain('clear'), chain('close'), chain('none') ('a', 'b', None) >>> chain.trace('close')['layer'], chain.trace('clear')['layer'], chain.trace('none')['layer'] ('adjudicate', 'retrieval', 'none') >>> DispatchChain(search=table.get, rel_gap=0.9)('close') is None # no adjudicator: abstain True
- aw.dispatch.ir_search(corpus='skills', *, mode='lexical', k=10, discover=None)[source]¶
A
search(query) -> [(name, score)]over anircorpus, copies collapsed.discoverdefaults toir.discover(imported lazily, soawitself does not depend onir); pass any callable with the same result shape to test without it. Scores are the engine’s (BM25-like for lexical), so calibratefloorper corpus.
- aw.dispatch.skill_name(candidate)[source]¶
The skill a corpus record stands for:
'branch-hygiene@priv'->'branch-hygiene'.>>> skill_name('ge-write-issue@g_ai'), skill_name('deslop') ('ge-write-issue', 'deslop')
- Return type:
- aw.dispatch.skills_dispatch_chain(*, corpus='skills', mode='lexical', k=10, floor=0.0, rel_gap=0.75, adjudicate=None, discover=None)[source]¶
The ADR 0011 chain over the
irskills corpus, ready to call.Defaults: lexical mode; a relative gap of 0.75 (the runner-up must score at most 75% of the top), the point on the 14-prompt probe set of opsward ADR 0011 where the chain gives no confident wrong answer (9 confident, 5 escalated; at 0.9 it answers 12 right and 2 wrong); no floor until
ir calibrate-min-scorehas produced one for the corpus; no adjudicator (pass anAdjudicatorto escalate instead of abstaining).- Return type: