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

@agenite/agent

v0.5.0

Published

Simple and maintainable agent library

Readme

@agenite/agent

A powerful and flexible TypeScript library for building AI agents with advanced tool integration and state management capabilities.

Features

  • 🛠️ Advanced tool integration - Seamlessly integrate custom tools and APIs with type safety
  • 🔄 Stateful conversations - Built-in state management with custom reducers
  • 🌊 Streaming support - Real-time streaming of agent responses and tool executions
  • 🎯 Execution context - Track and manage nested agent executions with context inheritance
  • 🔌 Provider agnostic - Support for multiple LLM providers (Ollama, Bedrock)
  • 🎨 Flexible architecture - Build simple to complex agent hierarchies with middleware support
  • 📊 Token usage tracking - Monitor and optimize token consumption across executions
  • 🔄 Step-based execution - Fine-grained control over agent execution flow

Installation

npm install @agenite/agent

Quick start

import { Agent } from '@agenite/agent';
import { OllamaProvider } from '@agenite/ollama';

// Create a simple calculator tool
const calculatorTool = new Tool({
  name: 'calculator',
  description: 'Perform basic math operations',
  execute: async ({ input }) => {
    // Tool implementation
    return { success: true, data: result.toString() };
  },
});

// Initialize the agent
const agent = new Agent({
  name: 'math-buddy',
  provider: new OllamaProvider({ model: 'llama2' }),
  tools: [calculatorTool],
  instructions: 'You are a helpful math assistant.',
});

// Execute the agent
const result = await agent.execute({
  messages: [{ role: 'user', content: [{ type: 'text', text: 'What is 1234 * 5678?' }] }],
});

Core concepts

Agent

The main class that orchestrates interactions between the LLM and tools. It handles:

  • Message processing and state management
  • Tool execution and result handling
  • Response streaming
  • Nested agent execution
  • Token usage tracking

Tools

Tools are functions that agents can use to perform specific tasks. Each tool has:

  • Name and description
  • Input schema with type safety
  • Execute function with context support
  • Error handling capabilities

Providers

LLM providers that handle the actual language model interactions:

  • Ollama
  • Amazon Bedrock
  • Extensible for other providers

Steps

The agent execution is broken down into steps:

  • llm-call - Handles LLM interactions
  • tool-call - Manages tool execution
  • tool-result - Processes tool results
  • agent-call - Handles nested agent execution

Advanced usage

Stateful agent with custom reducer

const customReducer = {
  messages: (newValue, previousValue) => [
    ...(previousValue || []),
    ...(newValue || []),
  ],
  runningTotal: (newValue, previousValue) =>
    (previousValue || 0) + (newValue || 0),
};

const agent = new Agent({
  name: 'stateful-calculator',
  provider,
  tools: [calculatorTool],
  stateReducer: customReducer,
  initialState: {
    runningTotal: 0,
  },
  instructions:
    'You are a helpful math assistant that maintains a running total.',
});

Nested agents with delegation

// Specialist agents
const calculatorAgent = new Agent({
  name: 'calculator-specialist',
  provider,
  tools: [calculatorTool],
  description: 'Specializes in mathematical calculations',
});

const weatherAgent = new Agent({
  name: 'weather-specialist',
  provider,
  tools: [weatherTool],
  description: 'Provides weather information',
});

// Coordinator agent
const coordinatorAgent = new Agent({
  name: 'coordinator',
  provider,
  agents: [calculatorAgent, weatherAgent],
  instructions:
    'Coordinate between specialist agents to solve complex problems.',
});

Streaming responses with middleware

const agent = new Agent({
  name: 'streaming-agent',
  provider,
  tools: [calculatorTool],
  middlewares: [
    executionContextInjector(),
    // Add custom middleware here
  ],
});

const iterator = agent.iterate({
  messages: [{ role: 'user', content: [{ type: 'text', text: 'Your query here' }] }],
  stream: true,
});

for await (const chunk of iterator) {
  switch (chunk.type) {
    case 'agenite.llm-call.streaming':
      console.log(chunk.content);
      break;
    case 'agenite.tool-call.params':
      console.log('Using tool:', chunk.toolUseBlocks);
      break;
    case 'agenite.tool-result':
      console.log('Tool result:', chunk.result);
      break;
  }
}

API reference

Agent constructor

new Agent({
  name: string;
  provider: LLMProvider;
  tools?: Tool[];
  instructions?: string;
  description?: string;
  agents?: Agent[];
  stateReducer?: CustomStateReducer;
  initialState?: Partial<StateFromReducer<CustomStateReducer>>;
  steps?: Steps;
  middlewares?: Middlewares;
})

Execute method

execute({
  messages: BaseMessage[];
  stream?: boolean;
  context?: Record<string, unknown>;
}): Promise<ExecutionResult>

Iterate method

iterate({
  messages: BaseMessage[];
  stream?: boolean;
  context?: Record<string, unknown>;
}): AsyncIterator<StreamChunk>

Examples

Check out the examples directory for more detailed examples:

  • basic/ - Simple examples showing core functionality
    • simple-chat.ts - Basic chat agent with calculator tool
  • advanced/ - More complex examples
    • nested-agents.ts - Agent composition and delegation
    • stateful-agent.ts - Maintaining conversation state
    • streaming-agent.ts - Real-time response streaming
    • multi-tool-agent.ts - Using multiple tools

Contributing

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

License

MIT