Call your agents from code
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
- TypeScript
- Python
- Java
npm install @autessa/agents
During the preview, build the package from the autessa-js repository and install the packed files, as its README describes.
pip install "autessa-core @ git+https://github.com/Autessa-Inc/autessa-python#subdirectory=packages/autessa-core"
pip install "autessa-agents @ git+https://github.com/Autessa-Inc/autessa-python#subdirectory=packages/autessa-agents"
After release: pip install autessa-agents.
<dependency>
<groupId>com.autessa</groupId>
<artifactId>autessa-agents</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
During the preview, build autessa-java from source first. For Spring Boot, add autessa-spring-boot-starter next to it.
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
- TypeScript
- Python
- Java
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);
from autessa.agents import Agents
agents = Agents() # reads AUTESSA_API_KEY
first = agents.start("V1StGXR8Z5", "Where is order A1001?")
print(first.reply)
print(agents.send(first.conversation_id, "Can I change the address?").reply)
import com.autessa.agents.Agents;
import com.autessa.agents.AgentReply;
Agents agents = Agents.fromEnv(); // AUTESSA_API_KEY
AgentReply first = agents.start("V1StGXR8Z5", "Where is order A1001?");
System.out.println(first.text());
System.out.println(agents.send(first.conversationId(), "Can I change the address?").text());
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.
- TypeScript
- Python
- Java
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();
with agents.conversation("V1StGXR8Z5") as chat:
print(chat.send("Hi, I need help with a refund.").reply)
print(chat.send("Order A1001.").reply)
# leaving the with block closes the conversation
AsyncAgents and AsyncConversation do the same as coroutines.
Conversation chat = agents.conversation("V1StGXR8Z5");
System.out.println(chat.send("Hi, I need help with a refund.").text());
System.out.println(chat.send("Order A1001.").text());
chat.close();
To pick up a conversation started elsewhere: agents.conversation(agentId, conversationId).
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.
- TypeScript
- Python
- Java
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);
pdf = agents.upload_file("V1StGXR8Z5", "invoice.pdf")
r = agents.send(conversation_id, "What does this invoice say?", attachments=[pdf])
print(r.reply)
Bytes need file_name= or extension=.
UploadedFile pdf = agents.uploadFile("V1StGXR8Z5", Path.of("invoice.pdf"));
System.out.println(agents.send(conversationId, "What does this invoice say?", List.of(pdf)).text());
Reference
| Call | What it does |
|---|---|
start | Opens 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, uploadAudio | Uploads 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.