ChatHistory#

class council.contexts.ChatHistory(messages: Iterable[ChatMessage] | None = None)[source]#

Bases: MessageList

represents a history of interaction, typically between and user and an agent.

__init__(messages: Iterable[ChatMessage] | None = None)#

initialize a new instance

add_agent_message(message: str, data: Any | None = None)#

adds an agent class:ChatMessage into the history

Parameters:
  • message (str) – a text message

  • data (Any) – Optional data to attach to the message

add_user_message(message: str, data: Any | None = None)#

adds a user ChatMessage into the history

Parameters:
  • message (str) – a text message

  • data (Any) – Optional data to attach to the message

static from_user_message(message: str) ChatHistory[source]#

helpers function that returns a new instance containing one user message

property last_agent_message: ChatMessage | None#

Returns the last message of kind ChatMessageKind.Agent, if any, otherwise None

Return type:

Optional[ChatMessage]

property last_message: ChatMessage | None#

Returns the last message, if any, otherwise None.

Return type:

Optional[ChatMessage]

last_message_from_skill(skill_name: str) ChatMessage | None#

Returns the last message generated by a given skill, if any, otherwise None

Parameters:

skill_name (str) – Name of the skill

Return type:

Optional[ChatMessage]

property last_user_message: ChatMessage | None#

Returns the last message of kind ChatMessageKind.User, if any, otherwise None

Return type:

Optional[ChatMessage]

property messages: Iterable[ChatMessage]#

Iterates over the collection of messages, in the order they appear in the context

Returns:

Iterable[ChatMessage]

property reversed: Iterable[ChatMessage]#

Iterates over the collection of messages, in reversed order

Returns:

Iterable[ChatMessage]

property try_last_agent_message: Option[ChatMessage]#

Returns the last message of kind ChatMessageKind.Agent wrapped into an Option

Returns:

Option[ChatMessage]

property try_last_message: Option[ChatMessage]#

Returns the last message, wrapped into an Option

Return type:

Option[ChatMessage]

try_last_message_from_skill(skill_name: str) Option[ChatMessage]#

Returns the last message generated by a given skill, wrapped into an Option

Parameters:

skill_name (str) – Name of the skill

Return type:

Option[ChatMessage]

property try_last_user_message: Option[ChatMessage]#

Returns the last message of kind ChatMessageKind.User, wrapped into an :class:`Option

Return type:

Option[ChatMessage]