Quick Start

Installation

AINU is available as an npm package. You can install it using the following command:

npm install @ainulabs/ainu

Create An Agent

Agents are the core abstraction in AINU. They orchestrate AI tasks by interacting with providers, tools, and other components. Follow these steps to create your first agent.

Step 1: Import Required Modules

Start by importing the necessary classes from AINU:

import { Agent, Anthropic } from "@ainulabs/ainu";

Here, Agent is the main class for creating agents, and Anthropic is a provider that connects the agent to an AI model.

Step 2: Set Up a Provider

Providers are responsible for connecting your agent to an AI service. For this example, we'll use the Anthropic provider:

const provider = new Anthropic({
  apiKey: "your-api-key", // Replace with your actual API key
});

The apiKey is required to authenticate with the Anthropic API. You can replace this with other providers like OpenAI or XAI, depending on your use case.

Step 3: Create the Agent

Now, create an agent and pass the provider to it:

This sets up a basic agent that can interact with the Anthropic provider.

Adding a Tool

Step 1: Import the Tool Class

Import the Tool class from AINU:

Step 2: Create a Tool

Define a tool with a name, description, parameters, and a handler function. For example, a tool to fetch weather data:

Here:

parameters defines the expected input using zod for validation. handler is the function executed when the tool is called.

Step 3: Attach the Tool to the Agent

Add the tool to the agent using the putTool method:

The agent can now use this tool to handle tasks related to weather.

Generating Text

Once your agent is set up with a provider and tools, you can use it to generate text or perform other tasks.

Step 1: Use the generateText Method

Call the generateText method on the agent to generate text based on a prompt:

Here:

  • prompt is the input text for the agent.

  • maxSteps limits the number of steps the agent takes to complete the task.

Step 2: Combine Tools and Text Generation

If the agent has tools (like the weather tool), it can use them to enhance its responses. For example:

This allows the agent to use the weatherTool to fetch weather data dynamically.

Running the Code

To run your code, ensure all dependencies are installed and your file is saved. Use the following command:

If you're using TypeScript, compile the code first:

With these steps, you've successfully installed AINU, created an agent, added a tool, and generated text. You're now ready to explore more advanced features, such as MCP integration and multi-agent systems, in the Core Concepts section.

Last updated