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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ulifeai/agentb

v0.1.2

Published

The easiest way to integrate AI agents with your API tools in your app.

Downloads

1

Readme

AgentB 🚀

AgentB is a flexible and extensible TypeScript framework designed for building sophisticated AI agents capable of interacting with Large LanguageModels (LLMs) and utilizing external tools. It provides a robust, modular architecture to create, manage, and orchestrate autonomous agents for complex task automation.

npm version License: MIT GitHub stars

✨ Features

  • Modular Design: Core abstractions for LLMs, tools, threads, messages, and agents, promoting separation of concerns.
  • Extensible Tool System:
    • Easily define custom tools (ITool).
    • Built-in OpenAPIConnector to automatically generate tools from OpenAPI specifications.
    • Support for generic HTTP tools for direct API calls.
  • LLM Agnostic: Designed with an ILLMClient interface to allow integration with various LLM providers. Comes with a ready-to-use OpenAIAdapter.
  • Hierarchical Agent Architecture: Supports advanced agent patterns like a PlanningAgent delegating tasks to specialized "worker" agents using the DelegateToSpecialistTool.
  • Stateful Conversations: Manage conversation threads and messages with persistent storage options (default in-memory, extendable to databases).
  • Context Management: Built-in ContextManager to handle LLM context window limits through summarization and truncation.
  • Streaming Support: Agents can stream responses and events, enabling real-time UI updates.
  • Simplified Facade (AgentB): An easy-to-use entry point (AgentB.initialize(), AgentB.registerToolProvider(), AgentB.getStreamingHttpHandler()) for quick integration into your applications.
  • Configuration Driven: Flexible configuration for agents, LLM parameters, tool execution, and response processing.
  • TypeScript First: Written entirely in TypeScript for strong typing and better developer experience.

📦 Installation

npm install agentb
# or
yarn add agentb

🚀 Quick Start

This example demonstrates setting up a simple agent that can use tools from an OpenAPI specification (e.g., the PetStore API) and stream responses via an Express.js server.

// server.ts
import express from 'express';
import { AgentB, ToolProviderSourceConfig } from 'agentb'; // Assuming 'agentb' is your published package name
import * as dotenv from 'dotenv';
// import { OpenAPISpec } from 'agentb/dist/openapi/types'; // For type if loading spec manually
// import * as fs from 'fs/promises';
// import * as path from 'path';

dotenv.config();

const app = express();
app.use(express.json());

async function startApp() {
    if (!process.env.OPENAI_API_KEY) {
        console.error("CRITICAL: OPENAI_API_KEY is not set!");
        process.exit(1);
    }

    // 1. Initialize AgentB
    AgentB.initialize({
        llmProvider: {
            provider: 'openai',
            apiKey: process.env.OPENAI_API_KEY,
            model: 'gpt-4o-mini', // Your preferred default model
        },
        // Optionally provide custom storage adapters here
        // messageStorage: new MyCustomMessageStorage(),
        // agentRunStorage: new MyCustomAgentRunStorage(),
        // threadStorage: new MyCustomThreadStorage(),
    });
    console.log("AgentB Initialized.");

    // 2. Register Tool Providers (e.g., OpenAPI specs)
    // Example using a public PetStore spec URL
    const petStoreApiConfig: ToolProviderSourceConfig = {
        id: 'petStoreAPI', // Unique ID for this tool source
        type: 'openapi',
        openapiConnectorOptions: {
            specUrl: 'https://petstore3.swagger.io/api/v3/openapi.json',
            // For local specs:
            // spec: await loadLocalSpec('./specs/petstore.openapi.json'), // Implement loadLocalSpec
            authentication: { type: 'none' }, // PetStore example needs no auth
        },
        toolsetCreationStrategy: 'byTag', // Create a toolset for each API tag
    };
    AgentB.registerToolProvider(petStoreApiConfig);
    console.log(`Tool Provider "${petStoreApiConfig.id}" Registered.`);

    // 3. Create the HTTP streaming endpoint
    app.post('/agent/stream', AgentB.getStreamingHttpHandler({
        // Customize how threadId and user messages are extracted from the request
        getThreadId: async (req, threadStorage) => {
            const requestedThreadId = req.body.threadId || req.query.threadId;
            if (requestedThreadId && typeof requestedThreadId === 'string') {
                if (await threadStorage.getThread(requestedThreadId)) return requestedThreadId;
            }
            const newThread = await threadStorage.createThread({ title: "New Chat" });
            return newThread.id;
        },
        getUserMessage: async (req) => {
            if (!req.body.prompt || typeof req.body.prompt !== 'string') {
                throw new Error("Request body must contain a 'prompt' string.");
            }
            return { role: 'user', content: req.body.prompt };
        },
        // Optional: Add your authorization logic
        // authorizeRequest: async (req, threadId) => { return true; },
    }));

    const PORT = process.env.PORT || 3001;
    app.listen(PORT, () => {
        console.log(`AgentB server listening on port ${PORT}`);
        console.log(`Try: POST http://localhost:${PORT}/agent/stream with JSON body: {"prompt": "Your question", "threadId": "optional_thread_id"}`);
        console.log(`Example: curl -X POST -H "Content-Type: application/json" -d '{"prompt":"Find pet with ID 1"}' http://localhost:${PORT}/agent/stream --no-buffer`);
    });
}

