Built-in Tools
easy5 minbuilt-in-tools.ts
You need an analyst that reads files and does exact math instead of guessing, without writing the tools yourself.
What it shows
- Use
calculator,datetime,fileRead,fileListandregexMatchfrom@cogitator-ai/core - Let the agent chain several tool calls in one run
The code
built-in-tools.ts
import { Agent, Cogitator, calculator, datetime, fileList, fileRead, regexMatch } from '@cogitator-ai/core';
import { mkdirSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
const apiKey = process.env.GOOGLE_API_KEY;
if (!apiKey) throw new Error('Set GOOGLE_API_KEY');
const dataDir = join(process.cwd(), 'sales-data');
mkdirSync(dataDir, { recursive: true });
writeFileSync(
join(dataDir, 'sales-q4.csv'),
[
'date,product,quantity,price',
'2025-10-01,Widget A,150,29.99',
'2025-11-01,Widget A,200,29.99',
'2025-11-20,Widget C,45,99.99',
'2025-12-18,Widget A,300,29.99',
].join('\n')
);
const cog = new Cogitator({ llm: { providers: { google: { apiKey } } } });
const analyst = new Agent({
name: 'analyst',
model: 'google/gemini-3.5-flash-lite',
instructions: `You are a data analyst with filesystem, calculator, datetime and regex tools.
Read files first, use the calculator for math and regex for pattern extraction.`,
tools: [calculator, datetime, fileRead, fileList, regexMatch],
temperature: 0.2,
maxIterations: 15,
});
const revenue = await cog.run(analyst, {
input: `Read ${join(dataDir, 'sales-q4.csv')} and calculate the total revenue for Widget A.`,
});
console.log(revenue.output);
const november = await cog.run(analyst, {
input: `Read ${join(dataDir, 'sales-q4.csv')} and use regex to count the November (2025-11-xx) rows.`,
});
console.log(november.output);
console.log('Tools used:', november.toolCalls.map((call) => call.name).join(', '));
await cog.close();Run it
install · bash
pnpm add @cogitator-ai/coreEnvironment
GOOGLE_API_KEYrun · bash
GOOGLE_API_KEY=your-key npx tsx built-in-tools.tsOr run the full example from a clone of the repository (keys in .env):
repository · bash
npx tsx examples/core/02-built-in-tools.ts