Skip to main content

Call your agents from code

Preview

The agents package is in private preview and not yet released. Names may change before release.

The agents package talks to the agents you deployed on Autessa: start a conversation, send turns, read the reply, and attach files, images and audio. The agent's own firewall policy runs on Autessa on every turn.

When to use it​

  • Your website, app or backend needs to chat with an Autessa agent.
  • You built the agent in the builder or in code, and want to call it from your own service.
  • You want to send documents, images or recordings to an agent along with a message.

Install​

npm install @autessa/agents

During the preview, build the package from the autessa-js repository and install the packed files, as its README describes.

Set a key that can use the agent. A developer key from Get a free API key acts as you, so it can talk to any agent you can open. To limit a key to one agent, create it in Settings → API keys. Agents are a resource-scoped API. See Keys.

export AUTESSA_API_KEY="<keyId>:<secret>"

Start a conversation​

import { Agents } from "@autessa/agents";

const agents = new Agents(); // reads AUTESSA_API_KEY
const { conversationId, reply } = await agents.start({ agentId: "V1StGXR8Z5", message: "Where is order A1001?" });
console.log(reply);
console.log((await agents.send(conversationId, "Can I change the address?")).reply);

start opens a conversation and sends the first message. It also takes externalId (your own ID for the conversation) and metadata. Both reach the agent's tools as environment variables: externalId, and one per metadata key.

Keep a conversation going​

A Conversation remembers its ID, so you just keep calling send.

const chat = await agents.conversation("V1StGXR8Z5");
console.log(await chat.send("Hi, I need help with a refund."));
console.log(await chat.send("Order A1001."));
await chat.close();

Send files, images and audio​

Upload first, then attach the result to a message. Uploads go straight to a short-lived link with the content type it expects, and your API key isn't sent with them.

const pdf = await agents.uploadFile("V1StGXR8Z5", bytes, { fileExtension: "pdf" });
const r = await agents.send(conversationId, [
{ inputType: "TEXT", content: "What does this invoice say?" },
{ inputType: "FILE", ...pdf },
]);
console.log(r.reply);

Reference​

CallWhat it does
startOpens a conversation and sends the first message. Returns the conversation ID and the reply.
send(conversationId, message)One turn. Returns the reply text and every output part.
create(agentId)Opens a conversation with no message yet (TypeScript and Python).
get(conversationId)The conversation's record.
status(conversationId)IN_PROGRESS, CLOSED or NOT_FOUND.
close(conversationId), revive(conversationId)Ends a conversation, or reopens it.
uploadFile, uploadImage, uploadAudioUploads a file to attach (upload_file and so on in Python).
conversation(agentId)A conversation object you keep calling send on.
  • A conversation this client didn't start needs the agent ID once: send(id, message, {}, agentId) in TypeScript, send(..., agent_id=...) in Python, conversation(agentId, conversationId) in Java.
  • Errors are typed: a key that can't use the agent is an auth error (401), an account out of credit is a budget error (402). Rate limits (429) and server errors (5xx) are retried.
  • The package doesn't call the firewall itself. The agent's policy runs on Autessa.

API reference​

The package calls the Agents API.