Skip to content

Feat/tool descriptions and confidence, MCP server#21

Open
bs258q wants to merge 4 commits into
cactus-compute:mainfrom
bs258q:feat/tool-descriptions-and-confidence
Open

Feat/tool descriptions and confidence, MCP server#21
bs258q wants to merge 4 commits into
cactus-compute:mainfrom
bs258q:feat/tool-descriptions-and-confidence

Conversation

@bs258q
Copy link
Copy Markdown

@bs258q bs258q commented May 13, 2026

feat: tool descriptions, confidence tracking, and no-match fallback

What

Three independent improvements to constrained decoding and inference:

1. Confidence threshold + no-match fallback

Always return best guess (default — no behavior change)

result = generate(model, params, tokenizer, query, tools)

Return no-match sentinel when model is uncertain

result = generate(..., threshold=0.5)

→ '{"match":false,"confidence":0.31}' when confidence < threshold

Get confidence score alongside result

result, conf = generate(..., return_confidence=True)

  1. needle playground — launches a local web UI for testing and fine-tuning.

  2. browser/workbench/workbench.html) — starts Needle as a local MCP tool router for agent workflows.

  3. browser/workbench/workbench.html) — runs a single inference request with tool support.
    Add tokenizer training pipeline and extract src/tokenizer.py #6. Tool description support

Include a "description" field in each tool object for better semantic
matching. The encoder already tokenizes the full tools JSON string, so
descriptions flow through automatically — no structural change required.

{"name": "get_weather", "description": "Get current weather for a location", "parameters": {"location": "string"}}

Confidence = softmax max probability over valid name tokens at the first
constrained step. Useful for production: escalate uncertain calls to a
cloud LLM instead of silently returning a wrong tool.


bs258q added 2 commits May 13, 2026 12:50
- Fix constrained decoding for flat parameter format {"key": "string"} —
  previously only JSON Schema {"properties": {"key": {...}}} worked; now
  both formats populate the param trie correctly
- Add confidence tracking to ConstrainedDecoder: captures softmax max
  probability over valid name tokens at the first IN_NAME step
- Add threshold/no-match fallback to generate(): returns
  {"match":false,"confidence":0.31} when confidence < threshold
- Add return_confidence param to generate() for tuple return
- Tool descriptions already work via encoder (no structural change needed)
- Add comprehensive unit tests covering Trie, ToolConstraints,
  JsonStateMachine, apply_constraints, and ConstrainedDecoder confidence

Signed-off-by: bs258q <bs258q@gmail.com>
Signed-off-by: bs258q <bs258q@gmail.com>
@bs258q bs258q force-pushed the feat/tool-descriptions-and-confidence branch from 984f7a4 to 7f98329 Compare May 13, 2026 19:50
Signed-off-by: bs258q <bs258q@gmail.com>
@bs258q bs258q force-pushed the feat/tool-descriptions-and-confidence branch from 9753265 to 10619b9 Compare May 13, 2026 19:59
… calling

Signed-off-by: bs258q <bs258q@gmail.com>
@bs258q bs258q changed the title Feat/tool descriptions and confidence Feat/tool descriptions and confidence, MCP server May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant