Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why are these changes needed?
✨ Pull Request: Add
MultiChatCompletionContext
andMergeSystemChatCompletionContext
🧩 Overview
I’m currently using AutoGen as the main framework for my project.
However, during development, I encountered several limitations when self-hosting custom LLM models.
⚙️ Motivation
1️⃣ Context Flexibility
Using only a single type of
ChatCompletionContext
within an agent (such asUnboundedChatCompletionContext
orBufferedChatCompletionContext
) is sometimes not sufficient to safely handle different model limitations.While
TokenLimitedChatCompletionContext
can help avoid issues related to exceeding the model’s context window, relying on just one context strategy still lacks flexibility for more complex use cases.To address this, I propose adding
MultiChatCompletionContext
, which allows combining multiple context management strategies dynamically, providing safer and more adaptable message handling for both large and small models.2️⃣ Multi-System Prompt Handling
When using the
memory
feature withinAssistantAgent
, I encountered the following error:This occurs because, even though the model is defined as not supporting
multiple_system_messages
, theAssistantAgent
automatically creates newSystemMessage
entries to store memory information.As a result, the agent unintentionally produces multiple system prompts, which leads to the above error.
Currently, there is no straightforward way to prevent this behavior through configuration.
To solve this, I introduced
MergeSystemChatCompletionContext
, which automatically merges multiple system prompts into a single unified message — ensuring compatibility with models that do not support multiple system messages.🧠 What’s New
Added
MultiChatCompletionContext
Added
MergeSystemChatCompletionContext
ValueError
whenmultiple_system_messages
is disabled🧪 Example Use Case
💬 Summary
This PR aims to improve flexibility and stability for developers using AutoGen with self-hosted or restricted LLMs.
It introduces more control over how contexts and system prompts are managed — reducing the need for users to build complex wrappers and ensuring safer handling of memory and multi-system configurations.
Related issue number
Checks