Runs
This page assumes you are already familiar with how get hold of an api_key
and org_id
and how to install the Engage Smarter Python library. If not, turn to the Getting Started tutorial.
Conceptual overview
The Engage Smarter AI Runs
API is a secondary API for interacting with agents on the platform.
Unlike the Conversations
API, the Runs
API is not stateful. This means that it is typically used in the cases where a single response is required from the Agent
.
In order to use the Runs
API, you need to send the full conversation history of messages required in this one run request.
Under the hood, the Runs
API does create a Conversation
for this one run and the conversation_id
is returned as part of the response message. This allows you the option to switch to the Conversations
API for further messages after the initial Run
.
This stateless API setup for the Runs
API is similar in structure to the standard OpenAI API setup which also requires the client to send the full conversation history with every API call.
Pre-requisites
First, we initialise the Engage Smarter Python Client
.
import os
from engagesmarter import Client
api_key = os.getenv("ENGAGE_SMARTER_API_KEY")
org_id = os.getenv("ENGAGE_SMARTER_ORG_ID")
client = Client(
api_key=api_key,
org_id=org_id,
)
Creating a run
from engagesmarter import AgentMessage, UserMessage
AGENT = "pensions-questions-latest"
user_message_1 = UserMessage(content="Hello, can you help me understand pensions?")
agent_message_1 = AgentMessage(content="I can yes. What do you want to know?")
user_message_2 = UserMessage(content="What is a DC pension?")
response = client.runs.chat_with_agent(
messages=[user_message_1, agent_message_1, user_message_2],
agent=AGENT,
)
response
message = response[0]
print(message.model_dump_json(indent=2))