SDK Integration
In previous sections, we've seen how the Agent Runner provides an excellent environment for quickly experimenting with Agents in Studio. To seamlessly integrate Vertesia Agents into your business applications and workflows, Vertesia offers a comprehensive REST API and a robust TypeScript SDK.
This section will guide you through interacting with agents using the TypeScript SDK. No complex configuration is required to get started.
Client Initialization
First, you'll need to get an instance of the Vertesia client. Remember to replace apiKey
with your actual API key.
import { VertesiaClient } from "@vertesia/client";
import { AgentMessageType } from "@vertesia/common";
const vertesia = new VertesiaClient({
apikey: apiKey,
});
Initiating Agent Execution
Next, you can kick off the agent by using the interactions.executeAsync function, setting its type to conversation
.
const task = `
Generate three lease agreement documents for commercial office space, each tailored to different specifications:
- A basic, cost-effective option suitable for approximately eight workstations.
- A mid-range option accommodating approximately twenty workstations, three meeting rooms, and two individual phone booths.
- A premium option located on the fortieth floor or above in an office building, designed to accommodate approximately fifty workstations, ten meeting rooms, and ten individual phone booths.
A lease agreement document must have the following metadata properties:
- space size in square feet
- term length
- monthly cost
- deposit amount
- state
- city
- address
- property manager
If a document type named “Lease Agreement” doesn’t already exit, create it with properties listed above
Subsequently, these documents should be organized and stored within a collection named "Office Leases."
`;
const run = await vertesia.interactions.executeAsync({
type: "conversation",
interaction: "MultipurposeAgent",
prompt_data: {
task: task
},
interactive: true,
});
Streaming Agent Messages
You can then stream messages from the agent using the streamMessages
function. This function needs the runId that was returned in the previous step.
await vertesia.workflows.streamMessages(run.runId, (item) => {
const { type, message } = item;
const date = new Date(item.timestamp);
console.log(`${date.toLocaleString()} - ${type}:\n${message}\n`);
});
The streamMessages
function automatically stops when a message of type AgentMessageType.COMPLETE
is received. This signals that the agent's current task is finished.
Sending Signals to the Agent
Finally, to send a message or "signal" to the agent, use the sendSignal function.
await vertesia.workflows.sendSignal(run.workflowId, run.runId, "UserInput", {
message: "create a spreadsheet with the agreement properties and add it to the collection",
});
Further Exploration
A simple agent cli example is available on GitHub