Conversation
Implement embedding-based tool schema filtering that reduces the number of tool definitions sent to the LLM per turn. Only the most relevant tools are selected based on cosine similarity between the user query and pre-computed tool description embeddings. Key design decisions: - Single `compute_filtered_tool_ids()` call per turn in rebuild_system_prompt() - Cached result consumed by native tool path (iteration 0 only, full set for 1+) - Config-driven always-on classification (no ToolDef struct changes) - Rank-based top-K selection (model-agnostic, no threshold tuning) - Pre-filters: tool name string matching + short MCP description auto-include - InclusionReason enum for observability (AlwaysOn/NameMentioned/SimilarityRank/ShortDescription) - Disabled by default (enabled=false), opt-in via [agent.tool_filter] - Prompt-path providers skip filtering (preserves stable cache block) - Graceful degradation when embedding is unsupported or fails Config section: [agent.tool_filter] enabled = false top_k = 6 always_on = ["memory_search", "memory_save", "load_skill", "bash", "read", "edit"] min_description_words = 5
) - Extract cosine_similarity to zeph-common::math (DRY: single canonical source used by zeph-tools and zeph-memory via re-export) - Add maybe_init_tool_schema_filter() async builder and wire into all 3 entry points (runner, daemon, acp) so the filter is actually initialized - Switch find_mentioned_tool_ids to word-boundary-aware matching to prevent false positives (e.g. "read" no longer matches inside "thread") - Add NoEmbedding fallback: tools without cached embeddings (e.g. MCP tools added after startup) are auto-included instead of silently dropped
This was referenced Mar 20, 2026
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.
Summary
Implement dynamic tool schema filtering based on arxiv 2411.15399 ("Less is More: Better Reasoning for Language Models with Fewer Tools"). Filters which tool schemas are exposed to the LLM on a per-turn basis, reducing context waste and improving tool selection accuracy.
Implementation
zeph-tools/src/schema_filter.rswithToolSchemaFilter,InclusionReasonenum, cosine similarity ranking[agent.tool_filter]section withenabled,top_k,always_on,min_description_wordsmaybe_init_tool_schema_filter()Token Savings
Quality
Related
Commits
Test Plan
All validators signed off. Ready to merge.