startApp().catch(console.error);

For the UI component suggestion (<AgentBridgeChatUI />): That's a great idea for a complementary package! AgentB provides the backend framework. A separate UI component library could consume the SSE stream from the /agent/stream endpoint to render a chat interface.

📚 Core Concepts

  • AgentB Facade: Simplifies initialization and HTTP handler creation.
  • ApiInteractionManager: Manages different agent interaction modes (genericOpenApi, toolsetsRouter, hierarchicalPlanner).
  • IAgent & BaseAgent: Define and implement the core agent execution loop, handling LLM calls, tool execution, and event streaming.
  • ITool, IToolProvider, IToolSet: Abstractions for defining, providing, and organizing tools.
  • OpenAPIConnector: Automatically creates tools from OpenAPI specifications.
  • ILLMClient & OpenAIAdapter: Abstract LLM interactions, with a default OpenAI implementation.
  • I[Message/Thread/AgentRun]Storage & MemoryStorage: Abstract and provide default in-memory storage for conversation state.
  • ToolsetOrchestrator: Manages creating logical groups of tools (IToolSet) from providers.
  • DelegateToSpecialistTool & PlanningAgent: Enable hierarchical agent architectures where a planner delegates to specialized agents.

📖 Documentation (Coming Soon)

Detailed API documentation and further examples will be available soon. In the meantime, the source code is heavily commented with JSDoc.

Key modules to explore:

  • src/facade/agent-b.ts: For the simplest entry point.
  • src/managers/api-interaction-manager.ts: For understanding interaction modes.
  • src/agents/base-agent.ts: For the core agent loop.
  • src/core/tool.ts: For tool interfaces.
  • src/openapi/connector.ts: For OpenAPI integration.

🛠️ Development

Prerequisites:

  • Node.js (>=18.0.0 recommended)
  • npm or yarn

Setup:

git clone https://github.com/ulifeai/agentb.git
cd agentb
npm install

Build:

npm run build

Lint & Format:

npm run lint
npm run format

Run Examples: (Ensure you have a .env file with OPENAI_API_KEY if running examples that use OpenAI)

# Example for running the PetStore API test script (after building)
# You might need to adjust the path in package.json or run directly
npm run start:example:petstore 
# Or during development with ts-node
npm run dev:example:petstore

🤝 Contributing

Contributions are welcome! Please feel free to submit issues, fork the repository, and create pull requests.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📜 License

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

🙏 Acknowledgements

  • Inspired by the evolving landscape of AI agent frameworks.
  • Utilizes powerful open-source libraries.

This README provides a starting point. You'll want to expand on usage examples, API details, and specific features as AgentB matures.


**Key points about this `README.md`:**

*   **Project Name and Badges**: Uses "AgentB" and includes placeholder badges. You can generate actual badges from services like shields.io after publishing.
*   **Features**: Highlights the key architectural benefits and capabilities.
*   **Installation**: Standard npm/yarn command.
*   **Quick Start**: Provides a concise Express.js example showing how to use the `AgentB` facade. This is crucial for new users.
    *   It now uses a public PetStore spec URL for easier out-of-the-box testing by users (they don't need a local file immediately).
    *   Includes a `curl` example for testing the endpoint.
*   **Core Concepts**: Briefly explains the main components for users who want to understand the architecture.
*   **Development Section**: Basic instructions for setting up, building, and linting.
*   **Contributing and License**: Standard sections.
*   **GitHub URL**: https://github.com/ulifeai/agentb