delphi

📘 Delphi Tutorial: Using Agent Functions

In Delphi, agent functions are a versatile tool allowing your conversational agent to execute specific tasks, like data retrieval or complex computations, dynamically during a conversation. Let’s dive into how you can utilize these functions in your Delphi projects.

Defining Functions

Registering Functions

Enabling And Disabling Functions

Function Invocation

Handling Responses

Example

import { AgentFunction, type JSONSchemaType } from "@wecandobetter/delphi";

interface WeatherParameters {
  location: string;
}

interface WeatherData {
  temperature: number;
  humidity: number;
  windSpeed: number;
}

const weatherSchema: JSONSchemaType<WeatherParameters> = {
  type: "object",
  properties: {
    location: {
      type: "string",
      description:
        "The location to fetch weather information for (e.g. 'The Hague, NL')",
    },
  },
  required: ["location"],
  additionalProperties: false,
};

// Define a custom function
const fetchWeatherInfo = new AgentFunction<WeatherParameters, WeatherData>(
  "getWeather",
  "Fetch current weather information",
  weatherSchema, // Your defined JSON schema for input validation
  async (params) => {
    // Logic to fetch weather information
    return {
      temperature: 22.5, // in Celsius
      humidity: 0.5,
      windSpeed: 10,
  },
);

Conclusion

Agent functions in Delphi provide a powerful way to extend the capabilities of your conversational agents. By defining custom functions, registering them with your agent, and then utilizing them in conversation flows, you can create rich, interactive, and dynamic conversational experiences. The key is to tailor these functions to fit the specific needs and contexts of your application. Happy coding!