Feat/tool descriptions and confidence, MCP server#21
Open
bs258q wants to merge 4 commits into
Open
Conversation
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>
984f7a4 to
7f98329
Compare
Signed-off-by: bs258q <bs258q@gmail.com>
9753265 to
10619b9
Compare
… calling Signed-off-by: bs258q <bs258q@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)
needle playground — launches a local web UI for testing and fine-tuning.
browser/workbench/workbench.html) — starts Needle as a local MCP tool router for agent workflows.
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 semanticmatching. 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.