mixle.task.toolcall module¶
Distill single-step tool calling into a calibrated local model.
Tool calling decomposes into two problems the task spine already solves, composed under one gate:
which tool (or none) – a calibrated classification student (
solve()over the request text: conformal answer-or-escalate + optional OOD gate);the arguments – one token-level extractor per tool (
distill_extractor()), distilled from the teacher’s own argument fills.
teacher(request) -> {"tool": name, "args": {...}} (or {"tool": None})
can be a frontier LLM behind mixle.task.llm, an agent loop, or a rule.
The returned ToolCaller emits a call only when the selector is
conformally confident and every required argument extracts. Anything else
escalates to the teacher and is harvested for the next distillation round.
This covers single-step function calling. Multi-step planning is handled by the planner distillation surfaces.
- class ToolSpec(name, args, required=None)[source]
Bases:
objectOne callable tool: its name and the argument fields to extract from the request text.
- class ToolCaller(selector, extractors, tools, teacher, selection_agreement, n_requests=0, n_escalated=0, harvested=<factory>)[source]
Bases:
objectDistilled function caller with calibrated selection and argument extraction.
- Parameters:
- try_local(request)[source]
Return the local decision, or
Nonewhen the request must escalate.This method does not call the teacher.
- report()[source]
Return serving counts, escalation rate, and selector agreement diagnostics.
- save(path)[source]
Persist selector, per-tool extractors, and tool specs.
- distill_tool_caller(teacher, requests, tools, *, seed=0, selector_kw=None, extractor_kw=None)[source]
Distill the teacher’s function-calling into a local selector plus per-tool argument extractors.
- Parameters:
teacher (Callable[[str], dict]) –
teacher(request) -> {"tool": name-or-None, "args": {field: value}}— the frontier LLM / agent / rule currently doing the calling. It labels everything; it remains the fallback.requests (Sequence[str]) – example request texts covering the tools.
tools (Sequence[ToolSpec]) – the tool specs (names + argument fields;
requireddefaults to all).extractor_kw (dict | None) – knobs forwarded to
solve()anddistill_extractor().seed (int)
selector_kw (dict | None)
extractor_kw
- Return type:
ToolCaller