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:193

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 private hosts.

#Parameters

#parsed

URL

#policy?

EgressPolicy = \{\}

#Returns

Promise<string | null>


#Function: defineZodTool()

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

Defined in: zod.ts:67

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>

#Returns

ToolDefinition<InferZodOutput<TSchema>>

#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:86

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 = \{\}

#Returns

ToolDefinition


#Function: filesystem()

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

Defined in: filesystem.ts:118

#Parameters

#config

FilesystemConfig

#Returns

ToolDefinition<Record<string, unknown>>[]


#Function: isPrivateHost()

isPrivateHost(host): Promise<boolean>

Defined in: safe-fetch.ts:166

Decide whether host resolves to a private/loopback/link-local address. Host literals are checked exactly; hostnames are resolved via node:dns/promises when available. Fails closed on any DNS failure (e.g. edge runtime) so a misconfigured resolver can't open the SSRF gap.

#Parameters

#host

string

#Returns

Promise<boolean>


#Function: isPrivateIPv4()

isPrivateIPv4(ip): boolean

Defined in: safe-fetch.ts:40

True if ip is an IPv4 address in a private/loopback/link-local/CGNAT range.

#Parameters

#ip

string

#Returns

boolean


#Function: isPrivateIPv6()

isPrivateIPv6(ip): boolean

Defined in: safe-fetch.ts:112

True if ip is an IPv6 loopback / unique-local / link-local / mapped-private address.

#Parameters

#ip

string

#Returns

boolean


#Function: listTools()

listTools(): ToolMetadata[]

Defined in: discovery.ts:26

#Returns

ToolMetadata[]


#Function: safeFetch()

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

Defined in: safe-fetch.ts:217

fetch with default-deny egress (ADR-0010). Validates the URL and every redirect hop against checkEgress; redirects are followed manually so each target host is re-gated. Throws a ToolError (AK_TOOL_INVALID_INPUT) when the policy blocks the request. Use for any tool that fetches a URL the model can influence.

#Parameters

#input

string

#init?

RequestInit = \{\}

#policy?

EgressPolicy = \{\}

#Returns

Promise<Response>


#Function: shell()

shell(config?): ToolDefinition

Defined in: shell.ts:54

#Parameters

#config?

ShellConfig = \{\}

#Returns

ToolDefinition


#Function: slackTool()

slackTool(config): ToolDefinition

Defined in: slack.ts:13

#Parameters

#config

SlackToolConfig

#Returns

ToolDefinition


#Function: sqliteQueryTool()

sqliteQueryTool(config): ToolDefinition

Defined in: sqlite-query.ts:42

#Parameters

#config

SqliteQueryConfig

#Returns

ToolDefinition


#Function: webSearch()

webSearch(config?): ToolDefinition

Defined in: web-search.ts:272

#Parameters

#config?

WebSearchConfig = \{\}

#Returns

ToolDefinition

Explore nearby