Conversation
Messages#
The Message
class represents a single message in a conversation, with a role and content. The Role
enum defines the possible roles a message can have:
Role.user
: Messages from the userRole.assistant
: Messages from the AI assistantRole.system
: System messages that provide instructions/contextRole.tool
: Messages from tool function calls, this is used internally by the agent to communicate with tools with OpenAI.
A message typically consists of a role and content. The content is the actual message text, while the role indicates who sent the message.
from emp_agents.models import Message, Role
message = Message(role=Role.user, content="hello how are you?")
Creating Conversations#
You can then create a convesation in a few ways. For example, you can construct the conversation history manually:
from emp_agents import AgentBase
from emp_agents.models import Message, Role
agent = AgentBase()
message = Message(role=Role.user, content="hello how are you?")
agent.add_message(message)
message = Message(role=Role.assistant, content="I dont want to help you!")
agent.add_message(message)
message = Message(role=Role.user, content="Why did you say that?")
agent.add_message(message)
response = await agent.run_conversation()
print(agent.conversation_history)
Or you can communicate with the agent using the answer
method, which will automatically add the user's message to the conversation history:
agent = AgentBase()
response = await agent.answer("How are you today?")
print(agent.conversation_history)
The other option is to use the run
method, which will automatically add the user's message to the conversation history, and run it in interactive mode: