autogen_core.model_context#
- class BufferedChatCompletionContext(buffer_size: int, initial_messages: List[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] | 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: Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]) None [source]#
Add a message to the memory.
- async get_messages() List[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] [source]#
Get at most buffer_size recent messages.
- class 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: Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]) None [source]#
- async get_messages() List[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] [source]#
- load_state(state: Mapping[str, Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]]) None [source]#
- save_state() Mapping[str, Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] [source]#
- class 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.
- async add_message(message: Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]) None [source]#
Add a message to the memory.
- async get_messages() List[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] [source]#
Get at most head_size recent messages and tail_size oldest messages.