pi-mono/packages/coding-agent/src
Petr Houška cc44fa2169
fix(coding-agent): weigh tool names above descriptions in tool search (#11625)
Follow-up to #11440 for the latest comment on #11331.

Problem: the ranker scored a tool as one bag of words. A query term in
the tool's name counted like a mention in its description, and the
server's instructions were copied into every tool's text, which
lengthened it and lowered its score. Models often add words to a tool
name, so `peekaboo app` ranked `mcp__peekaboo__app` 14th: other peekaboo
tools mention "app" in shorter descriptions, and its own description
says "applications".

Fix: `Bm25Ranker` scores three fields separately:
- name: a query term in the name counts 3x its IDF; the description part
of BM25 is at most 2.2x, so a name match beats any number of description
mentions;
- description and schema text: BM25 as before, length-normalized on this
field only;
- namespace name, description, and instructions: 0.5x IDF per matching
term, without length normalization.

A tool whose whole local name (last `__` segment) is in the query gets a
bonus worth one more match of every query term, so it mostly wins
(`peekaboo app`, `describe app`, `read thread_read state`). A query that
is exactly a tool's name still ranks it first (#11440). Applies to
`tool_search` and codemode `searchTools()`.

Not included: the comment's second point (loading a deferred tool on a
direct call instead of `Tool X not found`). That error comes from
`prepareToolCall` in `packages/agent`, which has no hook for unknown
tools; it needs an agent-loop API change.
2026-10-30 21:56:03 +01:00
..
bun feat(coding-agent): codemode and MCP 2026-09-29 09:12:50 +02:00
cli docs(coding-agent): document which working directory resumed sessions use (#11617) 2026-10-30 17:22:05 +00:00
core docs(coding-agent): document which working directory resumed sessions use (#11617) 2026-10-30 17:22:05 +00:00
experimental feat(coding-agent): remove the experimental server stack and the client, protocol, and server packages 2026-10-12 10:41:59 +00:00
extensions fix(coding-agent): weigh tool names above descriptions in tool search (#11625) 2026-10-30 21:56:03 +01:00
modes fix(coding-agent): start WSL interop helpers from / and report external editor failures (#11627) 2026-10-30 21:47:58 +01:00
utils fix(coding-agent): start WSL interop helpers from / and report external editor failures (#11627) 2026-10-30 21:47:58 +01:00
cli.ts fix(coding-agent): keep remote harness dependencies development-only 2026-09-05 12:45:04 +02:00
config.ts fix(coding-agent): name the package manager in pi update only when it owns the install (#11628) 2026-10-30 21:23:10 +01:00
index.ts fix(coding-agent): start when a configured package fails to install (#11304) 2026-10-23 12:27:45 +02:00
main.ts fix(coding-agent): honor saved project trust for projects without trust-requiring resources 2026-10-29 21:10:03 +01:00
migrations.ts fix(coding-agent): update repository links to "earendil-works/pi" (#9278) 2026-09-07 14:09:39 +02:00
package-manager-cli.ts fix(coding-agent): warn when an npm package update leaves the installed version unchanged (#11571) 2026-10-29 15:39:48 +01:00
rpc-entry.ts feat(coding-agent): set AI_AGENT environment variable (#7493) 2026-08-03 13:45:32 +02:00