Principle:Neuml Txtai Tool Assembly
| Knowledge Sources | |
|---|---|
| Domains | NLP, Agent, Tool_Use |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
Tool Assembly is the principle of dynamically constructing a unified toolset from heterogeneous specifications -- instances, callables, dictionaries, and string aliases -- through a factory pattern that normalises every input into a smolagents.Tool object.
Description
An agent's toolset is rarely homogeneous. In a production system, tools may come from multiple sources:
- Pre-built Tool instances -- already conforming to the smolagents.Tool interface.
- Python callables -- plain functions or objects with a __call__ method, possibly with or without type annotations.
- Configuration dictionaries -- declarative descriptions pairing a target function (or embeddings path) with metadata.
- String aliases -- shorthand names like "python", "websearch", or "webview" that resolve to built-in default tools.
- MCP URLs -- HTTP endpoints exposing Model Context Protocol tool collections.
- Skill files -- Markdown files (.md) describing agent skills.
The Tool Assembly principle encapsulates all of this heterogeneity behind a single factory method, ToolFactory.create, which iterates over the tools list in the agent configuration and produces a flat list of smolagents.Tool objects. Each element is dispatched through a type-based resolution chain:
- If the element is already a Tool instance, it passes through unchanged.
- If it is a callable (function, method, or object with __call__), the factory attempts smolagents.tool() for automatic creation from annotations, falling back to docstring parsing and FunctionTool wrapping.
- If it is a dictionary whose target is an Embeddings instance (or contains path/container keys), an EmbeddingsTool is created.
- If it is a dictionary with a generic callable target, the factory creates a FunctionTool.
- If it is a string matching a default name, the corresponding built-in tool is returned.
- If it is an HTTP URL, MCP tool collections are fetched and expanded.
- If it is a .md file path, a SkillTool is created.
This layered dispatch ensures that users can mix and match tool specifications freely in configuration files or Python code, and the factory produces a consistent, flat list for the agent runtime.
Usage
Use the Tool Assembly pattern when:
- Configuring an agent that needs a mix of built-in, custom, and external tools.
- Building agents from YAML or JSON configuration files where tools must be specified declaratively.
- Integrating MCP-compliant external tool servers alongside local functions.
- You want a single entry point that handles all tool-creation logic, avoiding scattered instantiation code.
Theoretical Basis
1. The Factory Pattern
The Factory pattern centralises object creation behind a single interface, hiding the complexity of deciding which concrete class to instantiate. ToolFactory.create is a classic static factory method: given a heterogeneous input list, it returns a uniform output list.
2. Convention over Configuration
For callables with proper type annotations and Google-style docstrings, the factory can automatically extract metadata without any configuration dictionary. This "convention over configuration" approach reduces boilerplate when wrapping well-documented functions.
3. Open/Closed Principle
The dispatch chain is open to extension (new string aliases, new URL schemes, new file types) and closed to modification of the core iteration logic. Adding a new tool source requires adding a new branch to the type-checking chain, not restructuring the factory.
The resolution algorithm can be summarised as:
for each element in config["tools"]:
if element is Tool: -> use as-is
if element is callable: -> try smolagents.tool(), fallback to FunctionTool
if element is dict:
if target is Embeddings or has path/container: -> EmbeddingsTool(element)
else: -> createtool(target, element)
if element is str:
if element in DEFAULTS: -> DEFAULTS[element]
if element starts "http": -> MCP adapter
if element ends ".md": -> SkillTool(element)
append result to tools list
return tools