AutoGen Extensions

0.7.5 · active · verified Mon Apr 13

AutoGen extensions library, version 0.7.5. This library provides additional tools and functionalities to enhance the capabilities of the Microsoft AutoGen multi-agent framework, such as advanced web search, persistent agent memory, and improved communication patterns. It follows the release cadence of its parent `autogen` library, with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate the `WebSearchTool` from `autogen-ext` into an AutoGen multi-agent conversation. It requires setting `OPENAI_API_KEY` and `SERPER_API_KEY` (e.g., from Serper.dev) as environment variables or directly in the code.

import os
import autogen
from autogen_extensions.web_search import WebSearchTool

# Configure LLM (replace with your actual configuration)
llm_config = {
    "model": "gpt-4o", # or "gpt-4", "gpt-3.5-turbo"
    "api_key": os.environ.get("OPENAI_API_KEY", "YOUR_OPENAI_API_KEY"),
}

# Create an AssistantAgent
assistant = autogen.AssistantAgent(
    name="assistant",
    llm_config=llm_config,
    is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
)

# Create a UserProxyAgent
user_proxy = autogen.UserProxyAgent(
    name="user_proxy",
    is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
    human_input_mode="NEVER",
    max_consecutive_auto_reply=10,
    llm_config=llm_config, # UserProxyAgent can also use LLM config for self-reflection
    code_execution_config={"work_dir": "autogen_extension_work_dir"},
)

# Register the WebSearchTool (requires SERPER_API_KEY or similar)
# Get an API key from https://serper.dev or a similar search API provider.
web_search_tool = WebSearchTool(config={"api_key": os.environ.get("SERPER_API_KEY", None)})
user_proxy.register_for_execution(web_search_tool)
assistant.register_for_llm(web_search_tool)

# Start the conversation
print("\n--- Initiating chat with WebSearchTool ---\n")
user_proxy.initiate_chat(
    assistant,
    message="What's the capital of France and what are its main attractions? Use web search to find out.",
)
print("\n--- Chat finished ---\n")

view raw JSON →