Conversation.get_last_message()

Return the most recent message, optionally filtered by role.

Usage

Source

Conversation.get_last_message(role=None)

Useful for quickly inspecting the latest assistant response or checking what the user last said without iterating the full history.

Parameters

role: Optional[str] = None
When provided, returns the last message with this role. When None, returns the last message regardless of role.

Returns

Message | None
The last matching message, or None if the conversation is empty (or no messages match the given role).

Examples

from talk_box.conversation import Conversation

convo = Conversation()
convo.add_user_message("First")
convo.add_assistant_message("Second")
convo.get_last_message().content
'Second'