Skip to main content

Autogen ContextPlus, User defined AutoGen model_context

Reason this release was yanked:

It's just test version

Project description

🧠 Autogen ContextPlus

Modular, customizable, and serializable context engine for AutoGen — enabling structured message summarization, filtering, and rewriting logic with full compatibility.


✨ What is ContextPlus?

autogen-contextplus provides a general-purpose context modifier system for AutoGen’s model_context layer. It supports:

  • ✅ Condition-triggered message summarization
  • ✅ Agent- or function-based message rewriting
  • ✅ Component-based serialization / deserialization
  • ✅ Full support for user-defined logic via AutoGen FunctionTool or custom agents

🔧 Installation

pip install autogen-contextplus

For development and type checking:

pip install -e ".[dev]"

Example

import asyncio
from pprint import pprint
from typing import List
from autogen_core.models import UserMessage, AssistantMessage
from autogen_ext.models.replay import ReplayChatCompletionClient
from autogen_ext.models.anthropic import AnthropicChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_core import CancellationToken 
from autogen_core.model_context import BufferedChatCompletionContext

from autogen_contextplus.conditions import (
    MaxContextPlus
)
from autogen_contextplus.base.types import (
    ModifierFunction,
)
from autogen_contextplus import (
    ContextPlusChatCompletionContext
)
from autogen_core.models import LLMMessage


def buffered_summary(
    messages: List[LLMMessage],
    non_summarized_messages: List[LLMMessage],
) -> List[LLMMessage]:
    """Summarize the last `buffer_count` messages."""
    if len(messages) > 3:
        return messages[-3:]
    return messages


async def main():
    client = ReplayChatCompletionClient(
        chat_completions=[
            "paris",
            "seoul",
            "paris",
            "seoul",
        ]
    )
    
    context = ContextPlusChatCompletionContext(
        modifier_func = buffered_summary,
        modifier_condition = MaxContextPlus(max_messages=2)
    )
    agent = AssistantAgent(
        "helper",
        model_client=client,
        system_message="You are a helpful agent",
        model_context=context
    )
    
    await agent.run(task="What is the capital of France?")
    res = await context.get_messages()
    print(f"[RESULTS] res:")
    pprint(res)
    print(f"[RESULTS] len_context : {len(res)}, context_type: {type(context)}")

    await agent.run(task="What is the capital of Korea?")
    res = await context.get_messages()
    print(f"[RESULTS] res:")
    pprint(res)
    print(f"[RESULTS] len_context : {len(res)}, context_type: {type(context)}")

    print("==========================")

    cancellation_token = CancellationToken() 
    await agent.on_reset(cancellation_token=cancellation_token)
    test = agent.dump_component()
    agent = AssistantAgent.load_component(test)
    context = agent.model_context

    await agent.run(task="What is the capital of France?")
    res = await context.get_messages()
    print(f"[RESULTS] res:")
    pprint(res)
    print(f"[RESULTS] len_context : {len(res)}, context_type: {type(context)}")
    await agent.run(task="What is the capital of Korea?")
    res = await context.get_messages()
    print(f"[RESULTS] res:")
    pprint(res)
    print(f"[RESULTS] len_context : {len(res)}, context_type: {type(context)}")
    
if __name__ == "__main__":
    asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autogen_contextplus-0.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

autogen_contextplus-0.0.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file autogen_contextplus-0.0.1.tar.gz.

File metadata

  • Download URL: autogen_contextplus-0.0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for autogen_contextplus-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5d42606e634652855148d8ca5727b576e0b9d210c5b6e079ea7619bdec8f3adf
MD5 843de3e97b3c70a7ad879039a2959ed6
BLAKE2b-256 380e363c46755f92196e29d63b777a41a4453ae69ae126fb460f4fd3600c77d6

See more details on using hashes here.

File details

Details for the file autogen_contextplus-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for autogen_contextplus-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1d4c350bb122227a922655a598a86555b2e4a538bc0cafd9a6d61099dcb3eef5
MD5 d1f4c9b87763ac3c17925057400f9092
BLAKE2b-256 b185ec9fe3a01733658197a81d8e90beac6e9cc8352d29627763fabbbadc5af2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page