Skip to main content
The conv.history attribute contains a chronological list of UserInput and AgentResponse objects representing the conversation so far.

UserInput

Represents a user turn in the conversation.
for event in conv.history:
    if isinstance(event, UserInput):
        print(f"User said: {event.text}")

Properties

PropertyTypeDescription
textstrThe user’s input text
rolestrAlways "user"

Methods

MethodReturnsDescription
to_dict()dictReturns {"type": "user", "text": "..."}
to_string()strReturns "User: <text>"

AgentResponse

Represents an agent turn in the conversation.
for event in conv.history:
    if isinstance(event, AgentResponse):
        print(f"Agent said: {event.text}")

Properties

PropertyTypeDescription
textstrThe agent’s response text
rolestrAlways "agent"

Methods

MethodReturnsDescription
to_dict()dictReturns {"type": "agent", "text": "..."}
to_string()strReturns "Agent: <text>"

Example: format history for logging

def log_conversation(conv: Conversation):
    for event in conv.history:
        conv.log.info(event.to_string())

Example: get last user message

def get_last_user_input(conv: Conversation) -> str:
    for event in reversed(conv.history):
        if hasattr(event, 'role') and event.role == "user":
            return event.text
    return ""

See also

  • conv object — full list of conversation methods and attributes.