This API reference details the AgentFunction
class in the Delphi framework,
which is used for defining custom functions callable by agents during
conversations.
AgentFn
TypeAgentFn
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. |
AgentFunction
This class represents a function that an agent can call.
options: AgentFunctionOptions
: Configuration options of the function.constructor(options: AgentFunctionOptions)
Initializes a new instance of AgentFunction
.
Parameter | Type | Description |
---|---|---|
options |
AgentFunctionOptions |
Configuration options of function. |
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>
value: Input
- The input to the function.Promise<Output>
- The output of the function.AggregateError
if the input is invalid or if the function
execution fails.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.