Skip to main content

Overview

Tools are functions that AI agents can call to interact with external systems. The ADK-TS createTool function enables you to create type-safe tools with schema validation.

Tool Structure

Every tool has three main components:
  1. name: Unique identifier for the tool
  2. description: Explanation of what the tool does (used by the LLM)
  3. fn: The actual function implementation
  4. schema (optional): Zod schema for input validation

Basic Tool Creation

Tool with Parameters

Blockchain Read Tools

Tools that read data from smart contracts without modifying state.

Reading Vault State

src/agents/sub-agents/strategy-sentinel-agent/tools.ts

Reading Strategy States

Reading User Balances

Blockchain Write Tools

Tools that execute transactions on the blockchain.

Vault Deposit

Vault Withdraw

Rebalance Vault

Harvest Strategy

API Integration Tools

Fetching Token Prices

Risk Management Tools

Check Liquidation Risk

Auto Deleverage

Stateful Tools with ToolContext

Tools can maintain state across invocations using ToolContext.

Complex Parameter Tools

Update Strategy Weights

Update Leverage Parameters

Utility Helpers

Chain Read Helper

src/agents/shared/utils/chain.ts

BigInt Helpers

src/agents/shared/utils/bigint.ts

Best Practices

1. Clear Descriptions

Provide detailed descriptions to help the LLM understand when to use each tool:

2. Type Safety

Use Zod schemas for type-safe parameter validation:

3. Error Handling

Handle errors gracefully and provide informative messages:

4. Return Structured Data

Return both raw and human-readable data:

5. Gas Estimation

Always estimate gas before sending transactions:

Next Steps

Building Agents

Learn how to integrate tools into custom agents

Automation

Set up automated tool execution with cron jobs

ADK-TS Integration

Understand the ADK-TS integration patterns

Smart Contracts

Learn about the smart contracts your tools interact with