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

@toolhouseai/client

v1.0.0

Published

JavaScript client library for interacting with Toolhouse AI agents

Downloads

18

Readme

Toolhouse JavaScript Client

A lightweight JavaScript client library for interacting with Toolhouse AI agents. Supports both complete response fetching and real-time streaming.

Installation

npm install @toolhouseai/client

Quick Start

import { Toolhouse } from "@toolhouseai/client";

// Initialize the client with your agent ID
const client = new Toolhouse("your-agent-id");

// Send a message and get the complete response
const response = await client.send("Hello, how can you help me?");
console.log(response);

Usage

Basic Setup

import { Toolhouse } from "@toolhouseai/client";

// Basic initialization
const client = new Toolhouse("your-agent-id");

// With custom configuration
const client = new Toolhouse("your-agent-id", {
  baseUrl: "https://custom-agents.toolhouse.ai",
  env: "production",
  toolhouse_id: "your-toolhouse-id",
  bundle: "your-bundle-name",
});

Sending Messages

Complete Response (Promise)

Wait for the complete response before proceeding:

const response = await client.send("What is the weather like today?");
console.log(response);

Streaming Response (Async Iterator)

Process the response as it streams in real-time:

for await (const chunk of client.send("Tell me a story")) {
  process.stdout.write(chunk);
}

Managing Conversations

The client automatically manages conversation state using run IDs. Once you send the first message, subsequent messages will continue the same conversation:

const client = new Toolhouse("your-agent-id");

// First message starts a new conversation
await client.send("Hello");

// Subsequent messages continue the same conversation
await client.send("Can you help me with JavaScript?");
await client.send("Show me an example");

Manual Run ID Management

You can also manually manage run IDs for more control:

// Get the current run ID
const runId = client.getRunId();

// Set a specific run ID (useful for resuming conversations)
client.setRunId("existing-run-id");

// Continue conversation with the set run ID
await client.send("Continue our previous conversation");

Error Handling

try {
  const response = await client.send("Your message");
  console.log(response);
} catch (error) {
  console.error("Error:", error.message);
}

For streaming responses:

try {
  for await (const chunk of client.send("Your message")) {
    process.stdout.write(chunk);
  }
} catch (error) {
  console.error("Streaming error:", error.message);
}

API Reference

Constructor

new Toolhouse(agentId, config?)

Parameters:

  • agentId (string): Your Toolhouse agent ID
  • config (object, optional): Configuration options
    • baseUrl (string): Custom base URL (default: 'https://agents.toolhouse.ai')
    • env (string): Environment parameter
    • toolhouse_id (string): Your Toolhouse ID
    • bundle (string): Bundle name

Methods

send(message)

Send a message to the agent.

Parameters:

  • message (string): The message to send

Returns:

  • Promise that resolves to the complete response string
  • Async iterator that yields response chunks when used with for await

setRunId(runId)

Set the run ID for subsequent requests.

Parameters:

  • runId (string): The run ID to use

getRunId()

Get the current run ID.

Returns:

  • string | null: The current run ID or null if not set

Examples

Chat Application

import { Toolhouse } from "@toolhouse/client";

const client = new Toolhouse("your-agent-id");

async function chat() {
  // Start conversation
  console.log("Bot:", await client.send("Hello! How can I help you today?"));

  // Continue conversation
  console.log("Bot:", await client.send("I need help with coding"));
  console.log("Bot:", await client.send("Show me a JavaScript example"));
}

chat();

Real-time Streaming

import { Toolhouse } from "@toolhouse/client";

const client = new Toolhouse("your-agent-id");

async function streamResponse() {
  console.log("Bot: ");
  for await (const chunk of client.send(
    "Write a short poem about technology"
  )) {
    process.stdout.write(chunk);
  }
  console.log("\n--- End of response ---");
}

streamResponse();

Multiple Conversations

import { Toolhouse } from "@toolhouseai/client";

// Separate clients for separate conversations
const conversation1 = new Toolhouse("your-agent-id");
const conversation2 = new Toolhouse("your-agent-id");

// Each maintains its own conversation state
await conversation1.send("Let's talk about JavaScript");
await conversation2.send("Let's talk about Python");

await conversation1.send("Show me an async function");
await conversation2.send("Show me a list comprehension");

Browser Support

This library works in modern browsers that support:

  • Fetch API
  • Async/await
  • Async iterators
  • ReadableStream

For older browsers, you may need polyfills.

Contributing

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

License

MIT License. See LICENSE file for details.

Support

If you have any questions, ask a question to our Help Agent or come see us on Discord.