Tools
Tools are what make agents useful. Without tools, an agent can only chat. With tools, agents can read data, create records, call APIs, run workflows, and more.
What Are Tools?
Tools are functions that agents can call to interact with your Frappe system or external services. Think of them as the agent’s hands—they enable action, not just conversation.
The following table shows the kind of work agents do by calling tools:
| Use case | Tool used |
|---|---|
| Look up a customer | Get Document |
| Create a support ticket | Create Document |
| Check inventory levels | Get List |
| Send a notification | HTTP Request or a custom function |
The agent decides which tool to use based on the conversation and tool descriptions.
How Tools Work
The Tool Execution Flow
Every tool call follows a predictable loop between the user, the agent, and the target system. Understanding this flow helps when debugging why an agent did—or did not—use a tool.
Tool Selection
Agents choose tools by matching the user’s request against each tool’s metadata. The quality of this decision depends almost entirely on how clearly the tool is described.
| Factor | Why it matters |
|---|---|
| Tool name | Descriptive identifier that helps the agent narrow candidates quickly. |
| Tool description | Explains what the tool does; this is the most important signal for selection. |
| Tool parameters | Defines what inputs the tool needs so the agent knows if it can satisfy the request. |
| Context | Current conversation and user request determine which tool fits right now. |
Write clear, specific tool descriptions. The agent uses these to decide when to use each tool.
Tool Types
Huf provides three categories of tools:
1. Built-in Tools
Built-in tools are pre-configured for common Frappe operations. They cover the document lifecycle and a few utility actions, so most agents can be assembled without writing any custom code.
| Tool Type | Purpose | Example Use Case |
|---|---|---|
| Get Document | Fetch a single document by name/ID | ”Show me customer CUST-001” |
| Create Document | Create a new document | ”Create a new lead for ABC Corp” |
| Update Document | Modify an existing document | ”Update the customer’s email” |
| Delete Document | Remove a document | ”Delete draft order SO-2024-001” |
| Submit Document | Submit a submittable DocType | ”Submit the invoice” |
| Get List | Query multiple documents | ”List all open support tickets” |
| Run Agent | Chain to another agent | ”Ask the sales agent about this” |
| HTTP Request | Call external APIs | ”Send to Slack webhook” |
2. Custom Tools
Custom tools are your own Python functions exposed to agents. They let you extend the platform beyond built-in operations while keeping the agent experience consistent.
| Characteristic | How it works |
|---|---|
| Define in Frappe | Create the tool via the Agent Tool Function DocType. |
| Link to functions | Point the tool to your module.function path. |
| Define parameters | Specify inputs and types so the agent knows what to provide. |
| Automatic execution | Huf handles calling your function when the agent invokes the tool. |
Example:
def calculate_discount(customer_type, order_total):
"""Calculate discount based on customer type and order total."""
if customer_type == "Wholesale":
return order_total * 0.15
elif order_total > 10000:
return order_total * 0.10
else:
return order_total * 0.053. Discovered Tools
Discovered tools are functions auto-discovered from your Frappe apps. They reduce setup effort because they are registered automatically and can be reused across projects.
- Use the
@agent_tooldecorator in your app code to mark a function as a tool. - Tools are auto-synced when the app is installed.
- No manual setup is required after the decorator is in place.
- Tools can be shared across projects because they travel with the app.
See Publishing Tools for details.
Tool Configuration
Agent Tool Function DocType
Tools are defined in Desk → Huf → Agent Tool Function. This DocType captures everything the agent needs to know in order to call the tool correctly.
Key Fields:
| Field | Description |
|---|---|
| Tool Name | Unique identifier (e.g., get_customer) |
| Description | What the tool does (used by AI for selection) |
| Types | Tool category (Get Document, Create Document, Custom Function, etc.) |
| Reference DocType | For DocType tools, which DocType to operate on |
| Function Path | For custom tools, the Python function path |
| Parameters | Table of input parameters with names, types, descriptions |
Adding Tools to Agents
Once created, a tool must be explicitly assigned to an agent before the agent can use it. This assignment step is also the main security gate for tool access.
In Agent DocType:
- Scroll to the Agent Tool table.
- Click Add Row.
- Select the Tool Function from the dropdown.
- Save the agent.
Agents can only use tools explicitly assigned to them.
Tool Parameters
Tools can accept parameters that the agent fills in based on conversation. Well-defined parameters make the difference between a tool that works reliably and one that the agent calls incorrectly.
Parameter Definition
For each parameter, specify the fields below so the agent understands exactly what to provide.
| Field | Purpose |
|---|---|
| Parameter Name | The variable name the function receives (e.g., customer_id). |
| Type | Data type: String, Int, Float, Boolean, Object, or Array. |
| Description | What this parameter represents and how to identify the right value. |
| Required | Whether the agent must provide a value for the tool to run. |
Example: Get Document Tool
The snippet below shows how a simple Get Document tool is declared. The agent uses this declaration to decide when to call the tool and what argument to pass.
{
"name": "get_customer",
"description": "Retrieve detailed information about a customer",
"parameters": [
{
"name": "customer_id",
"type": "String",
"description": "The customer ID or name",
"required": true
}
]
}Agent Behavior:
- The user says: “Show me info for CUST-001”.
- The agent extracts
customer_id = "CUST-001". - The agent calls
get_customer("CUST-001").
Built-in Tool Details
Get Document
Get Document fetches a single document by name or ID. Use it when the user refers to a specific record and the agent needs its full details.
Parameters:
| Parameter | Description |
|---|---|
doctype | The DocType name. |
name | The document name/ID. |
Returns: Full document with all fields.
Example:
get_document(doctype="Customer", name="CUST-001"){ "name": "CUST-001", "customer_name": "ABC Corp", ... }Create Document
Create Document creates a new document from a set of field values. It is the right choice when the user asks to add a record rather than update an existing one.
Parameters:
| Parameter | Description |
|---|---|
doctype | The DocType name. |
fields | Object with field values. |
Returns: Created document.
Example:
Agent Call: create_document(
doctype="Lead",
fields={
"lead_name": "John Doe",
"company_name": "XYZ Inc",
"email_id": "john@xyz.com"
}
)Update Document
Update Document modifies an existing document. Use it when the user wants to change specific fields on a known record.
Parameters:
| Parameter | Description |
|---|---|
doctype | The DocType name. |
name | The document name/ID. |
fields | Object with field values to update. |
Returns: Updated document.
Get List
Get List queries multiple documents with filtering, sorting, and pagination. It is useful whenever the user asks for a set of records rather than a single one.
Parameters:
| Parameter | Description |
|---|---|
doctype | The DocType name. |
filters | Filter conditions (optional). |
fields | Which fields to return (optional). |
order_by | Sort order (optional). |
limit | Max number of results (optional). |
Returns: Array of documents.
Example:
get_list(
doctype="Support Ticket",
filters={"status": "Open", "priority": "High"},
order_by="creation desc",
limit=10
)[ {...}, {...}, ... ]Run Agent
Run Agent chains to another agent for specialized tasks. It lets you keep each agent focused while still handling cross-domain requests in a single conversation.
Parameters:
| Parameter | Description |
|---|---|
agent_name | Name of the agent to run. |
prompt | The message to send to that agent. |
Returns: The other agent’s response.
Use Case: Route work to specialized agents for different domains:
- Main agent → Sales agent (for sales questions)
- Main agent → Support agent (for technical issues)
Permissions and Security
Tool Execution Context
Tools execute with the permissions of the user who triggered the agent. This keeps the agent inside the same authorization boundaries as a normal Frappe user.
| Principle | What it means |
|---|---|
| User runs agent | The tool runs as that user. |
| Agent cannot bypass permissions | If the user can’t read Customers, the agent can’t either. |
| Frappe permissions apply | Standard role-based access control is enforced. |
Security Best Practices
Follow these practices to keep agent capabilities aligned with what each user and agent actually needs.
- Least Privilege: Only assign necessary tools to each agent.
- Validate Inputs: Custom functions should validate parameters before acting on them.
- Audit Logs: All tool calls are logged in Agent Run for review.
- Permission Checks: Tools respect Frappe’s permission system by default.
- No Elevation: Agents cannot escalate permissions beyond those of the triggering user.
An agent with a “Delete Document” tool can only delete documents the current user has permission to delete. Agents are not a security bypass.
Tool Performance
Optimizing Tool Calls
Every tool assigned to an agent adds decision overhead and tokens. Keeping the toolset tight improves both speed and accuracy.
- Minimize tool count: Only assign tools the agent is actually expected to use.
- Clear descriptions: Help agents choose correctly the first time, avoiding repeated calls.
- Efficient queries: Use filters in Get List to reduce data transfer.
- Batch when possible: Group similar operations in custom functions instead of making many small calls.
Tool Call Costs
Tool calls affect agent costs in a few concrete ways. Being aware of them makes it easier to control token usage.
- Tool definitions add tokens to the prompt.
- Tool results add tokens to the conversation.
- More tools means more tokens, which means higher cost.
Optimization Tips:
- Assign only relevant tools per agent.
- Use specific DocTypes instead of overly generic tools.
- Return only needed fields in Get List.
- Keep tool descriptions concise but clear.
Troubleshooting
When an agent misbehaves, the cause usually falls into one of four patterns. Use the checklist below to narrow it down quickly.
Agent doesn’t use a tool:
Tool call fails:
Wrong tool selected:
Slow performance:
Best Practices
Tool Design
Well-designed tools are easier for agents to understand and harder to misuse. Use the guidelines below when creating or naming tools.
- Write clear, specific descriptions.
- Use descriptive tool names.
- Define all parameters explicitly.
- Include examples in descriptions.
- Keep tools focused on one task.
- Use vague descriptions like "handles customer stuff".
- Create overly generic mega-tools.
- Forget to specify required parameters.
- Mix multiple unrelated actions in one tool.
Tool Assignment
Assign tools strategically so each agent has exactly the capabilities it needs and no more. Specialized agents are generally more reliable than general-purpose ones.
Strategic Assignment:
- Give agents only the tools they need.
- Create specialized agents with focused toolsets.
- Use agent chaining for cross-domain tasks.
- Test with minimal tools, then add as needed.
Example:
Not: One agent with all 20 tools
Documentation for Tools
Good documentation inside your custom functions directly improves agent behavior, because Huf uses docstrings and parameter descriptions as part of the tool metadata.
When creating custom tools:
- Write a function docstring; it becomes part of the tool description.
- Add parameter descriptions so the agent understands inputs.
- Include return value comments to clarify what the agent will receive.
- Provide examples in docstrings to improve agent behavior.
def send_slack_notification(channel, message):
"""
Send a notification message to a Slack channel.
Args:
channel (str): Slack channel name (e.g., "#support")
message (str): The message text to send
Returns:
dict: Success status and message ID
Example:
send_slack_notification("#alerts", "New high-priority ticket!")
"""
# Implementation
passWhat’s Next?
Now that you understand tools:
- Built-in Tools - Detailed guide to each built-in tool
- Creating Custom Tools - Build your own tools
- Publishing Tools - Share tools via apps
- Conversations - How agents maintain context
Need help with tools? Check the GitHub discussions or open an issue.