Skip to content
AgentsKit

@agentskit/tools β€” Functions

API functions for @agentskit/tools.

#Function: checkEgress()

checkEgress(parsed, policy?): Promise<string | null>

Defined in: safe-fetch.ts:115

Gate a parsed URL against an egress policy. Returns an error string when the request must be blocked (caller can surface it verbatim), or null to allow. Enforces http/https only and default-deny of non-public hosts.

#Parameters

#parsed

URL

Parsed request URL.

#policy?

EgressPolicy = \{\}

Explicit vetted-host exceptions and redirect limits.

#Returns

Promise<string | null>

The compatibility error string or null when allowed.


#Function: defineZodTool()

defineZodTool<TSchema>(config): ToolDefinition<InferZodOutput<TSchema>>

Defined in: zod.ts:70

Create a ToolDefinition whose execute args are typed from a Zod schema.

Zod is NOT bundled β€” pass it as a peer dependency. The toJsonSchema callback lets you convert the Zod schema to JSON Schema for the adapter (e.g. using zod-to-json-schema).

#Type Parameters

#TSchema

TSchema extends ZodLike<unknown>

#Parameters

#config

DefineZodToolConfig<TSchema>

Tool metadata, Zod schema, and optional schema-conversion and execution callbacks.

#Returns

ToolDefinition<InferZodOutput<TSchema>>

A ToolDefinition whose execution arguments are inferred from the schema.

#Example

import { z } from 'zod'
import { zodToJsonSchema } from 'zod-to-json-schema'
import { defineZodTool } from '@agentskit/tools'

const weatherTool = defineZodTool({
  name: 'weather',
  description: 'Get weather for a city',
  schema: z.object({ city: z.string(), units: z.enum(['C', 'F']).optional() }),
  toJsonSchema: (s) => zodToJsonSchema(s) as JSONSchema7,
  execute: (args) => {
    // args.city is string, args.units is 'C' | 'F' | undefined
    return `Weather in ${args.city}: 22${args.units ?? 'C'}`
  },
})

#Function: fetchUrl()

fetchUrl(config?): ToolDefinition

Defined in: fetch-url.ts:96

