We've released the Enterprise CLI for seamless deployments of Next.js projects on the AWS with complete IaC (Terraform) setup. Learn more
Blazity Logo
Packages

TypeScript Library

Seamlessly integrate AgentBridge-defined APIs with AI agents through AI SDK

Installation

npm install @agent-bridge/client

Usage

This library is currently tailored to work with the AI SDK, providing a simple interface for interacting with AgentBridge-defined APIs.

Support beyond AI SDK is on the roadmap. While technically it can be used in other contexts, DX may be worse.

Loading a Schema

You can load an AgentBridge schema from either a local file or a remote URL:

import { readSchemaFromFile, fetchSchemaFromUrl } from "@agent-bridge/client";
 
// From a local file
const localSchema = await readSchemaFromFile("./path/to/schema.json");
 
// From a remote URL
const remoteSchema = await fetchSchemaFromUrl(
  "https://api.example.com/schema.json"
);

Creating a Client

import { AgentBridgeClient, LogLevel } from "@agent-bridge/client";
 
const client = AgentBridgeClient(schema, { apiKey: "your-api-key" }, LogLevel.INFO);

Usage with Vercel AI SDK

import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";
 
// ... code to initialize the client
 
const { messages } = await req.json();
 
const { text } = await generateText({
  model: openai("gpt-4o"),
  messages,
  tools: client.getTools(),
});

Logging

The client includes a configurable logging system:

// Set log level during initialization
const client = new AgentBridgeClient(schema, credentials, LogLevel.DEBUG);
 
// Or change it later
client.setLogLevel(LogLevel.TRACE);

Available log levels: NONE, ERROR, WARN, INFO, DEBUG, TRACE

Methods

executeAction

A method that executes a single API action. Returns a promise that resolves to the action result.

const result = await client.executeAction("get_weather", { city: "London" });

executeFlow

A method that executes a multi-step flow. Returns a promise that resolves to the flow result.

const result = await client.executeFlow("aviation_weather_briefing", {
  date: "2023-03-01",
  atsu: "LHR",
  time: "1200",
});

getTools

A method that returns a list of tools in ToolSet type from ai-sdk library.

const tools = client.getTools();

listFlows

A method that returns a list of flows that can be executed.

const flows = client.listFlows();

listActions

A method that returns a list of actions that can be executed.

const actions = client.listActions();

setLogLevel

A method that sets the log level, controlling the verbosity of the client's logging output.

client.setLogLevel(LogLevel.DEBUG);

Helpers

readSchemaFromFile

A helper function that reads a AgentBridge schema from a local file.

import { readSchemaFromFile } from "@agent-bridge/client";
 
const schema = await readSchemaFromFile("./path/to/schema.json");

fetchSchemaFromUrl

A helper function that fetches a AgentBridge schema from a remote URL.

import { fetchSchemaFromUrl } from "@agent-bridge/client";
 
const schema = await fetchSchemaFromUrl("https://api.example.com/schema.json");

On this page