Define Agent

Define Agent

Use the defineAgent function to create an agent type that can be reused.

API Reference

defineAgent(agent)

Defines an agent with tools, input, and output specifications.

Parameters

  • agent:
    • tools (object, required): The tools object for this agent
    • input (object, optional): An object with schemas of input values, with names as object keys
    • output (s.Schema, optional): A schema of the expected output

Example

import { defineAgent, defineTool } from 'agentscript-ai/core';
import * as s from 'agentscript-ai/schema'
 
const add = defineTool({
    name: 'add',
    description: 'Add two numbers',
    input: {
        a: s.number(),
        b: s.number(),
    },
    output: s.number(),
    handler: ({ input }) => input.a + input.b
})
 
const MyAgent = defineAgent({
    tools: {
      add
    },
    input: {
      text: s.string({description: "Text to process"}),
    },
    output: s.number({ description: "Result of the computation"})
});

The defined agent can be used with inferAgent, createAgent, and other AgentScript functions.