Tools Overview

opentine tools are plain Python functions. No decorators, no Pydantic models, no special base classes. If a function has type hints and a docstring, it's a valid tool.

How Tools Work

The tool_schema(fn) utility converts any function with type hints and a docstring into an opentine tool schema. Model adapters convert that schema into their provider-specific shape. It maps Python types to JSON Schema types: str, int, float, and bool.

schema_example.py
1from opentine.tools import tool_schema
2from opentine.tools.search import search
3
4# Convert any typed function to an opentine tool schema
5schema = tool_schema(search)
6print(schema)
7# {
8#   "name": "search",
9#   "description": "Search the web...",
10#   "input_schema": {
11#     "type": "object",
12#     "properties": {
13#       "query": {"type": "string", "description": "query"},
14#       "max_results": {"type": "integer", "description": "max_results"}
15#     },
16#     "required": ["query"]
17#   }
18# }

Built-in Tool Modules

opentine ships with tool modules that cover common agent needs:

  • Web & Search — Search the web, fetch pages, and get raw HTTP responses. Auto-selects search provider via environment variables.
  • File System — Read, write, edit, and list files. Sandboxed to the current working directory by default.
  • Shell & Python — Run shell commands and Python snippets only when explicit policies enable them.

Passing Tools to an Agent

Pass any combination of built-in or custom tools to the Agent constructor. Policy-gated tools such as shell and Python execution are usually passed through small wrappers that provide the approved policy.

agent_setup.py
1from opentine import Agent
2from opentine.core import PythonPolicy, ShellPolicy
3from opentine.models.anthropic import Anthropic
4from opentine.tools.fs import read, write, ls
5from opentine.tools.search import search
6from opentine.tools.web import fetch
7from opentine.tools.shell import run as _run
8from opentine.tools.python import execute as _execute
9
10def shell(command: str) -> str:
11    """Run an approved shell command."""
12    return _run(command, policy=ShellPolicy(enabled=True, executables=("git", "pytest")))
13
14def python(code: str) -> str:
15    """Execute Python code in an isolated subprocess."""
16    return _execute(code, policy=PythonPolicy(enabled=True))
17
18agent = Agent(
19    model=Anthropic("claude-sonnet-4-20250514"),
20    tools=[search, fetch, read, write, ls, shell, python],
21)

Custom Tools

Any function with type hints and a Google-style docstring is a valid tool. The tool_schema() function extracts parameter descriptions from the Args section of the docstring.

custom_tool.py
1def get_weather(city: str, units: str = "celsius") -> str:
2    """Get the current weather for a city.
3
4    Args:
5        city: The city name to look up.
6        units: Temperature units — celsius or fahrenheit.
7    """
8    # Your implementation here
9    return f"Weather in {city}: 22 {units}"
10
11# Pass it directly to an Agent — tool_schema() is called automatically
12agent = Agent(
13    model=Anthropic("claude-sonnet-4-20250514"),
14    tools=[get_weather],
15)

Parameters with default values become optional in the schema. Parameters without defaults are marked as required.

Next Steps