Skip to content

A programming framework for agentic AI

Add script to automatically generate API documentation and remove hard-coded RST files; fix API docs (#6755)

Eric Zhu89841b6aaf08
diff --git a/python/packages/autogen-core/.gitignore b/python/packages/autogen-core/.gitignore
index 06f543fa9..6f1f50b31 100644
--- a/python/packages/autogen-core/.gitignore
+++ b/python/packages/autogen-core/.gitignore
@@ -171,3 +171,6 @@ docs/**/jupyter_execute
# Temporary files
tmp_code_*.py
+
+# Reference files
+docs/src/reference
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/conf.py b/python/packages/autogen-core/docs/src/conf.py
index ff5608a17..26816481e 100644
--- a/python/packages/autogen-core/docs/src/conf.py
+++ b/python/packages/autogen-core/docs/src/conf.py
@@ -8,6 +8,7 @@ from typing import Any, Dict
from pathlib import Path
import sys
import os
+import subprocess
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
@@ -182,6 +183,35 @@ rediraffe_redirects = {
}
+def generate_api_docs() -> None:
+ """Generate API documentation before building."""
+ script_path = Path(__file__).parent / "generate_api_toc.py"
+ if script_path.exists():
+ print("🔄 Generating API documentation...")
+ try:
+ result = subprocess.run(
+ [sys.executable, str(script_path)],
+ cwd=script_path.parent,
+ capture_output=True,
+ text=True,
+ check=True
+ )
+ print("✅ API documentation generated successfully")
+ # Print the output for visibility
+ if result.stdout:
+ for line in result.stdout.strip().split('\n'):
+ print(f" {line}")
+ except subprocess.CalledProcessError as e:
+ print(f"❌ Failed to generate API documentation: {e}")
+ if e.stdout:
+ print(f"stdout: {e.stdout}")
+ if e.stderr:
+ print(f"stderr: {e.stderr}")
+ # Don't fail the build, just warn
+ else:
+ print(f"⚠️ API documentation generator not found at {script_path}")
+
+
def setup_to_main(
app: Sphinx, pagename: str, templatename: str, context, doctree
) -> None:
@@ -211,6 +241,9 @@ def setup(app: Sphinx) -> Dict[str, Any]:
Returns:
the 2 parallel parameters set to ``True``.
"""
+ # Generate API documentation before building
+ app.connect("builder-inited", lambda app: generate_api_docs())
+
app.connect("html-page-context", setup_to_main)
# Adding here so it is inline and not in a separate file.
diff --git a/python/packages/autogen-core/docs/src/generate_api_toc.py b/python/packages/autogen-core/docs/src/generate_api_toc.py
new file mode 100644
index 000000000..caf7532f7
--- /dev/null
+++ b/python/packages/autogen-core/docs/src/generate_api_toc.py
@@ -0,0 +1,305 @@
+#!/usr/bin/env python3
+"""
+Script to automatically generate the API reference table of contents for AutoGen.
+
+This script scans all packages and their modules to generate the toctree entries
+for the API documentation index.md file.
+"""
+
+import os
+from pathlib import Path
+from typing import List, Dict, Set
+import re
+
+
+# Constants for package filtering and organization
+DOCUMENTED_PACKAGES = ["autogen_core", "autogen_agentchat", "autogen_ext"]
+
+PACKAGE_SECTIONS = {
+ "autogen_agentchat": "AutoGen AgentChat",
+ "autogen_core": "AutoGen Core",
+ "autogen_ext": "AutoGen Extensions"
+}
+
+# Exclusion patterns for submodules that are re-exported by parent modules
+EXCLUSION_PATTERNS = [
+ # task_centric_memory re-exports from memory_controller and utils
+ (r'^autogen_ext\.experimental\.task_centric_memory\.memory_controller$',
+ 'autogen_ext.experimental.task_centric_memory'),
+ # utils package re-exports from utils.apprentice and other utils submodules
+ (r'^autogen_ext\.experimental\.task_centric_memory\.utils\.apprentice$',
+ 'autogen_ext.experimental.task_centric_memory.utils'),
+ (r'^autogen_ext\.experimental\.task_centric_memory\.utils\.chat_completion_client_recorder$',
+ 'autogen_ext.experimental.task_centric_memory.utils'),
+ (r'^autogen_ext\.experimental\.task_centric_memory\.utils\.grader$',
+ 'autogen_ext.experimental.task_centric_memory.utils'),
+ (r'^autogen_ext\.experimental\.task_centric_memory\.utils\.page_logger$',
+ 'autogen_ext.experimental.task_centric_memory.utils'),
+ (r'^autogen_ext\.experimental\.task_centric_memory\.utils\.teachability$',
+ 'autogen_ext.experimental.task_centric_memory.utils'),
+]
+
+
+def is_private_module(module_parts: List[str]) -> bool:
+ """Check if any part of the module path indicates it's a private module."""
+ return any(part.startswith('_') and part != '__init__' for part in module_parts)
+
+
+def find_python_packages() -> List[Path]:
+ """Find documented Python packages in the workspace."""
+ packages_dir = Path(__file__).parent.parent.parent.parent.parent / "packages"
+ python_packages = []
+
+ for package_dir in packages_dir.iterdir():
+ if package_dir.is_dir():
+ # Check if this package is in our documented packages list
+ package_name = package_dir.name.replace("-", "_")
+ if package_name in DOCUMENTED_PACKAGES:
+ src_dir = package_dir / "src"
+ if src_dir.exists():
+ python_packages.append(src_dir)
+
+ return python_packages
+
+
+def get_module_hierarchy(package_root: Path) -> Dict[str, Set[str]]:
+ """Get the module hierarchy for a package, filtering only documented packages."""
+ modules: Dict[str, Set[str]] = {}
+
+ for root, dirs, files in os.walk(package_root):
+ # Skip __pycache__ and hidden directories
+ dirs[:] = [d for d in dirs if not d.startswith('__pycache__') and not d.startswith('.')]
+
+ root_path = Path(root)
+
+ # Process Python files (excluding private modules)
+ for file in files:
+ if file.endswith('.py') and file != '__init__.py' and not file.startswith('_'):
+ file_path = root_path / file
+ module_path = file_path.relative_to(package_root)
+
+ # Convert file path to module name
+ module_parts = list(module_path.parts[:-1]) + [module_path.stem]
+
+ if module_parts:
+ # Skip if any part of the module path is private
+ if is_private_module(module_parts):
+ continue
+
+ module_name = '.'.join(module_parts)
+ package_name = module_parts[0]
+
+ # Only include modules from documented packages
+ if package_name in DOCUMENTED_PACKAGES:
+ if package_name not in modules:
+ modules[package_name] = set()
+
+ modules[package_name].add(module_name)
+
+ # Also check for directories with __init__.py (packages, excluding private)
+ for dir_name in dirs:
+ if not dir_name.startswith('_'): # Skip private directories
+ dir_path = root_path / dir_name
+ if (dir_path / '__init__.py').exists():
+ module_path = dir_path.relative_to(package_root)
+ module_parts = list(module_path.parts)
+
+ if module_parts:
+ # Skip if any part of the module path is private
+ if is_private_module(module_parts):
+ continue
+
+ module_name = '.'.join(module_parts)
+ package_name = module_parts[0]
+
+ # Only include modules from documented packages
+ if package_name in DOCUMENTED_PACKAGES:
+ if package_name not in modules:
+ modules[package_name] = set()
+
+ modules[package_name].add(module_name)
+
+ return modules
+
+
+def should_exclude_submodule(module_name: str, all_modules: Set[str]) -> bool:
+ """Check if a submodule should be excluded to avoid duplicate documentation."""
+ for pattern, parent_module in EXCLUSION_PATTERNS:
+ if re.match(pattern, module_name) and parent_module in all_modules:
+ return True
+
+ return False
+
+
+def clean_rst_files(reference_dir: Path) -> None:
+ """Clean existing RST files to ensure fresh generation."""
+ python_ref_dir = reference_dir / "python"
+ if python_ref_dir.exists():
+ print("🧹 Cleaning existing .rst files...")
+ rst_files = list(python_ref_dir.glob("*.rst"))
+ for rst_file in rst_files:
+ rst_file.unlink()
+ print(f" Removed {len(rst_files)} existing .rst files")
+
+
+def generate_rst_files(package_roots: List[Path], reference_dir: Path) -> Set[str]:
+ """Generate .rst files for all modules found in the packages."""
+ python_ref_dir = reference_dir / "python"
+ python_ref_dir.mkdir(exist_ok=True, parents=True)
+
+ # Clean existing RST files first
+ clean_rst_files(reference_dir)
+
+ generated_files = set()
+ all_module_names = set()
+
+ # First pass: collect all module names
+ for package_root in package_roots:
+ modules = get_module_hierarchy(package_root)
+ for package_name, module_set in modules.items():
+ all_module_names.update(module_set)
+
+ # Second pass: generate RST files, excluding problematic submodules
+ for package_root in package_roots:
+ modules = get_module_hierarchy(package_root)
+
+ for package_name, module_set in modules.items():
+ for module_name in module_set:
+ # Skip modules that would cause duplicate documentation
+ if should_exclude_submodule(module_name, all_module_names):
+ print(f" Skipping {module_name} (re-exported by parent)")
+ continue
+
+ # Use the proper RST filename pattern (keep dots for submodules)
+ rst_filename = module_name + '.rst'
+ rst_path = python_ref_dir / rst_filename
+
+ # Generate .rst content with proper title formatting
+ # Title should use dots as separators, but escape underscores for RST
+ title = module_name.replace('_', r'\_')
+ underline = '=' * len(title) # Underline matches title length
+
+ rst_content = f"""{title}
+{underline}
+
+.. automodule:: {module_name}
+ :members:
+ :undoc-members:
+ :show-inheritance:
+ :member-order: bysource
+"""
+
+ # Write the .rst file
+ with open(rst_path, 'w') as f:
+ f.write(rst_content)
+
+ generated_files.add(module_name)
+
+ return generated_files
+
+
+def generate_toctree_from_rst_files(reference_dir: Path) -> Dict[str, List[str]]:
+ """Generate toctree entries directly from existing .rst files."""
+ # Initialize sections using constants
+ toctree_sections: Dict[str, List[str]] = {section: [] for section in PACKAGE_SECTIONS.values()}
+
+ python_ref_dir = reference_dir / "python"
+ if not python_ref_dir.exists():
+ return toctree_sections
+
+ # Collect modules by package using constants
+ modules_by_section: Dict[str, List[str]] = {section: [] for section in PACKAGE_SECTIONS.values()}
+
+ # Get all .rst files and organize them by package
+ for rst_file in python_ref_dir.glob("*.rst"):
+ module_name = rst_file.stem # filename without .rst extension
+
+ # Find which documented package this module belongs to
+ for package_prefix, section_name in PACKAGE_SECTIONS.items():
+ if module_name.startswith(package_prefix):
+ modules_by_section[section_name].append(module_name)
+ break
+
+ # Sort modules so parent modules come before child modules
+ def sort_modules_hierarchically(modules):
+ """Sort modules so that parent modules come before child modules."""
+ return sorted(modules, key=lambda x: (x.count('.'), x))
+
+ # Apply hierarchical sorting and convert to rst paths
+ for section_name, modules in modules_by_section.items():
+ toctree_sections[section_name] = [f"python/{m}" for m in sort_modules_hierarchically(modules)]
+
+ return toctree_sections
+
+
+def generate_index_content(toctree_sections: Dict[str, List[str]]) -> str:
+ """Generate the complete index.md content with automatic toctrees."""
+
+ content = """---
+myst:
+ html_meta:
+ "description lang=en": |
+ AutoGen is a community-driven project. Learn how to get involved, contribute, and connect with the community.
+---
+
+# API Reference
+
+"""
+
+ for section_name, modules in toctree_sections.items():
+ if modules: # Only add section if it has modules
+ content += f"""```{{toctree}}
+:caption: {section_name}
+:maxdepth: 2
+
+"""
+ for module in modules:
+ content += f"{module}\n"
+ content += "```\n\n"
+
+ return content
+
+
+def main():
+ """Main function to generate the API documentation index."""
+ script_dir = Path(__file__).parent
+ reference_dir = script_dir / "reference"
+ index_file = reference_dir / "index.md"
+
+ print("🔍 Scanning Python packages...")
+ package_roots = find_python_packages()
+
+ all_modules = {}
+ for package_root in package_roots:
+ print(f" 📦 Scanning {package_root}")
+ modules = get_module_hierarchy(package_root)
+ all_modules.update(modules)
+
+ print("🏗️ Generating .rst files for all discovered modules...")
+ generated_files = generate_rst_files(package_roots, reference_dir)
+ print(f" Generated {len(generated_files)} .rst files")
+
+ print("📝 Generating toctree entries from .rst files...")
+ toctree_sections = generate_toctree_from_rst_files(reference_dir)
+
+ for section, modules in toctree_sections.items():
+ print(f" {section}: {len(modules)} modules")
+
+ print("✍️ Writing index.md...")
+ content = generate_index_content(toctree_sections)
+
+ with open(index_file, 'w') as f:
+ f.write(content)
+
+ print(f"✅ Generated API documentation index at {index_file}")
+ print("\n📖 Summary:")
+ total_modules = sum(len(modules) for modules in toctree_sections.values())
+ print(f" Total modules documented: {total_modules}")
+
+ for section, modules in toctree_sections.items():
+ if modules:
+ print(f" {section}: {len(modules)} modules")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/python/packages/autogen-core/docs/src/reference/index.md b/python/packages/autogen-core/docs/src/reference/index.md
deleted file mode 100644
index cd2d18f60..000000000
--- a/python/packages/autogen-core/docs/src/reference/index.md
+++ /dev/null
@@ -1,79 +0,0 @@
----
-myst:
- html_meta:
- "description lang=en": |
- AutoGen is a community-driven project. Learn how to get involved, contribute, and connect with the community.
----
-
-# API Reference
-
-```{toctree}
-:caption: AutoGen AgentChat
-:maxdepth: 2
-
-python/autogen_agentchat
-python/autogen_agentchat.messages
-python/autogen_agentchat.agents
-python/autogen_agentchat.tools
-python/autogen_agentchat.teams
-python/autogen_agentchat.base
-python/autogen_agentchat.conditions
-python/autogen_agentchat.ui
-python/autogen_agentchat.state
-```
-
-```{toctree}
-:caption: AutoGen Core
-:maxdepth: 2
-
-python/autogen_core
-python/autogen_core.code_executor
-python/autogen_core.models
-python/autogen_core.model_context
-python/autogen_core.tools
-python/autogen_core.tool_agent
-python/autogen_core.memory
-python/autogen_core.exceptions
-python/autogen_core.logging
-```
-
-```{toctree}
-:caption: AutoGen Extensions
-:maxdepth: 2
-
-python/autogen_ext.agents.azure
-python/autogen_ext.agents.magentic_one
-python/autogen_ext.agents.openai
-python/autogen_ext.agents.web_surfer
-python/autogen_ext.agents.file_surfer
-python/autogen_ext.agents.video_surfer
-python/autogen_ext.agents.video_surfer.tools
-python/autogen_ext.teams.magentic_one
-python/autogen_ext.models.cache
-python/autogen_ext.models.openai
-python/autogen_ext.models.replay
-python/autogen_ext.models.azure
-python/autogen_ext.models.anthropic
-python/autogen_ext.models.semantic_kernel
-python/autogen_ext.models.ollama
-python/autogen_ext.models.llama_cpp
-python/autogen_ext.tools.azure
-python/autogen_ext.tools.code_execution
-python/autogen_ext.tools.graphrag
-python/autogen_ext.tools.http
-python/autogen_ext.tools.langchain
-python/autogen_ext.tools.mcp
-python/autogen_ext.memory.canvas
-python/autogen_ext.tools.semantic_kernel
-python/autogen_ext.code_executors.local
-python/autogen_ext.code_executors.docker
-python/autogen_ext.code_executors.jupyter
-python/autogen_ext.code_executors.docker_jupyter
-python/autogen_ext.code_executors.azure
-python/autogen_ext.cache_store.diskcache
-python/autogen_ext.cache_store.redis
-python/autogen_ext.runtimes.grpc
-python/autogen_ext.auth.azure
-python/autogen_ext.experimental.task_centric_memory
-python/autogen_ext.experimental.task_centric_memory.utils
-```
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.agents.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.agents.rst
deleted file mode 100644
index 4ccb296c4..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.agents.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_agentchat.agents
-=========================
-
-
-.. automodule:: autogen_agentchat.agents
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.base.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.base.rst
deleted file mode 100644
index c973f560a..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.base.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_agentchat.base
-=======================
-
-
-.. automodule:: autogen_agentchat.base
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.conditions.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.conditions.rst
deleted file mode 100644
index 09db1eeb4..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.conditions.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_agentchat.conditions
-=============================
-
-
-.. automodule:: autogen_agentchat.conditions
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.messages.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.messages.rst
deleted file mode 100644
index b1dcf2932..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.messages.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-autogen\_agentchat.messages
-===========================
-
-.. automodule:: autogen_agentchat.messages
- :members:
- :undoc-members:
- :show-inheritance:
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.rst
deleted file mode 100644
index bf5b69736..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-autogen\_agentchat
-==================
-
-.. automodule:: autogen_agentchat
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.state.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.state.rst
deleted file mode 100644
index 72127b8ba..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.state.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_agentchat.state
-========================
-
-
-.. automodule:: autogen_agentchat.state
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.teams.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.teams.rst
deleted file mode 100644
index cfa76107e..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.teams.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_agentchat.teams
-========================
-
-
-.. automodule:: autogen_agentchat.teams
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.tools.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.tools.rst
deleted file mode 100644
index 3a7f5f125..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.tools.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_agentchat.tools
-========================
-
-
-.. automodule:: autogen_agentchat.tools
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.ui.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.ui.rst
deleted file mode 100644
index 7d5db1029..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_agentchat.ui.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_agentchat.ui
-=====================
-
-
-.. automodule:: autogen_agentchat.ui
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_core.code_executor.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_core.code_executor.rst
deleted file mode 100644
index f05bdd68d..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_core.code_executor.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-autogen\_core.code_executor
-===========================
-
-.. automodule:: autogen_core.code_executor
- :members:
- :undoc-members:
- :show-inheritance:
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_core.exceptions.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_core.exceptions.rst
deleted file mode 100644
index 5ca415524..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_core.exceptions.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-autogen\_core.exceptions
-========================
-
-.. automodule:: autogen_core.exceptions
- :members:
- :undoc-members:
- :show-inheritance:
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_core.logging.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_core.logging.rst
deleted file mode 100644
index 6caaf7475..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_core.logging.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-autogen\_core.logging
-=====================
-
-.. automodule:: autogen_core.logging
- :members:
- :undoc-members:
- :show-inheritance:
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_core.memory.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_core.memory.rst
deleted file mode 100644
index c2f7f446c..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_core.memory.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_core.memory
-====================
-
-
-.. automodule:: autogen_core.memory
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_core.model_context.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_core.model_context.rst
deleted file mode 100644
index e8beee6b2..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_core.model_context.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_core.model\_context
-=======================================
-
-
-.. automodule:: autogen_core.model_context
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_core.models.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_core.models.rst
deleted file mode 100644
index 9a2b06cfd..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_core.models.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_core.models
-===============================
-
-
-.. automodule:: autogen_core.models
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_core.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_core.rst
deleted file mode 100644
index c3f7bded9..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_core.rst
+++ /dev/null
@@ -1,11 +0,0 @@
-autogen\_core
-=============
-
-.. automodule:: autogen_core
- :members:
- :undoc-members:
- :show-inheritance:
- :member-order: bysource
-
-.. For some reason the following isn't picked up by automodule above
-.. autoclass:: autogen_core.ComponentType
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_core.tool_agent.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_core.tool_agent.rst
deleted file mode 100644
index 18e8e8a7d..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_core.tool_agent.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_core.tool\_agent
-====================================
-
-
-.. automodule:: autogen_core.tool_agent
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_core.tools.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_core.tools.rst
deleted file mode 100644
index c78d6a750..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_core.tools.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_core.tools
-===================
-
-
-.. automodule:: autogen_core.tools
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.azure.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.azure.rst
deleted file mode 100644
index 6eca2e9a7..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.azure.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.agents.azure
-================================
-
-
-.. automodule:: autogen_ext.agents.azure
- :members:
- :undoc-members:
- :show-inheritance:
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.file_surfer.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.file_surfer.rst
deleted file mode 100644
index fb83308ce..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.file_surfer.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.agents.file\_surfer
-================================
-
-
-.. automodule:: autogen_ext.agents.file_surfer
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.magentic_one.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.magentic_one.rst
deleted file mode 100644
index 93839ba88..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.magentic_one.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.agents.magentic\_one
-=================================
-
-
-.. automodule:: autogen_ext.agents.magentic_one
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.openai.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.openai.rst
deleted file mode 100644
index e3d068d71..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.openai.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.agents.openai
-================================
-
-
-.. automodule:: autogen_ext.agents.openai
- :members:
- :undoc-members:
- :show-inheritance:
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.video_surfer.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.video_surfer.rst
deleted file mode 100644
index a171573c2..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.video_surfer.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-autogen\_ext.agents.video\_surfer
-=================================
-
-.. automodule:: autogen_ext.agents.video_surfer
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.video_surfer.tools.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.video_surfer.tools.rst
deleted file mode 100644
index 1fe80764b..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.video_surfer.tools.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-autogen\_ext.agents.video\_surfer.tools
-=======================================
-
-.. automodule:: autogen_ext.agents.video_surfer.tools
- :members:
- :undoc-members:
- :show-inheritance:
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.web_surfer.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.web_surfer.rst
deleted file mode 100644
index 8ae0502ae..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.agents.web_surfer.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.agents.web\_surfer
-===============================
-
-
-.. automodule:: autogen_ext.agents.web_surfer
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.auth.azure.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.auth.azure.rst
deleted file mode 100644
index 7d2739826..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.auth.azure.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.auth.azure
-=======================
-
-
-.. automodule:: autogen_ext.auth.azure
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.cache_store.diskcache.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.cache_store.diskcache.rst
deleted file mode 100644
index 5fbc4c8b3..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.cache_store.diskcache.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.cache_store.diskcache
-==================================
-
-
-.. automodule:: autogen_ext.cache_store.diskcache
- :members:
- :undoc-members:
- :show-inheritance:
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.cache_store.redis.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.cache_store.redis.rst
deleted file mode 100644
index fab1b46d5..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.cache_store.redis.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.cache_store.redis
-==============================
-
-
-.. automodule:: autogen_ext.cache_store.redis
- :members:
- :undoc-members:
- :show-inheritance:
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.azure.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.azure.rst
deleted file mode 100644
index 08fd3bdcf..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.azure.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.code\_executors.azure
-==================================
-
-
-.. automodule:: autogen_ext.code_executors.azure
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.docker.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.docker.rst
deleted file mode 100644
index b4a9a287a..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.docker.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.code\_executors.docker
-===================================
-
-
-.. automodule:: autogen_ext.code_executors.docker
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.docker_jupyter.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.docker_jupyter.rst
deleted file mode 100644
index 003a5b987..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.docker_jupyter.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.code\_executors.docker_jupyter
-===========================================
-
-
-.. automodule:: autogen_ext.code_executors.docker_jupyter
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.jupyter.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.jupyter.rst
deleted file mode 100644
index 6b44c137f..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.jupyter.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.code\_executors.jupyter
-====================================
-
-
-.. automodule:: autogen_ext.code_executors.jupyter
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.local.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.local.rst
deleted file mode 100644
index 7fa6f06d6..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.code_executors.local.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.code\_executors.local
-==================================
-
-
-.. automodule:: autogen_ext.code_executors.local
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.experimental.task_centric_memory.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.experimental.task_centric_memory.rst
deleted file mode 100644
index e4bf80c70..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.experimental.task_centric_memory.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.experimental.task\_centric\_memory
-===============================================
-
-
-.. automodule:: autogen_ext.experimental.task_centric_memory
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.experimental.task_centric_memory.utils.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.experimental.task_centric_memory.utils.rst
deleted file mode 100644
index c5f7a58bf..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.experimental.task_centric_memory.utils.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.experimental.task\_centric\_memory.utils
-=====================================================
-
-
-.. automodule:: autogen_ext.experimental.task_centric_memory.utils
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.memory.canvas.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.memory.canvas.rst
deleted file mode 100644
index 1fcd16af5..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.memory.canvas.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.memory.canvas
-==========================
-
-
-.. automodule:: autogen_ext.memory.canvas
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.anthropic.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.anthropic.rst
deleted file mode 100644
index 51d882829..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.anthropic.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.models.anthropic
-=============================
-
-
-.. automodule:: autogen_ext.models.anthropic
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.azure.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.azure.rst
deleted file mode 100644
index 64c16a5a5..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.azure.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.models.azure
-==========================
-
-
-.. automodule:: autogen_ext.models.azure
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.cache.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.cache.rst
deleted file mode 100644
index 48956ace1..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.cache.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.models.cache
-=========================
-
-
-.. automodule:: autogen_ext.models.cache
- :members:
- :undoc-members:
- :show-inheritance:
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.llama_cpp.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.llama_cpp.rst
deleted file mode 100644
index 56470d36d..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.llama_cpp.rst
+++ /dev/null
@@ -1,9 +0,0 @@
-autogen\_ext.models.llama\_cpp
-==============================
-
-
-.. automodule:: autogen_ext.models.llama_cpp
- :members:
- :undoc-members:
- :show-inheritance:
- :member-order: bysource
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.ollama.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.ollama.rst
deleted file mode 100644
index 67076e797..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.ollama.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.models.ollama
-==========================
-
-
-.. automodule:: autogen_ext.models.ollama
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.openai.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.openai.rst
deleted file mode 100644
index b74e4903f..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.openai.rst
+++ /dev/null
@@ -1,9 +0,0 @@
-autogen\_ext.models.openai
-==========================
-
-
-.. automodule:: autogen_ext.models.openai
- :members:
- :undoc-members:
- :show-inheritance:
- :member-order: bysource
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.replay.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.replay.rst
deleted file mode 100644
index 4fc9aefbf..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.replay.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.models.replay
-==========================
-
-
-.. automodule:: autogen_ext.models.replay
- :members:
- :undoc-members:
- :show-inheritance:
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.semantic_kernel.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.semantic_kernel.rst
deleted file mode 100644
index c80d46253..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.models.semantic_kernel.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.models.semantic_kernel
-====================================
-
-
-.. automodule:: autogen_ext.models.semantic_kernel
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.runtimes.grpc.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.runtimes.grpc.rst
deleted file mode 100644
index 6a26dd2c3..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.runtimes.grpc.rst
+++ /dev/null
@@ -1,7 +0,0 @@
-autogen\_ext.runtimes.grpc
-==========================
-
-.. automodule:: autogen_ext.runtimes.grpc
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.teams.magentic_one.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.teams.magentic_one.rst
deleted file mode 100644
index 4e18d60a9..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.teams.magentic_one.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.teams.magentic\_one
-=================================
-
-
-.. automodule:: autogen_ext.teams.magentic_one
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.azure.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.azure.rst
deleted file mode 100644
index 149dc578a..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.azure.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.tools.azure
-========================
-
-.. automodule:: autogen_ext.tools.azure
- :members:
- :undoc-members:
- :show-inheritance:
-
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.code_execution.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.code_execution.rst
deleted file mode 100644
index 18dce6613..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.code_execution.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.tools.code\_execution
-==================================
-
-
-.. automodule:: autogen_ext.tools.code_execution
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.graphrag.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.graphrag.rst
deleted file mode 100644
index d15d486b0..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.graphrag.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.tools.graphrag
-===========================
-
-
-.. automodule:: autogen_ext.tools.graphrag
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.http.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.http.rst
deleted file mode 100644
index 7450fb9bf..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.http.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.tools.http
-=======================
-
-
-.. automodule:: autogen_ext.tools.http
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.langchain.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.langchain.rst
deleted file mode 100644
index 416a3b550..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.langchain.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.tools.langchain
-============================
-
-
-.. automodule:: autogen_ext.tools.langchain
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.mcp.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.mcp.rst
deleted file mode 100644
index 3c7ffd908..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.mcp.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-autogen\_ext.tools.mcp
-======================
-
-
-.. automodule:: autogen_ext.tools.mcp
- :members:
- :undoc-members:
- :show-inheritance:
diff --git a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.semantic_kernel.rst b/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.semantic_kernel.rst
deleted file mode 100644
index b3675fc1e..000000000
--- a/python/packages/autogen-core/docs/src/reference/python/autogen_ext.tools.semantic_kernel.rst
+++ /dev/null
@@ -1,10 +0,0 @@
-autogen\_ext.tools.semantic_kernel
-===================================
-
-
-.. automodule:: autogen_ext.tools.semantic_kernel
- :members:
- :undoc-members:
- :show-inheritance:
-
-
diff --git a/python/packages/autogen-core/src/autogen_core/utils/_json_to_pydantic.py b/python/packages/autogen-core/src/autogen_core/utils/_json_to_pydantic.py
index 082d950a1..1c6e0411d 100644
--- a/python/packages/autogen-core/src/autogen_core/utils/_json_to_pydantic.py
+++ b/python/packages/autogen-core/src/autogen_core/utils/_json_to_pydantic.py
@@ -366,7 +366,7 @@ def schema_to_pydantic_model(schema: Dict[str, Any], model_name: str = "Generate
.. code-block:: python
- from json_schema_to_pydantic import schema_to_pydantic_model
+ from autogen_core.utils import schema_to_pydantic_model
# Example 1: Simple user model
schema = {
@@ -385,6 +385,8 @@ def schema_to_pydantic_model(schema: Dict[str, Any], model_name: str = "Generate
.. code-block:: python
+ from autogen_core.utils import schema_to_pydantic_model
+
# Example 2: Nested model
schema = {
"title": "BlogPost",
@@ -403,8 +405,11 @@ def schema_to_pydantic_model(schema: Dict[str, Any], model_name: str = "Generate
BlogPost = schema_to_pydantic_model(schema)
+
.. code-block:: python
+ from autogen_core.utils import schema_to_pydantic_model
+
# Example 3: allOf merging with $refs
schema = {
"title": "EmployeeWithDepartment",
@@ -427,6 +432,8 @@ def schema_to_pydantic_model(schema: Dict[str, Any], model_name: str = "Generate
.. code-block:: python
+ from autogen_core.utils import schema_to_pydantic_model
+
# Example 4: Self-referencing (recursive) model
schema = {
"title": "Category",
diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/duckduckgo_search/__init__.py b/python/packages/autogen-ext/src/autogen_ext/agents/duckduckgo_search/__init__.py
new file mode 100644
index 000000000..7e18d619f
--- /dev/null
+++ b/python/packages/autogen-ext/src/autogen_ext/agents/duckduckgo_search/__init__.py
@@ -0,0 +1,5 @@
+from ._duckduckgo_agent import DuckDuckGoSearchAgent
+
+__all__ = [
+ "DuckDuckGoSearchAgent",
+]
diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/duckduckgo_search/_duckduckgo_agent.py b/python/packages/autogen-ext/src/autogen_ext/agents/duckduckgo_search/_duckduckgo_agent.py
index cc182fe2b..1dac92a23 100644
--- a/python/packages/autogen-ext/src/autogen_ext/agents/duckduckgo_search/_duckduckgo_agent.py
+++ b/python/packages/autogen-ext/src/autogen_ext/agents/duckduckgo_search/_duckduckgo_agent.py
@@ -3,7 +3,7 @@ from typing import Any, Optional
from autogen_agentchat.agents import AssistantAgent
from autogen_core.models import ChatCompletionClient
-from autogen_ext.tools.web_search.duckduckgo._duckduckgo_search import DuckDuckGoSearchTool
+from autogen_ext.tools.duckduckgo_search import DuckDuckGoSearchTool
class DuckDuckGoSearchAgent(AssistantAgent):
@@ -20,21 +20,27 @@ class DuckDuckGoSearchAgent(AssistantAgent):
Example:
.. code-block:: python
+ import asyncio
from autogen_ext.agents.duckduckgo_search import DuckDuckGoSearchAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
- # Create a model client
- model_client = OpenAIChatCompletionClient(model="gpt-4")
- # Create a DuckDuckGo search agent
- search_agent = DuckDuckGoSearchAgent(
- name="researcher",
- model_client=model_client,
- )
+ async def main() -> None:
+ # Create a model client
+ model_client = OpenAIChatCompletionClient(model="gpt-4")
- # Use the agent
- result = await search_agent.run(task="What are the latest developments in AI?")
- print(result.messages[-1].content)
+ # Create a DuckDuckGo search agent
+ search_agent = DuckDuckGoSearchAgent(
+ name="researcher",
+ model_client=model_client,
+ )
+
+ # Use the agent
+ result = await search_agent.run(task="What are the latest developments in AI?")
+ print(result.messages[-1].content) # type: ignore
+
+
+ asyncio.run(main())
"""
DEFAULT_DESCRIPTION = "A research assistant that uses DuckDuckGo to find and analyze information from the web."
diff --git a/python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chroma_configs.py b/python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chroma_configs.py
index 77e084104..3f30caacd 100644
--- a/python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chroma_configs.py
+++ b/python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chroma_configs.py
@@ -33,7 +33,9 @@ class SentenceTransformerEmbeddingFunctionConfig(BaseModel):
Example:
.. code-block:: python
- config = SentenceTransformerEmbeddingFunctionConfig(model_name="paraphrase-multilingual-mpnet-base-v2")
+ from autogen_ext.memory.chromadb import SentenceTransformerEmbeddingFunctionConfig
+
+ _ = SentenceTransformerEmbeddingFunctionConfig(model_name="paraphrase-multilingual-mpnet-base-v2")
"""
function_type: Literal["sentence_transformer"] = "sentence_transformer"
@@ -55,7 +57,9 @@ class OpenAIEmbeddingFunctionConfig(BaseModel):
Example:
.. code-block:: python
- config = OpenAIEmbeddingFunctionConfig(api_key="sk-...", model_name="text-embedding-3-small")
+ from autogen_ext.memory.chromadb import OpenAIEmbeddingFunctionConfig
+
+ _ = OpenAIEmbeddingFunctionConfig(api_key="sk-...", model_name="text-embedding-3-small")
"""
function_type: Literal["openai"] = "openai"
@@ -77,21 +81,6 @@ class CustomEmbeddingFunctionConfig(BaseModel):
Args:
function (Callable): Function that returns a ChromaDB-compatible embedding function.
params (Dict[str, Any]): Parameters to pass to the function.
-
- Example:
- .. code-block:: python
-
- def create_my_embedder(param1="default"):
- # Return a ChromaDB-compatible embedding function
- class MyCustomEmbeddingFunction(EmbeddingFunction):
- def __call__(self, input: Documents) -> Embeddings:
- # Custom embedding logic here
- return embeddings
-
- return MyCustomEmbeddingFunction(param1)
-
-
- config = CustomEmbeddingFunctionConfig(function=create_my_embedder, params={"param1": "custom_value"})
"""
function_type: Literal["custom"] = "custom"
diff --git a/python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chromadb.py b/python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chromadb.py
index ac3f531eb..6664b4044 100644
--- a/python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chromadb.py
+++ b/python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chromadb.py
@@ -45,25 +45,28 @@ class ChromaDBVectorMemory(Memory, Component[ChromaDBVectorMemoryConfig]):
For advanced use cases requiring specialized formatting of retrieved content, users should extend
this class and override the `update_context()` method.
- .. note::
+ This implementation requires the ChromaDB extra to be installed. Install with:
- This implementation requires the ChromaDB extra to be installed. Install with:
- `pip install autogen-ext[chromadb]`
+ .. code-block:: bash
+
+ pip install "autogen-ext[chromadb]"
Args:
config (ChromaDBVectorMemoryConfig | None): Configuration for the ChromaDB memory.
If None, defaults to a PersistentChromaDBVectorMemoryConfig with default values.
Two config types are supported:
- - PersistentChromaDBVectorMemoryConfig: For local storage
- - HttpChromaDBVectorMemoryConfig: For connecting to a remote ChromaDB server
+ * PersistentChromaDBVectorMemoryConfig: For local storage
+ * HttpChromaDBVectorMemoryConfig: For connecting to a remote ChromaDB server
Example:
.. code-block:: python
import os
+ import asyncio
from pathlib import Path
from autogen_agentchat.agents import AssistantAgent
+ from autogen_agentchat.ui import Console
from autogen_core.memory import MemoryContent, MemoryMimeType
from autogen_ext.memory.chromadb import (
ChromaDBVectorMemory,
@@ -73,68 +76,107 @@ class ChromaDBVectorMemory(Memory, Component[ChromaDBVectorMemoryConfig]):
)
from autogen_ext.models.openai import OpenAIChatCompletionClient
- # Initialize ChromaDB memory with default embedding function
- memory = ChromaDBVectorMemory(
- config=PersistentChromaDBVectorMemoryConfig(
- collection_name="user_preferences",
- persistence_path=os.path.join(str(Path.home()), ".chromadb_autogen"),
- k=3, # Return top 3 results
- score_threshold=0.5, # Minimum similarity score
+
+ def get_weather(city: str) -> str:
+ return f"The weather in {city} is sunny with a high of 90°F and a low of 70°F."
+
+
+ def fahrenheit_to_celsius(fahrenheit: float) -> float:
+ return (fahrenheit - 32) * 5.0 / 9.0
+
+
+ async def main() -> None:
+ # Use default embedding function
+ default_memory = ChromaDBVectorMemory(
+ config=PersistentChromaDBVectorMemoryConfig(
+ collection_name="user_preferences",
+ persistence_path=os.path.join(str(Path.home()), ".chromadb_autogen"),
+ k=3, # Return top 3 results
+ score_threshold=0.5, # Minimum similarity score
+ )
)
- )
- # Using a custom SentenceTransformer model
- memory_custom_st = ChromaDBVectorMemory(
- config=PersistentChromaDBVectorMemoryConfig(
- collection_name="multilingual_memory",
- persistence_path=os.path.join(str(Path.home()), ".chromadb_autogen"),
- embedding_function_config=SentenceTransformerEmbeddingFunctionConfig(
- model_name="paraphrase-multilingual-mpnet-base-v2"
- ),
+ # Using a custom SentenceTransformer model
+ custom_memory = ChromaDBVectorMemory(
+ config=PersistentChromaDBVectorMemoryConfig(
+ collection_name="multilingual_memory",
+ persistence_path=os.path.join(str(Path.home()), ".chromadb_autogen"),
+ embedding_function_config=SentenceTransformerEmbeddingFunctionConfig(
+ model_name="paraphrase-multilingual-mpnet-base-v2"
+ ),
+ )
)
- )
- # Using OpenAI embeddings
- memory_openai = ChromaDBVectorMemory(
- config=PersistentChromaDBVectorMemoryConfig(
- collection_name="openai_memory",
- persistence_path=os.path.join(str(Path.home()), ".chromadb_autogen"),
- embedding_function_config=OpenAIEmbeddingFunctionConfig(
- api_key="sk-...", model_name="text-embedding-3-small"
- ),
+ # Using OpenAI embeddings
+ openai_memory = ChromaDBVectorMemory(
+ config=PersistentChromaDBVectorMemoryConfig(
+ collection_name="openai_memory",
+ persistence_path=os.path.join(str(Path.home()), ".chromadb_autogen"),
+ embedding_function_config=OpenAIEmbeddingFunctionConfig(
+ api_key=os.environ["OPENAI_API_KEY"], model_name="text-embedding-3-small"
+ ),
+ )
)
- )
- # Add user preferences to memory
- await memory.add(
- MemoryContent(
- content="The user prefers temperatures in Celsius",
- mime_type=MemoryMimeType.TEXT,
- metadata={"category": "preferences", "type": "units"},
+ # Add user preferences to memory
+ await openai_memory.add(
+ MemoryContent(
+ content="The user prefers weather temperatures in Celsius",
+ mime_type=MemoryMimeType.TEXT,
+ metadata={"category": "preferences", "type": "units"},
+ )
)
- )
- # Create assistant agent with ChromaDB memory
- assistant = AssistantAgent(
- name="assistant",
- model_client=OpenAIChatCompletionClient(
- model="gpt-4o",
- ),
- memory=[memory],
- )
+ # Create assistant agent with ChromaDB memory
+ assistant = AssistantAgent(
+ name="assistant",
+ model_client=OpenAIChatCompletionClient(
+ model="gpt-4.1",
+ ),
+ tools=[
+ get_weather,
+ fahrenheit_to_celsius,
+ ],
+ max_tool_iterations=10,
+ memory=[openai_memory],
+ )
+
+ # The memory will automatically retrieve relevant content during conversations
+ await Console(assistant.run_stream(task="What's the temperature in New York?"))
+
+ # Remember to close the memory when finished
+ await default_memory.close()
+ await custom_memory.close()
+ await openai_memory.close()
+
+
+ asyncio.run(main())
+
+ Output:
+
+ .. code-block:: text
- # The memory will automatically retrieve relevant content during conversations
- stream = assistant.run_stream(task="What's the weather in New York?")
+ ---------- TextMessage (user) ----------
+ What's the temperature in New York?
+ ---------- MemoryQueryEvent (assistant) ----------
+ [MemoryContent(content='The user prefers weather temperatures in Celsius', mime_type='MemoryMimeType.TEXT', metadata={'type': 'units', 'category': 'preferences', 'mime_type': 'MemoryMimeType.TEXT', 'score': 0.3133561611175537, 'id': 'fb00506c-acf4-4174-93d7-2a942593f3f7'}), MemoryContent(content='The user prefers weather temperatures in Celsius', mime_type='MemoryMimeType.TEXT', metadata={'mime_type': 'MemoryMimeType.TEXT', 'category': 'preferences', 'type': 'units', 'score': 0.3133561611175537, 'id': '34311689-b419-4e1a-8bc4-09143f356c66'})]
+ ---------- ToolCallRequestEvent (assistant) ----------
+ [FunctionCall(id='call_7TjsFd430J1aKwU5T2w8bvdh', arguments='{"city":"New York"}', name='get_weather')]
+ ---------- ToolCallExecutionEvent (assistant) ----------
+ [FunctionExecutionResult(content='The weather in New York is sunny with a high of 90°F and a low of 70°F.', name='get_weather', call_id='call_7TjsFd430J1aKwU5T2w8bvdh', is_error=False)]
+ ---------- ToolCallRequestEvent (assistant) ----------
+ [FunctionCall(id='call_RTjMHEZwDXtjurEYTjDlvq9c', arguments='{"fahrenheit": 90}', name='fahrenheit_to_celsius'), FunctionCall(id='call_3mMuCK1aqtzZPTqIHPoHKxtP', arguments='{"fahrenheit": 70}', name='fahrenheit_to_celsius')]
+ ---------- ToolCallExecutionEvent (assistant) ----------
+ [FunctionExecutionResult(content='32.22222222222222', name='fahrenheit_to_celsius', call_id='call_RTjMHEZwDXtjurEYTjDlvq9c', is_error=False), FunctionExecutionResult(content='21.11111111111111', name='fahrenheit_to_celsius', call_id='call_3mMuCK1aqtzZPTqIHPoHKxtP', is_error=False)]
+ ---------- TextMessage (assistant) ----------
+ The temperature in New York today is sunny with a high of about 32°C and a low of about 21°C.
- # Remember to close the memory when finished
- await memory.close()
"""
component_config_schema = ChromaDBVectorMemoryConfig
component_provider_override = "autogen_ext.memory.chromadb.ChromaDBVectorMemory"
def __init__(self, config: ChromaDBVectorMemoryConfig | None = None) -> None:
- """Initialize ChromaDBVectorMemory."""
self._config = config or PersistentChromaDBVectorMemoryConfig()
self._client: ClientAPI | None = None
self._collection: Collection | None = None
@@ -269,67 +311,6 @@ class ChromaDBVectorMemory(Memory, Component[ChromaDBVectorMemoryConfig]):
self,
model_context: ChatCompletionContext,
) -> UpdateContextResult:
- """
- Update the model context with relevant memory content.
-
- This method retrieves memory content relevant to the last message in the context
- and adds it as a system message. It serves as the primary customization point for
- how retrieved memories are incorporated into the conversation.
-
- By default, this implementation:
- 1. Uses the last message as a query to find semantically similar memories
- 2. Formats retrieved memories as a numbered list
- 3. Adds them to the context as a system message
-
- For custom memory formatting, extend this class and override this method.
-
- Args:
- model_context (ChatCompletionContext): The model context to update with relevant memories.
-
- Returns:
- UpdateContextResult: Object containing the memories that were used to update the context.
-
- Example:
-
- .. code-block:: python
-
- from autogen_core.memory import Memory, MemoryContent, MemoryQueryResult, UpdateContextResult
- from autogen_core.model_context import ChatCompletionContext
- from autogen_core.models import SystemMessage
- from autogen_ext.memory.chromadb import ChromaDBVectorMemory, PersistentChromaDBVectorMemoryConfig
-
-
- class CustomVectorMemory(ChromaDBVectorMemory):
- async def update_context(
- self,
- model_context: ChatCompletionContext,
- ) -> UpdateContextResult:
- # Get the last message to use as query
- messages = await model_context.get_messages()
- if not messages:
- return UpdateContextResult(memories=MemoryQueryResult(results=[]))
-
- # Get query results
- last_message = messages[-1]
- query_text = last_message.content if isinstance(last_message.content, str) else str(last_message)
- query_results = await self.query(query_text)
-
- if query_results.results:
- # Custom formatting based on memory category
- memory_strings = []
- for memory in query_results.results:
- category = memory.metadata.get("category", "general")
- if category == "preferences":
- memory_strings.append(f"User Preference: {memory.content}")
- else:
- memory_strings.append(f"Memory: {memory.content}")
-
- # Add to context with custom header
- memory_context = "IMPORTANT USER INFORMATION:\n" + "\n".join(memory_strings)
- await model_context.add_message(SystemMessage(content=memory_context))
-
- return UpdateContextResult(memories=query_results)
- """
messages = await model_context.get_messages()
if not messages:
return UpdateContextResult(memories=MemoryQueryResult(results=[]))
@@ -352,7 +333,6 @@ class ChromaDBVectorMemory(Memory, Component[ChromaDBVectorMemoryConfig]):
return UpdateContextResult(memories=query_results)
async def add(self, content: MemoryContent, cancellation_token: CancellationToken | None = None) -> None:
- """Add a memory content to ChromaDB."""
self._ensure_initialized()
if self._collection is None:
raise RuntimeError("Failed to initialize ChromaDB")
@@ -378,7 +358,6 @@ class ChromaDBVectorMemory(Memory, Component[ChromaDBVectorMemoryConfig]):
cancellation_token: CancellationToken | None = None,
**kwargs: Any,
) -> MemoryQueryResult:
- """Query memory content based on vector similarity."""
self._ensure_initialized()
if self._collection is None:
raise RuntimeError("Failed to initialize ChromaDB")
@@ -438,7 +417,6 @@ class ChromaDBVectorMemory(Memory, Component[ChromaDBVectorMemoryConfig]):
raise
async def clear(self) -> None:
- """Clear all entries from memory."""
self._ensure_initialized()
if self._collection is None:
raise RuntimeError("Failed to initialize ChromaDB")
@@ -457,7 +435,6 @@ class ChromaDBVectorMemory(Memory, Component[ChromaDBVectorMemoryConfig]):
self._client = None
async def reset(self) -> None:
- """Reset the memory by deleting all data."""
self._ensure_initialized()
if not self._config.allow_reset:
raise RuntimeError("Reset not allowed. Set allow_reset=True in config to enable.")
diff --git a/python/packages/autogen-ext/src/autogen_ext/memory/mem0/__init__.py b/python/packages/autogen-ext/src/autogen_ext/memory/mem0/__init__.py
new file mode 100644
index 000000000..2f1af2567
--- /dev/null
+++ b/python/packages/autogen-ext/src/autogen_ext/memory/mem0/__init__.py
@@ -0,0 +1,6 @@
+from ._mem0 import Mem0Memory, Mem0MemoryConfig
+
+__all__ = [
+ "Mem0Memory",
+ "Mem0MemoryConfig",
+]
diff --git a/python/packages/autogen-ext/src/autogen_ext/memory/mem0.py b/python/packages/autogen-ext/src/autogen_ext/memory/mem0/_mem0.py
similarity index 77%
rename from python/packages/autogen-ext/src/autogen_ext/memory/mem0.py
rename to python/packages/autogen-ext/src/autogen_ext/memory/mem0/_mem0.py
index 17bae477d..6b91a723b 100644
--- a/python/packages/autogen-ext/src/autogen_ext/memory/mem0.py
+++ b/python/packages/autogen-ext/src/autogen_ext/memory/mem0/_mem0.py
@@ -9,29 +9,17 @@ from autogen_core import CancellationToken, Component, ComponentBase
from autogen_core.memory import Memory, MemoryContent, MemoryQueryResult, UpdateContextResult
from autogen_core.model_context import ChatCompletionContext
from autogen_core.models import SystemMessage
+from mem0 import Memory as Memory0
+from mem0 import MemoryClient
from pydantic import BaseModel, Field
from typing_extensions import Self
-try:
- from mem0 import Memory as Memory0
- from mem0 import MemoryClient
-except ImportError as e:
- raise ImportError("`mem0ai` not installed. Please install it with `pip install mem0ai`") from e
-
logger = logging.getLogger(__name__)
logging.getLogger("chromadb").setLevel(logging.ERROR)
class Mem0MemoryConfig(BaseModel):
- """Configuration for Mem0Memory component.
-
- Attributes:
- user_id: Optional user ID for memory operations. If not provided, a UUID will be generated.
- limit: Maximum number of results to return in memory queries.
- is_cloud: Whether to use cloud Mem0 client (True) or local client (False).
- api_key: API key for cloud Mem0 client. Required if is_cloud=True.
- config: Configuration dictionary for local Mem0 client. Required if is_cloud=False.
- """
+ """Configuration for Mem0Memory component."""
user_id: Optional[str] = Field(
default=None, description="User ID for memory operations. If not provided, a UUID will be generated."
@@ -63,21 +51,112 @@ class Mem0Memory(Memory, Component[Mem0MemoryConfig], ComponentBase[Mem0MemoryCo
of AutoGen's Memory interface. It supports both cloud and local backends through the
mem0ai Python package.
+ To use this component, you need to have the `mem0` (for cloud-only) or `mem0-local` (for local)
+ extra installed for the `autogen-ext` package:
+
+ .. code-block:: bash
+
+ pip install -U "autogen-ext[mem0]" # For cloud-based Mem0
+ pip install -U "autogen-ext[mem0-local]" # For local Mem0
+
The memory component can store and retrieve information that agents need to remember
across conversations. It also provides context updating for language models with
relevant memories.
Examples:
- ```python
- # Create a cloud Mem0Memory
- memory = Mem0Memory(is_cloud=True)
- # Add something to memory
- await memory.add(MemoryContent(content="Important information to remember"))
+ .. code-block:: python
+
+ import asyncio
+ from autogen_ext.memory.mem0 import Mem0Memory
+ from autogen_core.memory import MemoryContent
+
+
+ async def main() -> None:
+ # Create a local Mem0Memory (no API key required)
+ memory = Mem0Memory(
+ is_cloud=False,
+ config={"path": ":memory:"}, # Use in-memory storage for testing
+ )
+ print("Memory initialized successfully!")
+
+ # Add something to memory
+ test_content = "User likes the color blue."
+ await memory.add(MemoryContent(content=test_content, mime_type="text/plain"))
+ print(f"Added content: {test_content}")
+
+ # Retrieve memories with a search query
+ results = await memory.query("What color does the user like?")
+ print(f"Query results: {len(results.results)} found")
+
+ for i, result in enumerate(results.results):
+ print(f"Result {i+1}: {result}")
+
+
+ asyncio.run(main())
+
+ Output:
+
+ .. code-block:: text
+
+ Memory initialized successfully!
+ Added content: User likes the color blue.
+ Query results: 1 found
+ Result 1: content='User likes the color blue' mime_type='text/plain' metadata={'score': 0.6977155806281953, 'created_at': datetime.datetime(2025, 7, 6, 17, 25, 18, 754725, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200)))}
+
+ Using it with an :class:`~autogen_agentchat.agents.AssistantAgent`:
+
+ .. code-block:: python
- # Retrieve memories with a search query
- results = await memory.query("relevant information")
- ```
+ import asyncio
+ from autogen_agentchat.agents import AssistantAgent
+ from autogen_core.memory import MemoryContent
+ from autogen_ext.memory.mem0 import Mem0Memory
+ from autogen_ext.models.openai import OpenAIChatCompletionClient
+
+
+ async def main() -> None:
+ # Create a model client
+ model_client = OpenAIChatCompletionClient(model="gpt-4.1")
+
+ # Create a Mem0 memory instance
+ memory = Mem0Memory(
+ user_id="user123",
+ is_cloud=False,
+ config={"path": ":memory:"}, # Use in-memory storage for testing
+ )
+
+ # Add something to memory
+ test_content = "User likes the color blue."
+ await memory.add(MemoryContent(content=test_content, mime_type="text/plain"))
+
+ # Create an assistant agent with Mem0 memory
+ agent = AssistantAgent(
+ name="assistant",
+ model_client=model_client,
+ memory=[memory],
+ system_message="You are a helpful assistant that remembers user preferences.",
+ )
+
+ # Run a sample task
+ result = await agent.run(task="What color does the user like?")
+ print(result.messages[-1].content) # type: ignore
+
+
+ asyncio.run(main())
+
+ Output:
+
+ .. code-block:: text
+
+ User likes the color blue.
+
+ Args:
+ user_id: Optional user ID for memory operations. If not provided, a UUID will be generated.
+ limit: Maximum number of results to return in memory queries.
+ is_cloud: Whether to use cloud Mem0 client (True) or local client (False).
+ api_key: API key for cloud Mem0 client. It will read from the environment MEM0_API_KEY if not provided.
+ config: Configuration dictionary for local Mem0 client. Required if is_cloud=False.
"""
component_type = "memory"
@@ -92,18 +171,6 @@ class Mem0Memory(Memory, Component[Mem0MemoryConfig], ComponentBase[Mem0MemoryCo
api_key: Optional[str] = None,
config: Optional[Dict[str, Any]] = None,
) -> None:
- """Initialize Mem0Memory.
-
- Args:
- user_id: Optional user ID for memory operations. If not provided, a UUID will be generated.
- limit: Maximum number of results to return in memory queries.
- is_cloud: Whether to use cloud Mem0 client (True) or local client (False).
- api_key: API key for cloud Mem0 client. It will read from the environment MEM0_API_KEY if not provided.
- config: Configuration dictionary for local Mem0 client. Required if is_cloud=False.
-
- Raises:
- ValueError: If is_cloud=True and api_key is None, or if is_cloud=False and config is None.
- """
# Validate parameters
if not is_cloud and config is None:
raise ValueError("config is required when using local Mem0 client (is_cloud=False)")
diff --git a/python/packages/autogen-ext/src/autogen_ext/models/openai/_transformation/registry.py b/python/packages/autogen-ext/src/autogen_ext/models/openai/_transformation/registry.py
index c3148110d..bc603f4a5 100644
--- a/python/packages/autogen-ext/src/autogen_ext/models/openai/_transformation/registry.py
+++ b/python/packages/autogen-ext/src/autogen_ext/models/openai/_transformation/registry.py
@@ -74,10 +74,16 @@ def register_transformer(api: str, model_family: str, transformer_map: Transform
Registers a transformer map for a given model family.
Example:
- register_transformer("gpt-4o", {
- UserMessage: user_message_to_oai,
- SystemMessage: system_message_to_oai,
- })
+
+ .. code-block:: python
+
+ register_transformer(
+ "gpt-4o",
+ {
+ UserMessage: user_message_to_oai,
+ SystemMessage: system_message_to_oai,
+ },
+ )
"""
MESSAGE_TRANSFORMERS[api][model_family] = transformer_map
diff --git a/python/packages/autogen-ext/src/autogen_ext/tools/duckduckgo_search/__init__.py b/python/packages/autogen-ext/src/autogen_ext/tools/duckduckgo_search/__init__.py
new file mode 100644
index 000000000..7471bfffa
--- /dev/null
+++ b/python/packages/autogen-ext/src/autogen_ext/tools/duckduckgo_search/__init__.py
@@ -0,0 +1,7 @@
+from ._duckduckgo_search import DuckDuckGoSearchArgs, DuckDuckGoSearchResult, DuckDuckGoSearchTool
+
+__all__ = [
+ "DuckDuckGoSearchTool",
+ "DuckDuckGoSearchArgs",
+ "DuckDuckGoSearchResult",
+]
diff --git a/python/packages/autogen-ext/src/autogen_ext/tools/web_search/duckduckgo/_duckduckgo_search.py b/python/packages/autogen-ext/src/autogen_ext/tools/duckduckgo_search/_duckduckgo_search.py
similarity index 81%
rename from python/packages/autogen-ext/src/autogen_ext/tools/web_search/duckduckgo/_duckduckgo_search.py
rename to python/packages/autogen-ext/src/autogen_ext/tools/duckduckgo_search/_duckduckgo_search.py
index 526f9f9d0..92ec54a22 100644
--- a/python/packages/autogen-ext/src/autogen_ext/tools/web_search/duckduckgo/_duckduckgo_search.py
+++ b/python/packages/autogen-ext/src/autogen_ext/tools/duckduckgo_search/_duckduckgo_search.py
@@ -32,8 +32,7 @@ class DuckDuckGoSearchResult(BaseModel):
class DuckDuckGoSearchTool(BaseTool[DuckDuckGoSearchArgs, DuckDuckGoSearchResult]):
- """
- A tool for performing DuckDuckGo web searches.
+ """A tool for performing DuckDuckGo web searches.
This tool uses DuckDuckGo's HTML interface to perform web searches without requiring
an API key. It can optionally fetch and convert webpage content to markdown format.
@@ -54,112 +53,79 @@ class DuckDuckGoSearchTool(BaseTool[DuckDuckGoSearchArgs, DuckDuckGoSearchResult
* Configurable number of results
Examples:
- Using the tool directly:
- .. code-block:: python
+ Using the tool directly:
- from autogen_ext.tools.web_search import DuckDuckGoSearchTool, DuckDuckGoSearchArgs
- from autogen_core import CancellationToken
- import asyncio
+ .. code-block:: python
+ from autogen_ext.tools.duckduckgo_search import DuckDuckGoSearchTool, DuckDuckGoSearchArgs
+ from autogen_core import CancellationToken
+ import asyncio
- async def main():
- # Create the search tool
- search_tool = DuckDuckGoSearchTool()
- # Create search arguments
- search_args = DuckDuckGoSearchArgs(
- query="What is AutoGen?", num_results=3, include_snippets=True, include_content=True
- )
+ async def main() -> None:
+ # Create the search tool
+ search_tool = DuckDuckGoSearchTool()
- # Perform the search
- results = await search_tool.run(search_args, CancellationToken())
+ # Create search arguments
+ search_args = DuckDuckGoSearchArgs(
+ query="What is AutoGen?", num_results=3, include_snippets=True, include_content=True
+ )
- # Print results
- print(f"Results as string:\\n{search_tool.return_value_as_string(results)}")
- # This will output something like:
- # Result 1:
- # Title: Microsoft AutoGen: The Next-Gen AI Framework
- # URL: https://microsoft.github.io/autogen/
- # Snippet: AutoGen is a framework that enables development of LLM applications...
- # Content: AutoGen is a framework that enables the development of LLM applications...
+ # Perform the search
+ results = await search_tool.run(search_args, CancellationToken())
+ # Print results
+ print(f"Results as string:\\n{search_tool.return_value_as_string(results)}")
- asyncio.run(main())
- Basic usage with an AssistantAgent:
+ asyncio.run(main())
- .. code-block:: python
+ This will output something like:
- from autogen_ext.tools.web_search import DuckDuckGoSearchTool
- from autogen_agentchat.agents import AssistantAgent
- from autogen_ext.models.openai import OpenAIChatCompletionClient
+ .. code-block:: text
- # Create the search tool
- search_tool = DuckDuckGoSearchTool()
+ Result 1:
+ Title: Microsoft AutoGen: The Next-Gen AI Framework
+ URL: https://microsoft.github.io/autogen/
+ Snippet: AutoGen is a framework that enables development of LLM applications...
+ Content: AutoGen is a framework that enables the development of LLM applications...
- # Create an agent with the search tool
- model_client = OpenAIChatCompletionClient(model="gpt-4")
- agent = AssistantAgent(name="search_agent", model_client=model_client, tools=[search_tool])
+ Basic usage with an :class:`~autogen_agentchat.agents.AssistantAgent`:
- Advanced usage with custom search parameters:
+ .. code-block:: python
- .. code-block:: python
+ import asyncio
+ from autogen_ext.tools.duckduckgo_search import DuckDuckGoSearchTool
+ from autogen_agentchat.agents import AssistantAgent
+ from autogen_ext.models.openai import OpenAIChatCompletionClient
- from autogen_ext.tools.web_search import DuckDuckGoSearchArgs
- # Perform a search in Spanish with content fetching
- search_args = DuckDuckGoSearchArgs(
- query="inteligencia artificial",
- language="es",
- region="es",
- num_results=5,
- include_content=True,
- content_max_length=15000,
- )
+ async def main() -> None:
+ # Create the search tool
+ search_tool = DuckDuckGoSearchTool()
- # Use the search args with your agent
- response = await agent.on_messages(
- [
- TextMessage(
- source="user",
- content="Search for AI in Spanish using these parameters",
- tool_calls=[{"name": "duckduckgo_search", "args": search_args.dict()}],
- )
- ],
- CancellationToken(),
- )
+ # Create an agent with the search tool
+ model_client = OpenAIChatCompletionClient(model="gpt-4")
+ agent = AssistantAgent(name="search_agent", model_client=model_client, tools=[search_tool])
- Quick search without content fetching:
+ # Run the agent with a search task
+ response = await agent.run(task="Search for information about artificial intelligence")
+ print(response.messages[-1].content) # type: ignore
- .. code-block:: python
- # For faster searches without webpage content
- search_args = DuckDuckGoSearchArgs(
- query="latest AI news",
- num_results=3,
- include_snippets=True,
- include_content=False, # Skip content fetching for speed
- )
+ asyncio.run(main())
.. note::
- The tool uses web scraping to fetch results, so it may be affected by:
- - DuckDuckGo's rate limiting
- - Changes to DuckDuckGo's HTML structure
- - Website blocking or requiring JavaScript
- - Network connectivity issues
- Args:
- No initialization arguments required.
+ The tool uses web scraping to fetch results, so it may be affected by:
+ * DuckDuckGo's rate limiting
+ * Changes to DuckDuckGo's HTML structure
+ * Website blocking or requiring JavaScript
+ * Network connectivity issues
Returns:
- DuckDuckGoSearchResult: A result object containing:
- - results (List[Dict[str, str]]): List of search results, each containing:
- - title: The title of the webpage
- - link: The URL of the webpage
- - snippet: (optional) A brief excerpt from the webpage
- - content: (optional) Full webpage content in markdown format
-
+ DuckDuckGoSearchResult: A result object.
"""
def __init__(self) -> None:
diff --git a/python/packages/autogen-ext/tests/memory/test_mem0.py b/python/packages/autogen-ext/tests/memory/test_mem0.py
index a555270fb..24635de50 100644
--- a/python/packages/autogen-ext/tests/memory/test_mem0.py
+++ b/python/packages/autogen-ext/tests/memory/test_mem0.py
@@ -67,7 +67,7 @@ def local_config() -> Mem0MemoryConfig:
@pytest.mark.asyncio
-@patch("autogen_ext.memory.mem0.Memory0")
+@patch("autogen_ext.memory.mem0._mem0.Memory0")
async def test_basic_workflow(mock_mem0_class: MagicMock, local_config: Mem0MemoryConfig) -> None:
"""Test basic memory operations."""
# Setup mock
@@ -201,7 +201,7 @@ async def test_basic_workflow_with_cloud(mock_memory_client_class: MagicMock, cl
@pytest.mark.asyncio
-@patch("autogen_ext.memory.mem0.Memory0")
+@patch("autogen_ext.memory.mem0._mem0.Memory0")
async def test_metadata_handling(mock_mem0_class: MagicMock, local_config: Mem0MemoryConfig) -> None:
"""Test metadata handling."""
# Setup mock
@@ -263,7 +263,7 @@ async def test_metadata_handling(mock_mem0_class: MagicMock, local_config: Mem0M
@pytest.mark.asyncio
-@patch("autogen_ext.memory.mem0.Memory0")
+@patch("autogen_ext.memory.mem0._mem0.Memory0")
async def test_update_context(mock_mem0_class: MagicMock, local_config: Mem0MemoryConfig) -> None:
"""Test updating model context with retrieved memories."""
# Setup mock
@@ -315,7 +315,7 @@ async def test_update_context(mock_mem0_class: MagicMock, local_config: Mem0Memo
@pytest.mark.asyncio
-@patch("autogen_ext.memory.mem0.MemoryClient") # Patch for cloud mode
+@patch("autogen_ext.memory.mem0._mem0.MemoryClient") # Patch for cloud mode
async def test_component_serialization(mock_memory_client_class: MagicMock) -> None:
"""Test serialization and deserialization of the component."""
# Setup mock
@@ -369,7 +369,7 @@ async def test_component_serialization(mock_memory_client_class: MagicMock) -> N
@pytest.mark.asyncio
-@patch("autogen_ext.memory.mem0.Memory0")
+@patch("autogen_ext.memory.mem0._mem0.Memory0")
async def test_result_format_handling(mock_mem0_class: MagicMock, local_config: Mem0MemoryConfig) -> None:
"""Test handling of different result formats."""
# Setup mock
@@ -417,7 +417,7 @@ async def test_result_format_handling(mock_mem0_class: MagicMock, local_config:
@pytest.mark.asyncio
-@patch("autogen_ext.memory.mem0.Memory0")
+@patch("autogen_ext.memory.mem0._mem0.Memory0")
async def test_init_with_local_config(mock_mem0_class: MagicMock, full_local_config: Dict[str, Any]) -> None:
"""Test initializing memory with local configuration."""
# Setup mock
@@ -448,7 +448,7 @@ async def test_init_with_local_config(mock_mem0_class: MagicMock, full_local_con
@pytest.mark.asyncio
-@patch("autogen_ext.memory.mem0.Memory0") # Patches the underlying mem0.Memory class
+@patch("autogen_ext.memory.mem0._mem0.Memory0") # Patches the underlying mem0.Memory class
async def test_local_config_with_memory_operations(
mock_mem0_class: MagicMock,
full_local_config: Dict[str, Any], # full_local_config fixture provides the mock config
diff --git a/python/packages/autogen-ext/tests/tools/web_search/__init__.py b/python/packages/autogen-ext/tests/tools/duckduckgo_search/__init__.py
similarity index 100%
rename from python/packages/autogen-ext/tests/tools/web_search/__init__.py
rename to python/packages/autogen-ext/tests/tools/duckduckgo_search/__init__.py
diff --git a/python/packages/autogen-ext/tests/tools/web_search/test_duckduckgo_agent.py b/python/packages/autogen-ext/tests/tools/duckduckgo_search/test_duckduckgo_agent.py
similarity index 98%
rename from python/packages/autogen-ext/tests/tools/web_search/test_duckduckgo_agent.py
rename to python/packages/autogen-ext/tests/tools/duckduckgo_search/test_duckduckgo_agent.py
index c9921ab5f..d2b64cdad 100644
--- a/python/packages/autogen-ext/tests/tools/web_search/test_duckduckgo_agent.py
+++ b/python/packages/autogen-ext/tests/tools/duckduckgo_search/test_duckduckgo_agent.py
@@ -2,7 +2,7 @@ import pytest
from autogen_core.models import ModelInfo
from autogen_ext.agents.duckduckgo_search._duckduckgo_agent import DuckDuckGoSearchAgent
from autogen_ext.models.replay import ReplayChatCompletionClient
-from autogen_ext.tools.web_search.duckduckgo._duckduckgo_search import DuckDuckGoSearchTool
+from autogen_ext.tools.duckduckgo_search import DuckDuckGoSearchTool
class TestDuckDuckGoSearchAgent:
diff --git a/python/packages/autogen-ext/tests/tools/web_search/test_duckduckgo_integration.py b/python/packages/autogen-ext/tests/tools/duckduckgo_search/test_duckduckgo_integration.py
similarity index 98%
rename from python/packages/autogen-ext/tests/tools/web_search/test_duckduckgo_integration.py
rename to python/packages/autogen-ext/tests/tools/duckduckgo_search/test_duckduckgo_integration.py
index 0d92e549a..4d27d1755 100644
--- a/python/packages/autogen-ext/tests/tools/web_search/test_duckduckgo_integration.py
+++ b/python/packages/autogen-ext/tests/tools/duckduckgo_search/test_duckduckgo_integration.py
@@ -16,7 +16,7 @@ from autogen_core import CancellationToken, FunctionCall
from autogen_core.models import CreateResult, ModelInfo, RequestUsage
from autogen_ext.agents.duckduckgo_search._duckduckgo_agent import DuckDuckGoSearchAgent
from autogen_ext.models.replay import ReplayChatCompletionClient
-from autogen_ext.tools.web_search.duckduckgo._duckduckgo_search import DuckDuckGoSearchArgs, DuckDuckGoSearchTool
+from autogen_ext.tools.duckduckgo_search import DuckDuckGoSearchArgs, DuckDuckGoSearchTool
@pytest.mark.integration
diff --git a/python/packages/autogen-ext/tests/tools/web_search/test_duckduckgo_search.py b/python/packages/autogen-ext/tests/tools/duckduckgo_search/test_duckduckgo_search.py
similarity index 99%
rename from python/packages/autogen-ext/tests/tools/web_search/test_duckduckgo_search.py
rename to python/packages/autogen-ext/tests/tools/duckduckgo_search/test_duckduckgo_search.py
index 113ebc939..d0a428e79 100644
--- a/python/packages/autogen-ext/tests/tools/web_search/test_duckduckgo_search.py
+++ b/python/packages/autogen-ext/tests/tools/duckduckgo_search/test_duckduckgo_search.py
@@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
import httpx
import pytest
from autogen_core import CancellationToken
-from autogen_ext.tools.web_search.duckduckgo._duckduckgo_search import (
+from autogen_ext.tools.duckduckgo_search import (
DuckDuckGoSearchArgs,
DuckDuckGoSearchResult,
DuckDuckGoSearchTool,