Skip to content

Custom Tools

View the complete sample on GitHub

Overview

In this example we will guide you through creating custom tools using the Strands Agents tool() function. We will build a personal assistant that connects with a local SQLite database to manage appointments.

Custom Tools Architecture

FeatureDescription
Custom tools createdcreate_appointment, list_appointments, update_appointment
Agent StructureSingle agent architecture

Prerequisites

  • Node.js 22 or later (the version @strands-agents/sdk supports)
  • AWS account with Amazon Bedrock access
  • Basic TypeScript knowledge

Running the Example

Terminal window
cd typescript/01-learn/02-custom-tools
npm install
npx tsx src/index.ts

Project Structure

src/
├── database/
│ └── AppointmentDatabase.ts # SQLite data access layer
├── tools/
│ └── AppointmentTools.ts # Tool definitions factory
└── index.ts # Main entry point

Key Concepts

Class-Based Tool Organization

Tools are organized using a factory class pattern that encapsulates tool creation and database dependencies:

export class AppointmentTools {
constructor(private database: AppointmentDatabase) { }
getCreateAppointmentTool() {
return tool({
name: "create_appointment",
description: "Create a new personal appointment...",
inputSchema: z.object({ date, location, title, description }),
callback: (input) => {
const id = this.database.createAppointment(...);
return `Appointment created with ID: ${id}`;
}
});
}
getAllTools() {
return [
this.getCreateAppointmentTool(),
this.getListAppointmentsTool(),
this.getUpdateAppointmentTool()
];
}
}

Database Integration

The AppointmentDatabase class uses better-sqlite3 to store appointment information:

export class AppointmentDatabase {
constructor(databasePath: string = "appointments.db") {
this.db = new Database(databasePath);
this.initializeTables();
}
createAppointment(date, location, title, description): string
listAppointments(): Appointment[]
updateAppointment(id, updates): number
}

Agent Configuration

const agent = new Agent({
model: new BedrockModel({
modelId: "us.anthropic.claude-haiku-4-5-20251001-v1:0",
}),
systemPrompt: "You are a helpful personal assistant...",
tools
});

Additional Resources