PitchHut logo
Autogen ContextPlus
by songchiyoung
A versatile context engine for custom AutoGen workflows.
Pitch

Autogen ContextPlus enhances the AutoGen framework with a powerful, user-defined context modifier system. It enables structured message summarization, filtering, and rewriting, offering full control over context in multi-agent workflows. Ideal for those seeking to customize their LLM interactions seamlessly.

Description

Autogen ContextPlus is a highly customizable module designed to enhance context management in AutoGen's multi-agent workflows. This framework enables users to implement structured message summarization, filtering, and rewriting seamlessly, providing a powerful solution for developers looking to customize context handling in language model interactions.

Key Features

  • Condition-triggered Summarization: Automatically summarize messages based on defined conditions.
  • Message Rewriting: Tailor messages using agent or function-based logic.
  • Serialization and Deserialization: Manage context data effectively with component-based techniques.
  • User-defined Logic Support: Extend functionality using Function or Custom Agent implementations. (contextplus exclusive)

Example Usage

Implementing a buffered message summarization can be easily accomplished using the following code snippet:

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 MaxMessageCondition
from autogen_contextplus import ContextPlusChatCompletionContext
from autogen_core.models import LLMMessage

# Buffer summary function to limit messages

def buffered_summary(messages: List[LLMMessage], non_summarized_messages: List[LLMMessage]) -> List[LLMMessage]:
    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=MaxMessageCondition(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()
    pprint(res)

if __name__ == "__main__":
    asyncio.run(main())

This example demonstrates how to configure an Assistant Agent with customized context handling, allowing for efficient management of conversation history and generating precise responses based on user-defined logic. With Autogen ContextPlus, developers have the tools necessary to enhance their AutoGen implementations and tailor context management to meet specific needs.

0 comments

No comments yet.

Sign in to be the first to comment.