tooldiscovery Design Notes¶
Overview¶
tooldiscovery provides the discovery layer for the ApertureStack tool framework. It handles tool registration, search, and progressive documentation.
index Package¶
Design Decisions¶
-
Single Source of Truth: The index is the authoritative registry for all registered tools. Tool IDs are derived from
toolfoundation/model.Tool.ToolID(). -
Search Strategy Interface: Search is pluggable via the
SearchStrategyinterface. Default is lexical substring matching. -
Token-Efficient Summaries:
Search()returnsSummaryobjects that exclude schemas, keeping discovery cheap in terms of LLM context tokens. -
Namespace Isolation: Tools are grouped by namespace, enabling filtered views and multi-tenant scenarios.
Error Handling¶
- Duplicate tool registration returns an error
- Invalid tool IDs return descriptive errors
- Search errors are logged but don't fail the request
search Package¶
Design Decisions¶
-
BM25 Algorithm: Uses Okapi BM25 for relevance ranking, implemented via the Bleve search library.
-
Field Boosting: Configurable boosts for name (4x), namespace (2x), and tags (1x) fields.
-
Optional Dependency: BM25 support depends on Bleve and is only used when the
searchpackage is imported. Consumers can omit BM25 entirely by sticking with the default lexical strategy.
Search Strategy Policy¶
- Lexical (default): Lightweight substring matching; best for small indexes.
- BM25 (search package): Preferred for larger registries; tunable boosts.
- Semantic (semantic package): Best for fuzzy intent matching; requires embeddings.
Configuration¶
| Config | Default | Description |
|---|---|---|
| NameBoost | 4.0 | Boost for tool name matches |
| NamespaceBoost | 2.0 | Boost for namespace matches |
| TagBoost | 1.0 | Boost for tag matches |
| MaxDocs | 0 | Max docs to index (0=unlimited) |
semantic Package¶
Design Decisions¶
-
Embedder Interface: Abstracts the embedding model, allowing different providers (OpenAI, local models, etc.).
-
Vector Store Interface: Abstracts the vector storage, supporting in-memory, file-based, or external stores.
-
Optional Dependency: Semantic search is opt-in and requires additional setup (embeddings, vector store).
Contract Expectations¶
- Embedder: Must be deterministic for the same input and return fixed-size vectors. Errors should be propagated rather than swallowed.
- VectorStore: Must return results ordered by similarity and include IDs that map back to registered tools.
- Hybrid: The hybrid searcher uses Reciprocal Rank Fusion (RRF) to combine BM25 and semantic results.
tooldoc Package¶
Design Decisions¶
- Detail Levels: Three progressive levels:
Summary: Name, namespace, short descriptionSchema: Input/output JSON schemas-
Full: Everything including examples -
On-Demand Loading: Schemas are only loaded when requested at
DetailSchemaorDetailFulllevel. -
Index Integration: DocStore can use an Index to derive documentation from registered tools.
Detail-Level Field Matrix¶
| Level | Fields |
|---|---|
| Summary | ID, Name, Namespace, ShortDescription, Summary, Category, InputModes, OutputModes, SecuritySummary |
| Schema | Summary + InputSchema, OutputSchema |
| Full | Schema + Examples, Metadata |
Dependencies¶
github.com/jonwraymond/toolfoundation/model- Tool definitionsgithub.com/blevesearch/bleve/v2- BM25 search (optional)