Skip to main content

Creating Tools

Tools allow your agents to execute Python code, access external systems, and perform actions that language models cannot do on their own. In BindAI, creating a tool is intentionally simple: write a Python function and register it with an agent.

The Simplest Tool

A tool is typically a normal Python function decorated with @tool.
Once registered, the language model can decide when to call it.

Registering a Tool

Register the tool on an agent.
The tool immediately becomes available during execution.

Calling a Tool

Suppose the user asks:
The model may generate an internal tool call similar to:
BindAI executes the function automatically and returns:
The model then uses that result to generate the final response.

Tool Parameters

BindAI automatically discovers function parameters. Example:
The model understands that the tool expects:
  • a
  • b
Both are integers.

Optional Parameters

Default values become optional parameters.
The model may call:
or

Type Hints

Always provide type hints. Good:
Avoid:
Type hints improve parameter validation and help language models understand the expected inputs.

Returning Values

Tools can return nearly any Python object. Simple text:
Numbers:
Lists:
Objects:
BindAI converts the output into a tool result that is passed back to the language model.

Accessing External APIs

Tools are ideal for API integrations. Example:
The agent can now answer questions using live information instead of relying only on model knowledge.

Reading Files

Tools can interact with the file system.
This enables document analysis and automation workflows.

Database Queries

Tools can access databases.
Agents can retrieve records, perform lookups, or execute business operations.

Using Multiple Tools

Register as many tools as needed.
During execution, the language model chooses the most appropriate tool.

Tool Descriptions

Provide meaningful names and documentation. Example:
Descriptions help the model decide when a tool should be used.

Tool Context

Advanced tools may receive an execution context. The context can expose:
  • workflow variables
  • runtime state
  • metadata
  • execution information
This allows tools to participate in larger workflows without requiring additional parameters.

Error Handling

Handle expected failures inside the tool. Example:
Returning useful information is generally better than allowing the tool to fail unexpectedly.

Tool Result Flow

The language model never executes the Python function directly. It only requests the tool; BindAI performs the execution.

Best Practices

  • Give tools descriptive names.
  • Keep each tool focused on a single responsibility.
  • Use type hints for every parameter.
  • Return predictable outputs.
  • Handle expected errors gracefully.
  • Avoid unnecessary side effects.
  • Write clear docstrings and descriptions.
  • Reuse tools across multiple agents whenever possible.

Example

Now the agent can answer questions such as:
by calling the tool automatically.