Tool: fetch a URL and return its text content.

  • Enforces HTTPS/HTTP only (no file://, ftp://, etc).
  • SSRF-gated: every hop's resolved host is checked against private / loopback / link-local ranges and (when configured) an allowlist.
  • Redirects are followed manually so the target host of each hop is re-validated; the platform's automatic redirect is disabled.
  • Caps response size via maxBytes so a huge page can't flood the model's context window or blow memory.
  • Strips HTML tags by default; set raw: true to get the body verbatim.

#Parameters

#config?

FetchUrlConfig = \{\}

Byte cap, timeout, user agent, and egress policy options.

#Returns

ToolDefinition

A fetch_url tool definition.

#Example

import { fetchUrl } from '@agentskit/tools'

const tool = fetchUrl({ maxBytes: 100_000 })

#Function: filesystem()

filesystem(config): ToolDefinition<Record<string, unknown>>[]

Defined in: filesystem.ts:130

Create jailed file read, write, and directory-listing tools.

#Parameters

#config

FilesystemConfig

Workspace root and symlink policy.

#Returns

ToolDefinition<Record<string, unknown>>[]

The read_file, confirmation-gated write_file, and list_directory tools.

#Example

import { filesystem } from '@agentskit/tools'

const tools = filesystem({ basePath: './workspace' })

#Function: isPrivateHost()

isPrivateHost(host): Promise<boolean>

Defined in: safe-fetch.ts:85

Decide whether a hostname or bracketed/unbracketed IPv6 literal is non-public. Delegates classification to @agentskit/net; Node DNS resolves every record and any non-public address, malformed authority, or lookup failure is blocked. Decimal dotted quads with leading zeroes keep the public helper's base-10 interpretation; safeFetch applies WHATWG URL normalization before this check. This preflight does not pin the address used by the later fetch.

#Parameters

#host

string

Hostname or IPv6 literal, without credentials, path, or port.

#Returns

Promise<boolean>

true for non-public or malformed input; false only for public hosts.


#Function: isPrivateIPv4()

isPrivateIPv4(ip): boolean

Defined in: safe-fetch.ts:45

True when a valid IPv4 address is not public unicast, as classified by @agentskit/net. Invalid inputs return false; reserved and other non-public ranges are now blocked alongside private, loopback, link-local and CGNAT. Decimal dotted quads with leading-zero octets keep the previous base-10 behavior (for example, 010.0.0.1 is classified as 10.0.0.1).

#Parameters

#ip

string

#Returns

boolean

false for malformed or non-IPv4 input.


#Function: isPrivateIPv6()

isPrivateIPv6(ip): boolean

Defined in: safe-fetch.ts:58

True when a valid IPv6 address is not public unicast, as classified by @agentskit/net. Invalid inputs return false; mapped IPv4 and other non-public ranges are blocked as well.

#Parameters

#ip

string

#Returns

boolean

false for malformed, bracketed, or non-IPv6 input.


#Function: listTools()

listTools(): ToolMetadata[]

Defined in: discovery.ts:31

List metadata for the package's built-in tools using their default configurations.

#Returns

ToolMetadata[]

Names, descriptions, tags, categories, and JSON Schemas for each built-in tool.


#Function: safeFetch()

safeFetch(input, init?, policy?): Promise<Response>

Defined in: safe-fetch.ts:149

Fetch an HTTP(S) URL with default-deny egress (ADR-0010), manually re-gating each redirect. WHATWG URL canonicalization precedes host classification. DNS is checked before each request but is not pinned to the later connection, so DNS rebinding is not prevented.

#Parameters

#input

string

URL to fetch.

#init?

RequestInit = \{\}

Fetch options.

#policy?

EgressPolicy = \{\}

Explicit vetted-host exceptions and redirect limit.

#Returns

Promise<Response>

The final Response.

#Throws

AK_TOOL_INVALID_INPUT for an invalid or blocked URL, redirect, or hop limit.

#Throws

AK_CONFIG_INVALID when maxRedirects is invalid.

#Example

import { safeFetch } from '@agentskit/tools'
const response = await safeFetch('https://example.com/data')

#Function: shell()

shell(config?): ToolDefinition

Defined in: shell.ts:67

Create a confirmation-gated tool that runs one executable without a shell.

#Parameters

#config?

ShellConfig = \{\}

Allowlist or trusted open mode, timeout, output limit, and process options.

#Returns

ToolDefinition

A shell tool definition.

#Throws

With code AK_CONFIG_INVALID when neither allowed nor allowAny is set.

#Example

import { shell } from '@agentskit/tools'

const tool = shell({ allowed: ['git', 'node'] })

#Function: slackTool()

slackTool(config): ToolDefinition

Defined in: slack.ts:30

Create a confirmation-gated tool that sends messages through a Slack webhook.

#Parameters

#config

SlackToolConfig

Slack incoming webhook URL and optional fetch, timeout, and abort signal.

#Returns

ToolDefinition

A slack_send tool definition.

#Throws

With code AK_CONFIG_INVALID when webhookUrl is empty.

#Throws

During execution when the message is empty or Slack returns a non-success response.

#Example

import { slackTool } from '@agentskit/tools'

const tool = slackTool({ webhookUrl: process.env.SLACK_WEBHOOK_URL! })

#Function: sqliteQueryTool()

sqliteQueryTool(config): ToolDefinition

Defined in: sqlite-query.ts:56

Create a read-only SQLite query tool backed by optional better-sqlite3.

#Parameters

#config

SqliteQueryConfig

Database file path, read-only flag, and maximum returned rows.

#Returns

ToolDefinition

A sqlite_query tool definition.

#Throws

With code AK_CONFIG_INVALID for an unsupported readOnly value or invalid maxRows.

#Throws

During execution when better-sqlite3 is unavailable or the query is not read-only.

#Example

import { sqliteQueryTool } from '@agentskit/tools'

const tool = sqliteQueryTool({ path: './data.db', maxRows: 50 })

#Function: webSearch()

webSearch(config?): ToolDefinition

Defined in: web-search.ts:272

Create a web-search tool; provider responses use the configured byte cap and are cancelled when the limit is exceeded.

#Parameters

#config?

WebSearchConfig = \{\}

Provider, credentials, result limit, timeout, and body limit.

#Returns

ToolDefinition

A web_search ToolDefinition.

#Throws

AK_CONFIG_INVALID for an unsupported provider or invalid limit.

#Example

import { webSearch } from '@agentskit/tools'
const search = webSearch({ provider: 'duckduckgo', maxResponseBytes: 1_000_000 })

Explore nearby