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

open-agents-builder-example

v1.0.0

Published

Example usage of Open Agents Builder client

Readme

Getting Started

This example demonstrates how to use the open-agents-builder-client to connect to the Open Agents Builder API. The API documentation can be found here.

Step 1: Create an API Key

To create an API key, follow the instructions here.

Step 2: Install the npm Packages

Install the required npm packages:

yarn add open-agents-builder-client zod nanoid dotenv
yarn add -D @types/node typescript

Step 3: Set the Required Environment Variables

Set the following environment variables in your project:

  • DATABASE_ID_HASH: Your database ID hash (optional)
  • OPEN_AGENTS_BUILDER_API_KEY: Your API key (required)
  • AGENT_ID: Your agent ID (required for chat examples)

You can set these variables in a .env file at the root of your project:

DATABASE_ID_HASH=your_database_id_hash
OPEN_AGENTS_BUILDER_API_KEY=your_api_key
AGENT_ID=your_agent_id

Example Usage

Here are several examples showing how to use the client:

Basic Setup

import { config } from 'dotenv';
import { OpenAgentsBuilderClient } from "open-agents-builder-client";

// Load environment variables from .env file
config();

const client = new OpenAgentsBuilderClient({
    baseUrl: "https://app.openagentsbuilder.com",  // optional, defaults to this if omitted
    databaseIdHash: process.env.DATABASE_ID_HASH ?? '',  // optional, defaults to this if omitted
    apiKey: process.env.OPEN_AGENTS_BUILDER_API_KEY ?? ''  // required
});

Example 1: Basic Chat with Streaming

import { ChatMessage } from "open-agents-builder-client";

async function basicChat() {
    const messages: ChatMessage[] = [
        { role: "user", content: "What is the capital of France?" }
    ];

    try {
        for await (const chunk of client.chat.streamChat(messages, {
            agentId: process.env.AGENT_ID!
        })) {
            if (chunk.type === 'text') {
                process.stdout.write(chunk.content);
            }
        }
    } catch (error) {
        console.error("Error:", error);
    }
}

Example 2: Chat with Attachments

import * as fs from 'fs';

async function chatWithAttachments() {
    const messages: ChatMessage[] = [
        {
            role: "user",
            content: "What can you tell me about this image?",
            experimental_attachments: [
                {
                    name: "screenshot.png",
                    contentType: "image/png",
                    url: "https://example.com/image.png"
                },
                {
                    name: "sample.pdf",
                    file: "./sample.pdf" // Local file path
                }
            ]
        }
    ];

    try {
        for await (const chunk of client.chat.streamChat(messages, {
            agentId: process.env.AGENT_ID!
        })) {
            if (chunk.type === 'text') {
                process.stdout.write(chunk.content);
            }
        }
    } catch (error) {
        console.error("Error:", error);
    }
}

Example 3: Maintaining Conversation History

import { nanoid } from 'nanoid';

async function conversationWithHistory() {
    const sessionId = nanoid();
    const messages: ChatMessage[] = [
        { role: "user", content: "Let's talk about space exploration." }
    ];

    try {
        // First message
        for await (const chunk of client.chat.streamChat(messages, {
            agentId: process.env.AGENT_ID!,
            sessionId: sessionId
        })) {
            if (chunk.type === 'text') {
                process.stdout.write(chunk.content);
            }
        }

        // Continue conversation
        const followUpMessages: ChatMessage[] = [
            { role: "user", content: "Tell me more about Mars missions." }
        ];

        for await (const chunk of client.chat.streamChat(followUpMessages, {
            agentId: process.env.AGENT_ID!,
            sessionId: sessionId
        })) {
            if (chunk.type === 'text') {
                process.stdout.write(chunk.content);
            }
        }
    } catch (error) {
        console.error("Error:", error);
    }
}

Running the Examples

To run the examples:

yarn build
yarn start

For more detailed examples, check the src/index.ts file in this repository.