Install the superagentai-js
package.
npm i superagentai-js
import SuperagentSDK from "superagentai-js";
const superagent = new SuperagentSDK(process.env.SUPERAGENT_API_TOKEN);
The SDK exposes the following three resources: Prompts
, Documents
and Agents
. Below you will find a schematic overivew of each resource:
// List all agents
await superagent.agents().list();
// Retuns a specific agent
await superagent.agents().get("<AGENT_ID>");
// Delete agent
await superagent.agents().delete("<AGENT_ID>");
// Create agent
await superagent.agents().create({
name: "Ny agent",
llm: {
provider: "openai-chat",
model: "gpt-4",
api_key: process.env.OPENAI_API_KEY,
},
has_memory: true,
promptId: "<PROMPT_ID>",
documentId: "<DOCUMENT_ID>",
toolId: "<TOOL_ID>",
});
// Run an agent
await superagent.agents().predict({
input: { human_input: "Hello" },
has_streaming: true,
});
// List all tools
await superagent.tools().list();
// Retuns a specific tool
await superagent.tools().get("<TOOL_ID>");
// Delete tool
await superagent.tools().delete("<TOOL_ID>");
// Create tool
await superagent.tools().create({
name: "My tool",
type: "SEARCH",
});
// List all documents
await superagent.documents().list();
// Retuns a specific document
await superagent.documents().get("<DOCUMENT_ID>");
// Delete document
await superagent.documents().delete("<DOCUMENT_ID>");
// Create document
await superagent.documents().create({
name: "Ny agent",
url: "https://digitalassets.tesla.com/tesla-contents/image/upload/IR/TSLA-Q1-2023-Update",
type: "PDF",
authorization: null,
splitter: { type: "character", chunk_size: 1000, chunk_overlap: 0 },
});
// List all prompts
await superagent.prompts().list();
// Retuns a specific prompt
await superagent.prompts().get("<PROMPT_ID>");
// Update a specific prompt
await superagent.prompts().update("<PROMPT_ID>", {name: "Some updated name"});
// Delete prompt
await superagent.prompts().delete("<PROMPT_ID>");
// Create prompt
await superagent.prompts().create({
name: "My prompt",
input_variables: ["human_input", "chat_history"],
template="You are an AI assistant that should answer a humans question. \n {chat_history} \n\n Human input: {human_input} \n Answer:"
});