async def get_conversation_history(
    agent_id: UUID | str,
    context: WorldContext,
) -> str:
    """Gets up to 20 messages from the location. If a message is provided, only gets messages from that agent."""
    if isinstance(agent_id, str):
        agent_id = UUID(agent_id)

    # get all the messages sent at the location witnessed by the agent_id
    (message_events, _) = await context.events_manager.get_events(
        type=EventType.MESSAGE,
        witness_ids=[agent_id],
    )

    messages = [AgentMessage.from_event(event, context) for event in message_events]

    # sort the messages by timestamp, with the newest messages last
    messages.sort(key=lambda x: x.timestamp)

    # limit the messages to 20
    messages = messages[-20:]

    formatted_messages = [
        f"{m.sender_name}: {m.content} @ {m.timestamp}" for m in messages
    ]

    return "\n".join(formatted_messages)
Gets up to 20 messages from the location. If a message is provided, only gets messages from that agent.
src/agent/message.py