autogen_core.components.model_context#

class autogen_core.components.model_context.BufferedChatCompletionContext(buffer_size: int, initial_messages: List[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage] | None = None)[source]#

Bases: ChatCompletionContext

A buffered chat completion context that keeps a view of the last n messages, where n is the buffer size. The buffer size is set at initialization.

Parameters:

buffer_size (int) – The size of the buffer.

async add_message(message: SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage) None[source]#

Add a message to the memory.

async clear() None[source]#

Clear the message memory.

async get_messages() List[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage][source]#

Get at most buffer_size recent messages.

load_state(state: Mapping[str, Any]) None[source]#
save_state() Mapping[str, Any][source]#
class autogen_core.components.model_context.ChatCompletionContext(*args, **kwargs)[source]#

Bases: Protocol

A protocol for defining the interface of a chat completion context. A chat completion context lets agents store and retrieve LLM messages. It can be implemented with different recall strategies.

async add_message(message: SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage) None[source]#
async clear() None[source]#
async get_messages() List[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage][source]#
load_state(state: Mapping[str, SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage]) None[source]#
save_state() Mapping[str, SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage][source]#
class autogen_core.components.model_context.HeadAndTailChatCompletionContext(head_size: int, tail_size: int)[source]#

Bases: ChatCompletionContext

A chat completion context that keeps a view of the first n and last m messages, where n is the head size and m is the tail size. The head and tail sizes are set at initialization.

Parameters:
  • head_size (int) – The size of the head.

  • tail_size (int) – The size of the tail.

async add_message(message: SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage) None[source]#

Add a message to the memory.

async clear() None[source]#

Clear the message memory.

async get_messages() List[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage][source]#

Get at most head_size recent messages and tail_size oldest messages.

load_state(state: Mapping[str, Any]) None[source]#
save_state() Mapping[str, Any][source]#