thread
Thread management for conversations.
marvin.thread
Thread management for conversations.
This module provides the Thread class for managing conversation context.
Classes
LLMCall
Represents an LLM call.
Methods:
get_messages
Get the messages for this LLM call.get_messages_async
Get the messages for this LLM call.
LLMCallMessages
Message
Thread
Main runtime object for managing conversation context.
Methods:
-
add_agent_message
Add an agent message to the thread.
-
add_agent_message_async
Add an agent message to the thread.
-
add_info_message
Add an info message to the thread.
-
add_info_message_async
Add an info message to the thread.
-
add_messages
Add multiple messages to the thread.
Args: messages: List of messages to add (UserMessage, AssistantMessage, etc.) llm_call_id: Optional ID of the LLM call that generated these messages
-
add_messages_async
Add multiple messages to the thread.
Args: messages: List of messages to add (UserMessage, AssistantMessage, etc.) llm_call_id: Optional ID of the LLM call that generated these messages
-
add_system_message
Add a system message to the thread.
-
add_system_message_async
Add a system message to the thread.
-
add_user_message
Add a user message to the thread.
-
add_user_message_async
Add a user message to the thread.
-
get_current
Get the current thread from context.
-
get_llm_calls
Get LLM calls for this thread.
Args: before: Only return calls before this timestamp after: Only return calls after this timestamp limit: Maximum number of calls to return
Returns: List of LLM calls in chronological order
-
get_llm_calls_async
Get LLM calls for this thread.
Args: before: Only return calls before this timestamp after: Only return calls after this timestamp limit: Maximum number of calls to return
Returns: List of LLM calls in chronological order
-
get_messages
Get all messages in this thread.
Args: before: Only return messages before this timestamp after: Only return messages after this timestamp limit: Maximum number of messages to return include_system_messages: Whether to include system messages Returns: List of messages in chronological order
-
get_messages_async
Get all messages in this thread.
Args: before: Only return messages before this timestamp after: Only return messages after this timestamp limit: Maximum number of messages to return include_system_messages: Whether to include system messages Returns: List of messages in chronological order
-
get_usage
Get the usage for this thread.
Args: before: Only include usage before this timestamp after: Only include usage after this timestamp
Returns: Total usage for the specified time range
-
get_usage_async
Get the usage for this thread.
Args: before: Only include usage before this timestamp after: Only include usage after this timestamp
Returns: Total usage for the specified time range
Functions
get_current_thread
Get the currently active thread from context.
Returns: The current Thread instance or None if no thread is active.
get_last_thread
Get the last thread that was set as current.
This function is intended for debugging purposes only, and will only work in certain contexts where the last thread is available in memory.
get_thread
Get a thread from the given input.
Args: thread: Thread instance, thread ID, or None
Returns: A Thread instance
Parent Module: marvin