Add a tool

Give an agent a tool: a typed function it can call, which says what it needs and when to use it, and runs on the server.

Before you start

You need an agent. See Create an agent.

Add a tool

  1. Create the tool. Its id is how agents name it:
    tools/get-time.ts
    import { tool } from "veryfront/tool"; export default tool({  id: "get-time",  description: "Get the current time in a time zone, such as Asia/Tokyo.",  inputSchema: {    type: "object",    properties: {      timeZone: { type: "string", description: "An IANA time zone, such as Asia/Tokyo" },    },    required: ["timeZone"],    additionalProperties: false,  },  execute: async ({ timeZone }) => ({    time: new Date().toLocaleString("en-GB", { timeZone, dateStyle: "full", timeStyle: "short" }),  }),});
  2. Add it to your agent's tools. An agent uses only the tools it lists:
    agents/support.ts
    import { agent } from "veryfront/agent"; export default agent({  id: "support",  name: "Support assistant",  system: "Answer customer questions about orders and refunds. Keep replies to two sentences.",  tools: { "get-time": true },});
  3. Start the project with npm run dev.
  4. Open Chat in Studio.
  5. Pick Support assistant.
  6. Ask "What time is it in Tokyo?". You should now see it call get-time and reply with the time in Tokyo.

Try it in a sandbox

  1. Create a project

  2. Create the tool

  3. Add it to your agent

  4. Start it

  5. Ask it

Try it out

Next steps