Cogitator
Tools

Built-in Tools

Reference for the 26 built-in tools that ship with @cogitator-ai/core, the environment variables they read, and the tool factories next to them.

Overview

Cogitator ships with 26 built-in tools covering math, data processing, the file system, network, databases, email and GitHub. Every tool has a Zod schema (the runtime validates the model's arguments against it) and returns structured results; most failures come back as { error } data the model can read instead of a thrown exception.

import { Agent, builtinTools, calculator, fileRead, httpRequest } from '@cogitator-ai/core';

const assistant = new Agent({
  name: 'assistant',
  model: 'openai/gpt-6.1-sol',
  instructions: 'You are a helpful assistant.',
  tools: [calculator, fileRead, httpRequest],
});

const everything = new Agent({
  name: 'power-user',
  model: 'openai/gpt-6.1-sol',
  instructions: 'You are a helpful assistant.',
  tools: builtinTools,
});

builtinTools is a Tool[], so pass it as tools directly or spread it next to your own tools. Prefer picking the tools an agent needs: builtinTools includes exec, file_delete and send_email.

ExportTool nameExportTool name
calculatorcalculatorfileReadfile_read
datetimedatetimefileWritefile_write
uuiduuidfileListfile_list
randomNumberrandom_numberfileExistsfile_exists
randomStringrandom_stringfileDeletefile_delete
hashhashhttpRequesthttp_request
base64Encodebase64_encodeexecexec
base64Decodebase64_decodewebSearchweb_search
sleepsleepwebScrapeweb_scrape
jsonParsejson_parsesqlQuerysql_query
jsonStringifyjson_stringifyvectorSearchvector_search
regexMatchregex_matchsendEmailsend_email
regexReplaceregex_replacegithubApigithub_api

Environment Variables

VariableRead by
TAVILY_API_KEY, BRAVE_API_KEY, SERPER_API_KEYweb_search (first one set wins when provider is omitted)
DATABASE_URLsql_query, vector_search when no connectionString is passed
OPENAI_API_KEY, OLLAMA_BASE_URL / OLLAMA_URL / OLLAMA_HOST, GOOGLE_API_KEYvector_search embeddings (auto-detected in that order)
RESEND_API_KEY, RESEND_FROM_EMAILsend_email via Resend
SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, SMTP_FROMsend_email via SMTP
GITHUB_TOKENgithub_api

Variables are read on each call. On runtimes without process.env (Cloudflare Workers without nodejs_compat, Deno without --allow-env) they count as unset.

Optional Packages

PackageNeeded by
pgsql_query on PostgreSQL, vector_search
better-sqlite3sql_query on SQLite
nodemailersend_email via SMTP

They are optional peer dependencies of @cogitator-ai/core; a tool that needs a missing one returns an error telling you what to install.


Math & Utilities

calculator

Evaluates mathematical expressions without eval. Supports +, -, *, /, ^ (power), parentheses, and functions: sqrt, sin, cos, tan, log, abs, round, floor, ceil. Constants: pi, e.

ParameterTypeDescription
expressionstringMath expression, e.g. "2 + 3 * 4"

uuid

Generates UUID v4 identifiers with crypto.randomUUID.

ParameterTypeDescription
countnumberNumber of UUIDs to generate (1 - 100, default 1)

random_number

Generates a random number within a range.

ParameterTypeDescription
minnumberMinimum value (default: 0)
maxnumberMaximum value (default: 1)
integerbooleanReturn integer (default: false)

random_string

Generates a cryptographically secure random string using crypto.randomBytes.

ParameterTypeDescription
lengthnumberString length (1 - 1000)
charsetenumalphanumeric | alpha | numeric | hex (default: alphanumeric)

hash

Computes cryptographic hashes.

ParameterTypeDescription
datastringString to hash
algorithmenummd5 | sha1 | sha256 | sha512 (default: sha256)
encodingenumhex | base64 (default: hex)

sleep

Pauses execution for a specified duration. Maximum 60 seconds.

ParameterTypeDescription
msnumberMilliseconds to sleep (0 - 60000)

datetime

Returns the current date and time in various formats and timezones.

ParameterTypeDescription
timezonestringIANA timezone, e.g. "America/New_York" (default: system zone)
formatenumiso | unix | readable | date | time (default: iso)

Data Processing

json_parse

Parses a JSON string into an object. Returns { result, valid: true } on success, { error, valid: false } on failure.

ParameterTypeDescription
jsonstringJSON string to parse

json_stringify

Converts a value to a JSON string with optional pretty-printing.

ParameterTypeDescription
dataunknownData to serialize
prettybooleanEnable indentation (default: false)
indentnumberSpaces for indent (0 - 8, default 2)

base64_encode / base64_decode

Encode strings to Base64 or decode Base64 back to plain text. Both support the URL-safe variant.

ParameterTypeDescription
datastringInput string
urlSafebooleanURL-safe Base64 variant (default: false)

regex_match

Finds matches of a regular expression in text, returning match strings, indices, and named groups.

ParameterTypeDescription
textstringText to search
patternstringRegular expression pattern
flagsstringRegex flags (default: "g")

regex_replace

Replaces regex matches in text. Supports $1, $2 capture group references.

ParameterTypeDescription
textstringInput text
patternstringRegex pattern
replacementstringReplacement string
flagsstringRegex flags (default: "g")

Both regex tools reject texts over 1,000,000 characters and stop matching after 5 seconds. They run on the host event loop; for untrusted patterns prefer the WASM regex tool, which runs in a worker that the timeout terminates.


File System

file_write and file_delete declare sideEffects: ['filesystem']. None of the file tools restricts paths — they act with the permissions of your process, so give them only to agents you trust or put the agent behind approvals.

file_read

Reads file contents. Use base64 encoding for binary files.

ParameterTypeDescription
pathstringPath to the file
encodingenumutf-8 | base64 (default: utf-8)

file_write

Writes content to a file. Creates parent directories by default.

ParameterTypeDescription
pathstringFile path
contentstringContent to write
encodingenumutf-8 | base64 (default: utf-8)
createDirsbooleanCreate parent dirs (default: true)

file_list

Lists directory contents with file names, paths, types, and sizes.

ParameterTypeDescription
pathstringDirectory path
recursivebooleanRecurse into subdirectories (default: false)
includeHiddenbooleanInclude dotfiles (default: false)

file_exists

Checks if a file or directory exists and returns its type and size.

ParameterTypeDescription
pathstringPath to check

file_delete

Deletes a file or directory. Use recursive: true for non-empty directories.

ParameterTypeDescription
pathstringPath to delete
recursivebooleanDelete contents recursively (default: false)

Network & Web

http_request

Makes HTTP requests with custom headers, body, and timeout. Response bodies longer than 100,000 characters are truncated (truncated: true).

ParameterTypeDescription
urlstringRequest URL
methodenumGET | POST | PUT | PATCH | DELETE | HEAD | OPTIONS (default: GET)
headersRecord<string, string>Request headers
bodystringRequest body (for POST/PUT/PATCH)
timeoutnumberTimeout in ms (1000 - 60000, default: 30000)

Searches the web via Tavily, Brave Search, or Serper. Without provider it uses the first of TAVILY_API_KEY, BRAVE_API_KEY, SERPER_API_KEY that is set.

ParameterTypeDescription
querystringSearch query
providerenumtavily | brave | serper
maxResultsnumberMax results (1 - 20, default: 5)
pagenumberPage of results (1 - 10, Brave and Serper only)
topicenumgeneral | news (default: general)
recencyenumday | week | month | year: only results from that period
dateRange{ from: string, to?: string }Only results published within these days (YYYY-MM-DD, to defaults to today)
includeDomainsstring[]Search only these domains, e.g. ["reuters.com"]
excludeDomainsstring[]Leave out results from these domains
countrystringFavour results from a country, ISO 3166-1 alpha-2 (us, de)
languagestringFavour results in a language, ISO 639-1 (en, pt-br)
searchDepthenumultra-fast | fast | basic | advanced (Tavily only)
includeAnswerbooleanInclude AI summary (Tavily only)
includeRawContentbooleanFull page content as markdown in each result (Tavily only)

The filters work on every provider, each through its own parameters: Tavily's topic, time_range, start_date, include_domains, country and language, the news endpoints, freshness, country and search_lang of Brave, and the news endpoint, tbs, gl and hl of Serper. Domain filters become site: operators for Brave and Serper. A filter a provider cannot apply comes back as an error instead of being dropped: Tavily has no result pages, and it favours a country only in general searches.

Results carry publishedAt (ISO 8601) when the provider reports a date, Serper's relative dates ("3 hours ago") resolved at the time of the search, source for Serper news, and content with includeRawContent.

createWebSearchTool({ provider, apiKeys }) builds the same tool with a default provider and keys passed in code instead of the environment:

import { createWebSearchTool } from '@cogitator-ai/core';

const search = createWebSearchTool({ provider: 'tavily', apiKeys: { tavily: config.tavilyKey } });

web_scrape

Fetches an HTML page and extracts its content as text, markdown or raw HTML, optionally limited to a CSS selector, with link and image collection.

ParameterTypeDescription
urlstringURL to scrape
selectorstringCSS selector to extract (e.g. "article")
formatenumtext | markdown | html (default: text)
maxLengthnumberMax content length (100 - 100000, default: 50000)
timeoutnumberRequest timeout in ms (1000 - 60000, default: 30000)
includeLinksbooleanExtract links (default: false)
includeImagesbooleanExtract image URLs (default: false)

Non-HTML responses return an error.


sql_query

Executes SQL queries against PostgreSQL (pg) or SQLite (better-sqlite3). Supports parameterized queries and is read-only by default.

ParameterTypeDescription
querystringSQL query
databaseenumpostgres | sqlite (auto-detected from the connection string)
connectionStringstringPostgres URL or SQLite file path (defaults to DATABASE_URL)
paramsunknown[]Parameterized query values
maxRowsnumberMax rows returned (1 - 1000, default: 100)
readOnlybooleanOnly allow read queries (default: true)

In read-only mode the query must be a single SELECT/WITH/SHOW/DESCRIBE/EXPLAIN statement. On PostgreSQL it additionally runs inside a BEGIN TRANSACTION READ ONLY block that is always rolled back, so side-effecting functions (for example nextval()) are rejected by the database itself; SQLite databases are opened with readonly: true. With readOnly: false, statements that return no rows (INSERT, UPDATE, DELETE) return rows: [] and the number of affected rows in rowCount.

Performs semantic similarity search with pgvector: embeds the query via OpenAI, Ollama, or Google, then finds similar rows in PostgreSQL.

ParameterTypeDescription
querystringSearch query (converted to embedding)
collectionstringTable name (default: "documents")
topKnumberNumber of results (1 - 100, default: 5)
thresholdnumberMinimum similarity 0 - 1 (default: 0.7)
filterRecordMetadata filter as key-value pairs
embeddingProviderenumopenai | ollama | google
embeddingModelstringEmbedding model override
connectionStringstringPostgreSQL URL (defaults to DATABASE_URL)

The provider is auto-detected from OPENAI_API_KEY, then OLLAMA_BASE_URL/OLLAMA_URL/OLLAMA_HOST (the first one set is also the Ollama URL; default http://localhost:11434), then GOOGLE_API_KEY. Default models: text-embedding-3-small (OpenAI), nomic-embed-text (Ollama), gemini-embedding-001 (Google). The embedding dimension must match your pgvector column.


Communication & Dev

send_email

Sends email via the Resend API or SMTP (nodemailer). Declares sideEffects: ['network', 'external'].

ParameterTypeDescription
tostring | string[]Recipient(s)
subjectstringEmail subject
bodystringEmail body (plain text or HTML)
htmlbooleanTreat body as HTML (default: false)
fromstringSender (default: RESEND_FROM_EMAIL / SMTP_FROM)
replyTostringReply-to address
ccstring | string[]CC recipients
bccstring | string[]BCC recipients
providerenumresend | smtp (auto-detected)

Auto-detection picks Resend when RESEND_API_KEY is set, otherwise SMTP when SMTP_HOST and SMTP_USER are set. Resend sends from onboarding@resend.dev when no sender is configured. SMTP needs SMTP_PASS too, uses port SMTP_PORT (default 587, TLS on 465) and falls back to SMTP_USER as sender.

github_api

GitHub REST API access with GITHUB_TOKEN. One tool, 12 actions: get_repo, list_issues, get_issue, create_issue, update_issue, list_prs, get_pr, create_pr, get_file, list_commits, search_code, search_issues.

ParameterTypeDescription
actionenumOne of the actions above
owner, repostringRepository
numbernumberIssue or PR number (get/update)
title, bodystringFor new issues and PRs
stateenumopen | closed | all (default: open)
labels, assigneesstring[]For issues
path, refstringFile path and ref for get_file
base, headstringBranches for create_pr
querystringFor the search actions
perPage, pagenumberPagination (1 - 100, default 30; default page 1)
import { Agent, githubApi } from '@cogitator-ai/core';

const agent = new Agent({
  name: 'github-bot',
  model: 'openai/gpt-6.1-sol',
  tools: [githubApi],
  instructions: 'You help manage GitHub repositories.',
});

exec

Executes shell commands and returns stdout, stderr and the exit code. Declares sideEffects: ['process', 'filesystem', 'network'] and requiresApproval: true, so every call waits for a decision (see Approvals).

ParameterTypeDescription
commandstringShell command to execute
cwdstringWorking directory
timeoutnumberTimeout in ms (100 - 300000, default: 30000)
envRecordAdditional environment variables

exec declares a Docker sandbox (cogitator/sandbox:base, 256 MB, 100 PIDs, no network). Inside a Cogitator the command runs in that container through @cogitator-ai/sandbox. When the sandbox package is not installed or Docker is unreachable, the runtime logs a warning and runs the command on the host, unless sandbox.allowNativeFallback: false on the Cogitator makes the call fail. See Sandbox.


Multimodal Tool Factories

Image and audio tools are created with factories rather than shipped in builtinTools. See Vision & Audio for parameters and results.

FactoryToolDefault model
createAnalyzeImageToolanalyzeImagegpt-6.1-sol on the llm backend you pass in
createGenerateImageToolgenerateImagegpt-image-2.5-flare; returns base64 imageBase64, size / quality default to auto
createTranscribeAudioTooltranscribeAudiogpt-transcribe; whisper-1 when word timestamps are requested without an explicit model
createGenerateSpeechToolgenerateSpeechgpt-4o-mini-tts

Other Tool Factories

These build tools around state you provide; they are not part of builtinTools.

FactoryToolsNotes
createMemoryTools({ graphAdapter, agentId, coreFacts?, embeddingFn? })remember, recall, forgetLong-term memory in a knowledge graph — see Smart Memory
createSchedulerTools({ store, defaultChannel?, defaultUserId? })schedule_task, list_tasks, cancel_taskDelayed, dated or cron tasks in a workflows TimerStore — see Scheduler
createCapabilitiesTool(doc)lookup_capabilitiesSearches a capabilities document line by line
createDeviceTools()clipboard_read, clipboard_write, system_info, screenshotClipboard via pbpaste/pbcopy (macOS) or xclip; screenshot is macOS only
createSelfTools({ toolsDir, onToolsChanged? })create_tool, test_tool, list_custom_tools, delete_toolLets the agent write .mjs tools into toolsDir; create_tool requires approval
loadCustomTools(toolsDir)the tools in toolsDirLoads the .mjs default exports createSelfTools wrote

Tools created with createSelfTools run with full Node.js access in your process.

Public hosts only

A model chooses the URLs web_scrape and http_request fetch, and the audio URL transcribe_audio reads, so a page it read or a prompt it was given can point it at http://169.254.169.254/ (a cloud's credentials), http://localhost:8080/admin or a database on the internal network. These tools reach only the public internet: a URL on a loopback, private, link-local, carrier-grade NAT, multicast or documentation address, localhost, *.local, *.internal or a metadata host is refused, every redirect target is checked again, and a hostname is checked by the address it resolves to when the request connects, so a name that resolves elsewhere a moment later (DNS rebinding) is refused too. A refused URL comes back to the model as an error naming it.

An agent meant to work on a trusted network opts in, or brings its own client:

import { createHttpRequestTool, createWebScrapeTool } from '@cogitator-ai/core';

const intranet = createWebScrapeTool({ allowPrivateNetwork: true });
const api = createHttpRequestTool({ fetch: proxiedFetch });

A fetch of your own is trusted with every URL, so it should apply your network policy. createTranscribeAudioTool takes the same two options.

The guard is yours to use too: fetchPublic is a fetch for public hosts, createPublicFetch({ allowPrivateNetwork, maxRedirects, resolver, isBlocked }) builds one to your rules, assertPublicUrl(url) checks a URL up front, assertPublicHost(url) checks the addresses its host resolves to as well and isPrivateAddress(ip) classifies an address. They run on node:http, in Node and Bun alike, and a refusal throws a PrivateNetworkError.

With robots, the tool checks a URL and the addresses its host resolves to before it reads the site's robots.txt. RobotsPolicy reads robots.txt with the global fetch unless given another: new RobotsPolicy({ userAgent, fetch: fetchPublic }) keeps those reads on public hosts too.

Requests carry DEFAULT_USER_AGENT and Accept: */* unless the caller sets its own headers.

Polite crawling with robots.txt

RobotsPolicy reads and caches a site's robots.txt and answers whether a URL may be fetched, by RFC 9309: the groups that name your product token (else *), longest match wins with * and $ patterns, a 4xx robots.txt allows everything, a 5xx or a network failure allows nothing until the cache (one hour by default) expires. It implements RobotsChecker, which WebLoader in @cogitator-ai/rag and BrowserSession in @cogitator-ai/browser take as robots:

import { RobotsPolicy } from '@cogitator-ai/core';

const robots = new RobotsPolicy({ userAgent: 'NewsBot/1.0 (+https://example.com/bot)' });
await robots.allows('https://example.com/news/today'); // true or false

The token defaults to the User-Agent's first word (NewsBot); pass token to match another. robotsRulesFor(text, token) and robotsAllowsPath(rules, path) expose the parser for robots.txt files you already have.

createWebScrapeTool({ userAgent, robots }) builds a web_scrape tool with your User-Agent and a robots.txt check on every hop, redirects included (a disallowed page comes back as an error). The plain webScrape keeps the default User-Agent and checks nothing.

On this page