delphi

Delphi API Reference > Agent Function

This API reference details the AgentFunction class in the Delphi framework, which is used for defining custom functions callable by agents during conversations.

AgentFn Type

AgentFn is a generic type for agent functions.

export type AgentFn<Input, Output> = (value: Input) => Promise<Output>;
Type Description
Input Type of input the function will receive.
Output Type of output the function will return.

AgentFunctionOptions

AgentFunctionOptions is a type representing the required fields for AgentFunction.

Property Type Description
name string Name of the function.
description string Description of the function.
schema JSONSchemaType<Input> JSON schema for input validation.
fn AgentFn<Input, Output> The function to be executed.

Class: AgentFunction

This class represents a function that an agent can call.

Properties

Constructor

constructor(options: AgentFunctionOptions)

Initializes a new instance of AgentFunction.

Parameter Type Description
options AgentFunctionOptions Configuration options of function.

Methods

run

Executes the function with validated input.

Note: This method validates the input before executing the function. If the input is invalid, an AggregateError is thrown containing all validation errors.

async run(value: Input): Promise<Output>

Usage Example

const myFunction = new AgentFunction<InputType, OutputType>(
  "myFunctionName",
  "This function does something",
  myInputSchema,
  async (input) => {
    // Function logic here
  },
);

Use the AgentFunction class to define custom functions for your agent, ensuring they have proper input validation and clear, descriptive names and purposes. This class provides a robust way to extend the functionality of your agent in the Delphi framework.