AmazonBedrockSupportedModels

The AmazonBedrockSupportedModels class offers constants for models supported by Amazon Bedrock, simplifying model selection in your applications.

Usage

import { AmazonBedrockSupportedModels } from 'xpander-sdk';

const model = AmazonBedrockSupportedModels.ANTHROPIC_CLAUDE_3_5_SONNET_20240620;
ConstantDescription
ANTHROPIC_CLAUDE_3_5_SONNET_20240620Optimized for general use.
ANTHROPIC_CLAUDE_3_HAIKU_20240307Excels in summarization tasks.
COHERE_COMMAND_RIdeal for command-based instructions and NLP.

These constants help in selecting models that support function calling, reducing the need to memorize model names and IDs.

NvidiaNIMSupportedModels

The NvidiaNIMSupportedModels class provides constants for NVIDIA’s NIM platform models, aiding in model selection.

Usage

import { NvidiaNIMSupportedModels } from 'xpander-sdk';

const model = NvidiaNIMSupportedModels.LLAMA_3_1_70B_INSTRUCT;
ConstantDescription
LLAMA_3_1_70B_INSTRUCTSuitable for large-scale instructional tasks requiring deep context understanding.

OpenAISupportedModels

The OpenAISupportedModels class provides constants for OpenAI models compatible with the xpander SDK.

Usage

import { OpenAISupportedModels } from 'xpander-sdk';

const model = OpenAISupportedModels.GPT_4;
ConstantDescription
GPT_4Latest version of OpenAI’s GPT model.
GPT_4_OCost-effective optimized version.

ToolResponse

The ToolResponse class encapsulates the response from a tool invoked by an AI Agent, including details like tool call ID, role, and response message.

Initialization

import { ToolResponse } from 'xpander-sdk';

const response = new ToolResponse(
  'tool-call-id',
  'assistant',
  'Weather Tool',
  'Here is your weather report...',
  filteredToolObject,
  'payload request data'
);

Methods

  • toJSON(): Serializes the ToolResponse instance to a JSON object.
  • fromJSON(json: any): Instantiates a ToolResponse from a JSON object.

XpanderClient

The XpanderClient is the core class for interacting with xpanderAI tools, offering methods for managing sessions and invoking tools.

Initialization

import { XpanderClient } from 'xpander-sdk';

const client = new XpanderClient(
  'agent-key',
  'https://agent-url',
  LLMProvider.OPEN_AI,
  localToolsArray,
  toolsArray,
  customParams
);

Methods

MethodDescription
addLocalTools(tools: ILocalTool[])Adds tools for specific needs.
getGraphSessionParam(param: string)Retrieves a parameter for the current session.
startSession(prompt?: string)Initiates a new session with an optional prompt.
xpanderToolCall(toolSelectorResponse: any, llmProvider?: string)Invokes tools based on the selector response.

LLMProvider Enum

The LLMProvider enum allows selection of the desired LLM provider for interactions.

Values

ValueDescription
LANG_CHAINLangChain’s LLM models.
OPEN_AIOpenAI models like GPT-4.
NVIDIA_NIMNVIDIA’s LLM models.
AMAZON_BEDROCKAmazon Bedrock’s LLM models.

Example Workflow

To create an AI agent workflow interacting with multiple systems, follow these steps:

  1. Initialize the Xpander Client:
import { XpanderClient, OpenAISupportedModels } from 'xpander-sdk';

const xpanderClient = new XpanderClient(
  'your-agent-key',
  'your-agent-url',
  OpenAISupportedModels.GPT_4
);
  1. Add Local Tools:
xpanderClient.addLocalTools(localToolsArray);
  1. Start a Session:
xpanderClient.startSession('Start analyzing customer support conversations.');
  1. Invoke a Tool:
const response = xpanderClient.xpanderSingleToolInvoke('sentiment-analysis-tool-id', payloadData);
console.log(response);

Protocols & Interfaces

To extend the xpander SDK or create custom implementations, interfaces are provided:

ITool

The ITool interface represents a generic tool used by AI agents, including properties like:

PropertyDescription
nameThe tool’s name.
descriptionA description of the tool’s capabilities.
funcFunction for executing the tool.
parametersParameters required for execution.

Example Implementation

class CustomTool implements ITool {
  name = 'Custom Sentiment Analyzer';
  description = 'Analyzes sentiment of customer support messages';
  func = (params) => {
    // Custom logic here
  };
  parameters = {
    inputText: { type: 'string', description: 'Text to analyze' },
  };
}

ILocalTool

The ILocalTool interface allows the creation of tools for local use, maintaining security boundaries.