Tools
Declare a Python function or an existing LangChain BaseTool in the plugin manifest. Parameters come from the function signature and docstring or from the tool schema.
Minimal implementation
tools/statistics.py:
from langchain_core.tools import ToolException
def summarize_numbers(numbers: list[float]) -> dict[str, float | int]:
"""Return count, sum, mean, minimum and maximum for a list of numbers."""
if not numbers:
raise ToolException("Provide a nonempty list of numbers")
total = sum(numbers)
return {
"count": len(numbers),
"sum": total,
"mean": total / len(numbers),
"min": min(numbers),
"max": max(numbers),
}.plugin.yaml:
schema_version: 3
id: common
tools:
summarize_numbers:
entrypoint: tools/statistics.py:summarize_numbersThe model calls common__summarize_numbers. The host wraps ordinary functions. For a BaseTool, it reuses the schema and registers the tool under the fully qualified name. See plugin manifest and the complete validation example.
Save the implementation to tools/statistics.py under the plugin root and enable common. In two separate runs, ask the Agent to call common__summarize_numbers, then inspect the actual tool call and its result.
| Tool input | Expected result |
|---|---|
{"numbers": [1, 2, 3]} |
count is 3, sum is 6, mean is 2, min is 1, and max is 3. |
{"numbers": []} |
If the empty list reaches the tool, it returns a correctable tool error asking for a nonempty list. |
Access models and the semantic client
Use ToolRuntime for other configured models. Read model configuration through the runtime rather than loading .env in the tool.
from langchain.tools import ToolRuntime
from dataagent import AgentContext
async def summarize(text: str, runtime: ToolRuntime[AgentContext]) -> str:
"""Summarize text with the configured fast model."""
model = runtime.context.get_model("fast")
return (await model.ainvoke(text, config=runtime.config)).textget_model("fast") selects models.fast. An invalid alias fails. Clients are reused within the current agent.
When configured, runtime.context.semantic_client is the host- or SDK-owned SemanticServiceClient. Otherwise it is None. See semantic service and the llm-utils example.
Pass runtime.config to carry the call context. Direct model calls inside ordinary tools run separately from the Agent loop and are not exported as independent model spans. See trace data boundaries.
Execution limits
The root Agent and each standard subagent enforce separate per-invocation model and tool call counts using dataagent.limits.model_calls_per_agent and dataagent.limits.tool_calls_per_agent. Counts reset on the next invocation. See configuration fields for defaults.
A ToolException becomes a correctable Invalid tool input... tool message. Other exceptions follow native tool error handling. File and shell tools access paths allowed by the host process. The session directory organizes files. See security boundaries for access rules.