AutoGen Extensions
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
- breaking `autogen-ext` is tightly coupled with specific versions of `autogen`. The current `autogen-ext` (v0.7.5) has a dependency constraint `autogen~=0.2.0` (i.e., `>=0.2.0, <0.3.0`). Using `autogen-ext` with newer versions of `autogen` (e.g., `autogen>=0.3.0` or even later `0.2.x` sub-versions that introduced breaking changes) will likely lead to runtime errors due to API changes in `autogen`.
- gotcha Tools like `WebSearchTool` often require their own dedicated API keys (e.g., `SERPER_API_KEY` for Serper API), separate from the `OPENAI_API_KEY` used for the LLM itself. Misconfiguring or omitting the tool-specific API key will result in search operations failing silently or with generic errors.
Install
-
pip install autogen-ext
Imports
- WebSearchTool
from autogen_extensions.web_search import WebSearchTool
- AgentMemory
from autogen_extensions.agent_memory import AgentMemory
Quickstart
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")