Skip to content

A flexible toolkit for building, running, and managing AI-powered agents - built on top of the Vercel AI SDK. Integrates seamlessly with your favorite frameworks.

License

Notifications You must be signed in to change notification settings

sslava/ai-sdk-agents

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

59 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

AI SDK Agents

NPM version GitHub license Actions Status

A powerful and flexible library for building AI agents using the Vercel AI SDK. This project provides a simple yet powerful way to create and manage AI agents with customizable flows, tools, and contexts.

Features

  • πŸ€– Simple agent creation and management
  • πŸ”„ Customizable agent flows
  • πŸ› οΈ Extensible tool system
  • πŸ“ Context management
  • πŸ”„ Streaming support

Installation

npm install ai-sdk-agents
# or
yarn add ai-sdk-agents
# or
pnpm add ai-sdk-agents

Prerequisites

This package requires the Vercel AI SDK and zod as a peer dependency:

npm install ai zod
# or
yarn add ai zod
# or
pnpm add ai zod

Usage

Here's a basic example of how to use the library:

import { agent, ChatFlow, Context } from 'ai-sdk-agents';
import { openai } from '@ai-sdk/openai';

export type PlannerContext = Context & {
  today: string;
};

const sqlAgent = agent({
  model: openai('gpt-4o'),
  system: (ctx: PlannerContext) => plannerPrompt(ctx.today),
  description: 'This agent can help you write SQL queries',
  tools: { sqlExecutor: sqlExecutorTool },
  asTool: {
    input: z.object({
      question: z.string().describe('The user query to analyze'),
    }),
    getPrompt: ({ question }) => ({
      prompt: `question: ${question}.
      - Make sure you return no more than 200 rows of data.`,
    }),
  },
});

export const routerAgent = agent({
  system: (ctx: InsightContext) => routerPrompt(ctx),
  model: openai('gpt-4o'),
  maxSteps: 5,
  tools: { sqlAgent },
  toolChoice: 'auto',
});

const flow = new ChatFlow({ agent: routerAgent });
const ctx = { history: [], today: new Date().toISOString().split('T')[0] };
const { result } = await flow.run(ctx);

Project Structure

src/
β”œβ”€β”€ agent.ts           # Core agent implementation
β”œβ”€β”€ context.ts         # Context management
β”œβ”€β”€ flow.ts             # Flow control and management
β”œβ”€β”€ flows/              # Predefined flow implementations
β”‚   └── chat-flow.ts    # Chat flow implementation
β”œβ”€β”€ index.ts           # Main entry point
β”œβ”€β”€ tools.ts           # Tool definitions
β”œβ”€β”€ types.ts           # Type definitions
β”œβ”€β”€ utils.ts           # Utility functions
└── prompts.ts         # Prompt handling

Development

Setup

  1. Clone the repository
  2. Install dependencies:
    yarn install

Available Scripts

  • yarn test - Run tests using Vitest
  • yarn lint - Run ESLint with auto-fix
  • yarn format - Format code using Prettier

Tests

Comprehensive tests are located in the tests/ directory.

Examples

Example projects are located in the examples/ directory. (Note: If the directory is currently named exmaples/, please rename it to examples/.)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

TODO

  • Add more tests
  • Add more examples
  • Add more documentation
  • Inter-Agent memory

About

A flexible toolkit for building, running, and managing AI-powered agents - built on top of the Vercel AI SDK. Integrates seamlessly with your favorite frameworks.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •