Creating Tools
Tools are Python callables that agents can use during execution. They allow BindAI applications to perform operations such as:- Calling APIs
- Querying databases
- Reading files
- Performing calculations
- Executing business logic
- Accessing external services
@tool.
Your First Tool
The simplest tool is a decorated Python function.@tool decorator marks the function as a BindAI tool.
The function remains normal Python code. BindAI adds the information needed for the function to participate in agent tool calling.
Registering a Tool
A tool can be registered with an agent using the builder API.agent.tool() when a tool needs to be attached to an existing agent.
Registering Multiple Tools
Use.tools() when an agent needs several capabilities.
Automatic Tool Calling
Once a tool is registered, the model can request it during agent execution when appropriate. For example:Parameters
Tool parameters come directly from the Python function signature.ais an integerbis an integer- both parameters are required
- the function returns an integer
Optional Parameters
Python default values can be used for optional parameters.Type Hints
Type hints are strongly recommended for tools. Good:- Strings
- Integers
- Floats
- Booleans
- Collections
- Structured application types
Docstrings
Give tools concise descriptions.- What the tool does
- When it should be used
- What its important parameters represent
- What kind of result it returns
Returning Values
Tools can return values produced by the underlying Python function.Strings
Numbers
Lists
Dictionaries
Returning Structured Data
Tools can return structured Python values when the application needs more than plain text. For example:Calling APIs
Tools are useful for integrating external services. For example:- Request timeouts
- Authentication
- Rate limits
- API failures
- Response validation
- Retries where appropriate
- Secure credential handling
Reading Files
A tool can expose controlled file operations.Working with Databases
Database operations can also be exposed through tools.- Querying records
- Inserting data
- Updating records
- Looking up customers
- Executing business operations
Multiple Tools
An agent can register multiple tools.Tool Execution
A typical tool-enabled execution looks like this:Tool Iterations
An agent execution can involve multiple rounds of tool calls. For example:Error Handling
Tools should handle expected failures explicitly. For example:Exceptions
Not every exception should be hidden. Unexpected programming errors should generally remain visible during development so they can be diagnosed and fixed. For expected operational failures, controlled handling may be appropriate. For example:Tool Lifecycle
A typical tool-enabled execution follows this lifecycle:Tool Organization
As projects grow, keep tools separated by responsibility. For example:- Discover
- Test
- Maintain
- Reuse
- Review for security
Tool Reuse
The same tool can be attached to multiple agents.Tool Safety
Tools can perform real operations, so they should be treated as application boundaries. For sensitive operations:- Validate inputs.
- Restrict accessible resources.
- Avoid unrestricted file-system access.
- Protect credentials.
- Validate external API parameters.
- Enforce authorization where appropriate.
- Keep destructive operations narrowly scoped.
- Avoid returning sensitive information to the model.
- Require confirmation for high-impact actions where appropriate.
Read vs Write Tools
It is useful to distinguish between tools that read information and tools that modify state. Read-oriented tools might include:- Explicit authorization
- Input validation
- Confirmation
- Idempotency
- Audit logging
- Narrow permissions
Execution Context
Some advanced BindAI integrations may need execution context in addition to normal function arguments. For standard tools, prefer explicit function parameters:Tools and External Integrations
Tools are a natural interface for external services. Examples include:- REST APIs
- Databases
- Search services
- SaaS platforms
- Internal business systems
- Application services
Tool Testing
Tools should be tested independently from the language model whenever possible. A deterministic tool can be tested like normal Python application code:- Tool registration
- Parameter handling
- Successful execution
- Error handling
- External service failures
- Security and authorization
- Tool output formatting
Tool Calling Across Providers
Tool calling is coordinated between BindAI and the selected model provider. The provider determines how tool calls are represented to the model, while BindAI manages application-level tool execution. This allows tool implementations to remain largely independent of a specific provider. Conceptually:Tools and Memory
Tools can work alongside BindAI memory. For example:Tools and Knowledge
Tools can also complement BindAI knowledge and retrieval capabilities. For example:Tools and Workflows
Tools can participate in workflow-driven applications. A workflow can coordinate agent execution while tools provide individual capabilities. Conceptually:Tools and Multi-Agent Systems
Tools can be assigned to different specialist agents. For example:Tool Security Boundaries
A tool should define a clear boundary between model-generated requests and trusted application operations. For example:- Payments
- Account changes
- Deletions
- Messaging
- Database writes
- File operations
- Administrative actions
Complete Example
multiply tool during execution and can use it when appropriate.
Best Practices
- Keep each tool focused on one responsibility.
- Use descriptive function and parameter names.
- Add Python type hints.
- Write concise and accurate docstrings.
- Return predictable values.
- Handle expected failures gracefully.
- Allow unexpected programming errors to remain visible during development.
- Validate inputs to external systems.
- Restrict sensitive operations.
- Protect credentials.
- Avoid unnecessary side effects.
- Keep long-running operations out of latency-sensitive paths when possible.
- Reuse tools across multiple agents.
- Prefer several focused tools over one large tool.
- Test tools independently from the language model.
- Apply authorization in application code.
- Use dedicated connections for reusable external integrations.
- Use workflows for complex orchestration.
- Keep the model outside the application’s security boundary.
