npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@deepagents/agent

v0.8.1

Published

A framework for building multi-agent AI systems with TypeScript. Create agents that use tools, coordinate through handoffs, and work together to solve complex tasks.

Downloads

756

Readme

@deepagents/agent

A framework for building multi-agent AI systems with TypeScript. Create agents that use tools, coordinate through handoffs, and work together to solve complex tasks.

Features

  • Agent Composition - Build modular agents with specific roles and capabilities
  • Tool Integration - Compatible with Vercel AI SDK tools
  • Handoffs - Agents can delegate to specialized agents automatically
  • Structured Output - Type-safe responses with Zod schemas
  • Streaming - Real-time streaming responses
  • Context Sharing - Type-safe state passed between agents

Installation

npm install @deepagents/agent

Requires Node.js LTS (20+) and a zod peer dependency.

Quick Start

Simple Agent

import { agent, execute, user } from '@deepagents/agent';
import { openai } from '@ai-sdk/openai';

const assistant = agent({
  name: 'assistant',
  model: openai('gpt-4o'),
  prompt: 'You are a helpful assistant.',
});

const stream = execute(assistant, 'Hello!', {});

for await (const chunk of stream.textStream) {
  process.stdout.write(chunk);
}

Agent with Tools

import { agent, execute } from '@deepagents/agent';
import { openai } from '@ai-sdk/openai';
import { tool } from 'ai';
import { z } from 'zod';

const weatherTool = tool({
  description: 'Get weather for a location',
  parameters: z.object({
    location: z.string(),
  }),
  execute: async ({ location }) => {
    return { temperature: 72, condition: 'sunny', location };
  },
});

const weatherAgent = agent({
  name: 'weather_agent',
  model: openai('gpt-4o'),
  prompt: 'You help users check the weather.',
  tools: { weather: weatherTool },
});

const stream = execute(weatherAgent, 'What is the weather in Tokyo?', {});
console.log(await stream.text);

Multi-Agent with Handoffs

import { agent, instructions, swarm } from '@deepagents/agent';
import { openai } from '@ai-sdk/openai';

const researcher = agent({
  name: 'researcher',
  model: openai('gpt-4o'),
  prompt: 'You research topics and provide detailed information.',
  handoffDescription: 'Handles research and fact-finding tasks',
  tools: { /* research tools */ },
});

const writer = agent({
  name: 'writer',
  model: openai('gpt-4o'),
  prompt: 'You write clear, engaging content based on research.',
  handoffDescription: 'Handles writing and content creation',
});

const coordinator = agent({
  name: 'coordinator',
  model: openai('gpt-4o'),
  prompt: instructions({
    purpose: ['Coordinate research and writing tasks'],
    routine: [
      'Analyze the request',
      'Use transfer_to_researcher for fact-finding',
      'Use transfer_to_writer for content creation',
    ],
  }),
  handoffs: [researcher, writer],
});

// Agents automatically transfer control via transfer_to_<agent_name> tools
const stream = swarm(coordinator, 'Write a blog post about AI agents', {});

Structured Output

import { agent, generate } from '@deepagents/agent';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';

const analyzer = agent({
  name: 'analyzer',
  model: openai('gpt-4o'),
  prompt: 'Analyze the sentiment of the given text.',
  output: z.object({
    sentiment: z.enum(['positive', 'negative', 'neutral']),
    confidence: z.number(),
    keywords: z.array(z.string()),
  }),
});

const result = await generate(analyzer, 'I love this product!', {});
console.log(result.experimental_output);
// { sentiment: 'positive', confidence: 0.95, keywords: ['love', 'product'] }

Context Variables

Share state between agents and tools:

import { agent, execute, toState } from '@deepagents/agent';
import { tool } from 'ai';
import { z } from 'zod';

interface AppContext {
  userId: string;
  preferences: Record<string, string>;
}

const preferenceTool = tool({
  description: 'Save user preference',
  parameters: z.object({
    key: z.string(),
    value: z.string(),
  }),
  execute: async ({ key, value }, options) => {
    const ctx = toState<AppContext>(options);
    ctx.preferences[key] = value;
    return `Saved ${key}=${value}`;
  },
});

const assistant = agent<unknown, AppContext>({
  name: 'assistant',
  model: openai('gpt-4o'),
  prompt: (ctx) => `Help user ${ctx?.userId} manage their preferences.`,
  tools: { savePreference: preferenceTool },
});

const context: AppContext = { userId: 'user123', preferences: {} };
const stream = execute(assistant, 'Set my theme to dark', context);
await stream.text;

console.log(context.preferences); // { theme: 'dark' }

API Reference

agent(config)

Creates a new agent:

agent<Output, ContextIn, ContextOut>({
  name: string;                    // Agent identifier (required)
  model: LanguageModel;            // AI SDK model (required)
  prompt: string | string[] | ((ctx?) => string);  // Instructions
  tools?: ToolSet;                 // Available tools
  handoffs?: Agent[];              // Agents to delegate to
  handoffDescription?: string;     // When to use this agent
  output?: z.Schema<Output>;       // Structured output schema
  temperature?: number;            // LLM temperature
  toolChoice?: ToolChoice;         // 'auto' | 'none' | 'required'
})

instructions({ purpose, routine })

Helper for structured prompts:

instructions({
  purpose: string | string[],  // Agent's role
  routine: string[],           // Step-by-step workflow
})

// For swarm coordination
instructions.swarm({ purpose, routine })

Execution Functions

// Streaming execution
execute(agent, messages, context, config?)
stream(agent, messages, context, config?)  // alias

// Non-streaming execution
generate(agent, messages, context, config?)

// High-level UI streaming with handoff support
swarm(agent, messages, context, abortSignal?)

Utilities

// Create user message
user(message: string): UIMessage

// Access context in tools
toState<T>(options: ToolCallOptions): T

// Extract structured output
toOutput<T>(result): Promise<T>

AI Model Providers

Works with any model provider supported by the Vercel AI SDK:

import { openai } from '@ai-sdk/openai';
import { anthropic } from '@ai-sdk/anthropic';
import { google } from '@ai-sdk/google';
import { groq } from '@ai-sdk/groq';

const agent1 = agent({ model: openai('gpt-4o'), /* ... */ });
const agent2 = agent({ model: anthropic('claude-sonnet-4-20250514'), /* ... */ });
const agent3 = agent({ model: google('gemini-1.5-pro'), /* ... */ });

Documentation

Full documentation available at januarylabs.github.io/deepagents.

Repository

github.com/JanuaryLabs/deepagents