createAgent
The createAgent function takes a partial Agent object with schema definitions, and produces full Agent object that contains a script, plan and an execution state.
API Reference
createAgent(params)
Creates an agent object that can be executed.
Parameters
params:script(Script, required): The script that represents the agent logictools(object, optional): The tools object for the agentoutput(s.Schema, optional): An schema of the expected outputinput(object, optional): An object with schemas of input values, with names as object keysstate(AgentState, optional): State of the agent, this is set by the executeAgent
Returns
Returns a full Agent object with the following properties:
tools: Tools that are passed into the methodinput: Input schema for the agentoutput: Output schema for the agentscript: Parsed agent code ASTplan: Execution plan summarystate: Execution state for this agentid: Unique id of the agent
Example
import { parseScript, createAgent, 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 script = parseScript('const result = add(1, 2);');
const agent = createAgent({
tools: {
add
},
script
});