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.

| Feature | Description |
|---|---|
| Custom tools created | create_appointment, list_appointments, update_appointment |
| Agent Structure | Single agent architecture |
Prerequisites
- Node.js 22 or later (the version
@strands-agents/sdksupports) - AWS account with Amazon Bedrock access
- Basic TypeScript knowledge
Running the Example
cd typescript/01-learn/02-custom-toolsnpm installnpx tsx src/index.tsProject Structure
src/├── database/│ └── AppointmentDatabase.ts # SQLite data access layer├── tools/│ └── AppointmentTools.ts # Tool definitions factory└── index.ts # Main entry pointKey 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});