Skip to main content

Messages

note

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.

The Engage Smarter AI Platform delivers conversational AI using the concept of Messages.

There are two different types of messages:

  • Basic messages are objects that contain only minimal information including the content and the message role
  • Full messages are returned by the API and include additional meta data such as id, conversation_id and other metadata.

Pydantic objects

All Message objects are pydantic.BaseModel objects and so all of the usual pydantic validation and methods apply to these objects.

tip

Check out the pydantic documentation for more information.

Basic Messages

Basic messages all inherit from the MessageBasic class within the engagesmarter package.

  • UserMessage represents a message posted by the user
  • AgentMessage represents a message from the agent posted to the user
  • InfoMessage is a type of message that some of the agents may additionally use from the agent which provides metadata. InfoMessages are not intended to be shown to the end user
  • StatusMessage are temporary messages streamed to the user during a long running agent call. These provide status updates to keep the user engaged.
from engagesmarter import AgentMessage, UserMessage

user_message = UserMessage(content="My name is Mary and I have a question")
print(user_message.model_dump_json(indent=2))
    {
"role": "user",
"content": "My name is Mary and I have a question",
"name": null
}
agent_message = AgentMessage(
content="Hi Mary, how can I help you?", agent="pensions-qa-latest"
)
print(agent_message.model_dump_json(indent=2))
    {
"role": "agent",
"content": "Hi Mary, how can I help you?",
"name": null
}

Full Messages

Full messages are represented by the MessageRead class within the engagesmarter package.

These are similar to MessageBasic objects but include id and other metadata which is provided by the API such as identifiers for the conversation_id or the run_id.

import datetime

from engagesmarter import MessageRead
from uuid_extensions import uuid7

agent_message = MessageRead(
id=str(uuid7()),
org_id=str(uuid7()),
conversation_id=str(uuid7()),
run_id=str(uuid7()),
role="agent",
content="Hi Mary, how can I help you?",
created=datetime.datetime.now(),
)
print(agent_message.model_dump_json(indent=2))
    {
"id": "065dbb4a-23f0-7fe0-8000-8e6b45426e5c",
"org_id": "065dbb4a-23f1-7162-8000-25c4be4b5608",
"conversation_id": "065dbb4a-23f1-71b6-8000-3546236e2961",
"run_id": "065dbb4a-23f1-71e8-8000-c32f8c868b65",
"role": "agent",
"content": "Hi Mary, how can I help you?",
"created": "2024-02-25T22:44:02.246372",
"name": null,
"user_id": null
}