🔄 Big News! bazed.ai is now sagentic.ai. Same vision, new name!

Skip to content

@sagentic-ai/sagentic-af / FunctionTool

FunctionTool<Args, Returns> ​

Tool is a spicy function that can describe itself with OpenAI compatible JSON schema.

Param ​

Name of the tool

Param ​

Description of the tool

Param ​

Zod schema for parameters of the tool

Param ​

Zod schema for return value of the tool

Type parameters ​

• Args

• Returns

Implements ​

Constructors ​

new FunctionTool(name, description, args, returns, func) ​

ts
new FunctionTool<Args, Returns>(
   name,
   description,
   args,
   returns,
func): FunctionTool<Args, Returns>

Parameters ​

• name: string

• description: string

• args: ZodType<Args, ZodTypeDef, Args>

• returns: ZodType<Returns, ZodTypeDef, Returns>

• func

Returns ​

FunctionTool<Args, Returns>

Source ​

src/tool.ts:54

Properties ​

args ​

ts
args: ZodType<Args, ZodTypeDef, Args>;

Zod schema for parameters of the tool

Source ​

src/tool.ts:47


description ​

ts
description: string;

Description of the tool

Implementation of ​

Tool.description

Source ​

src/tool.ts:45


func ​

ts
func: (agent, args) => Promise<Returns>;

Function for the tool to perform when called

Parameters ​

• agent: Agent

• args: Args

Returns ​

Promise<Returns>

Source ​

src/tool.ts:52


name ​

ts
name: string;

Name of the tool

Implementation of ​

Tool.name

Source ​

src/tool.ts:43


returns ​

ts
returns: ZodType<Returns, ZodTypeDef, Returns>;

Zod schema for return value of the tool

Source ​

src/tool.ts:49

Methods ​

describe() ​

ts
describe(): ChatCompletionTool

Convert a tool to OpenAI compatible tool schema.

Returns ​

ChatCompletionTool

OpenAI compatible JSON schema as JS object

Implementation of ​

Tool.describe

Source ​

src/tool.ts:83


invoke() ​

ts
invoke(agent, args): Promise<Returns>

Invoke the tool.

Parameters ​

• agent: Agent

• args: Args

Arguments for the tool

Returns ​

Promise<Returns>

Return value of the tool

Implementation of ​

Tool.invoke

Throws ​

Error if the arguments are invalid or not supported

Source ​

src/tool.ts:68