Getting Started

Getting Started with AgentScript

This guide will walk you through the installation process and setting up a basic AgentScript project.

Installation

To begin using AgentScript, install the core package using npm:

npm install agentscript-ai

or with yarn:

yarn add agentscript-ai

Make sure you have Node.js and either npm or yarn installed on your system.

Setting up the Environment

AgentScript relies on environment variables to configure API keys for different services. You'll need to create a .env file in your project's root directory.

  1. Copy .env.example: You will find a .env.example file in the root folder of the project, copy it into a .env file.

  2. Fill in API Keys: Open the .env file and add your API keys. For example:

ANTHROPIC_API_KEY=your-anthropic-api-key
LINEAR_API_KEY=your-linear-api-key

Make sure you fill the appropriate keys to connect your app with other integrations.

Basic Agent Example

Here's a basic example of how to create and run an agent:

import { AnthropicModel } from 'agentscript-ai/anthropic';
import { defineTool, inferAgent, executeAgent } 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 llm = AnthropicModel({
    model: 'claude-3-5-sonnet-latest',
    apiKey: process.env.ANTHROPIC_API_KEY,
});
 
const tools = {
    add
};
 
const prompt = 'Add numbers 1 and 2';
const output = s.number();
 
async function main() {
    const agent = await inferAgent({
      tools,
      output,
      llm,
      prompt,
    });
 
    await executeAgent({agent});
 
    console.log("Agent output:", agent.state?.output)
    console.log("Execution variables:", agent.state?.root.variables)
}
 
main()

This example:

  1. Defines a Tool: Creates a simple tool named add that performs addition
  2. Configures LLM: Sets up the AnthropicModel for code generation
  3. Define Available Tools: Pass available tools into tools object
  4. Defines a Task: Sets a natural language prompt for what you want to achieve
  5. Defines the output: Sets the output type using schema
  6. Infers the Agent: Uses inferAgent to let LLM generate the code for execution
  7. Executes the Agent: Executes the agent's generated code with executeAgent
  8. Logs the Results: Outputs the final result, and execution variables

You should see the output Agent output: 3 in the console, with variables that has a and b.

This gives a basic overview of the entire AgentScript flow.