Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MagenticOne API #4782

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a710b23
Add MagenticOne API
gagb Dec 21, 2024
04bab6a
Add CodeExecutorAgent to MagenticOne for enhanced task execution
gagb Dec 21, 2024
ed1fbd2
Refactor MagenticOne class to inherit from MagenticOneGroupChat and s…
gagb Dec 21, 2024
d3cc745
Enhance MagenticOne class documentation with detailed usage examples …
gagb Dec 21, 2024
5232e4b
Refactor MagenticOne module structure and update import paths
gagb Dec 21, 2024
8f3e655
Remove unused imports
gagb Dec 21, 2024
52ae9d3
Add documentation for MagenticOne module and remove redundant initial…
gagb Dec 21, 2024
bcd05e7
Merge branch 'main' into gagb-magentic
husseinmozannar Dec 21, 2024
ce54a24
Enhance MagenticOne class with human-in-the-loop mode and update exam…
gagb Dec 22, 2024
a949095
Update MagenticOne class documentation with safety precautions and ar…
gagb Dec 22, 2024
01598b3
Run poe format
gagb Dec 22, 2024
dab681b
Add blog post reference to MagenticOne class documentation
gagb Dec 22, 2024
c6fe0c4
change default of websurfer use_ocr to false because of refusals
husseinmozannar Dec 22, 2024
9876ccc
Refactor MagenticOne class to use ChatCompletionClient instead of Ope…
gagb Dec 23, 2024
833a6b2
Merge branch 'gagb-magentic' of github.com:microsoft/autogen into gag…
gagb Dec 23, 2024
592adfa
Add client capability validation to MagenticOne initialization
gagb Dec 23, 2024
b414d90
Poe format
gagb Dec 23, 2024
84373be
Refactor imports in MagenticOne class for clarity and organization
gagb Dec 23, 2024
15aa3a8
Add stacklevel parameter to warning in client capability validation
gagb Dec 23, 2024
5c24a95
Update README to recommend using Magentic-One API for improved integr…
gagb Dec 23, 2024
f63db65
Add create_args property to OpenAIChatCompletionClient for better acc…
gagb Dec 23, 2024
4d80dd1
Enhance client capability validation in MagenticOne to ensure compati…
gagb Dec 23, 2024
7f02b5b
Refactor client capability validation in MagenticOne for improved cla…
gagb Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions python/packages/autogen-ext/src/autogen_ext/teams/magentic_one.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from autogen_agentchat.agents import CodeExecutorAgent
from typing import List

from autogen_agentchat.agents import CodeExecutorAgent, UserProxyAgent
from autogen_agentchat.base import ChatAgent
from autogen_agentchat.teams import MagenticOneGroupChat

from autogen_ext.agents.file_surfer import FileSurfer
Expand All @@ -16,10 +19,13 @@ class MagenticOne(MagenticOneGroupChat):

Attributes:
client (OpenAIChatCompletionClient): The client used for model interactions.
hil_mode (bool): Optional; If set to True, adds the UserProxyAgent to the list of agents.

Example:
Examples:

.. code-block:: python

# Autonomously complete a coding task:
import asyncio
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.teams.magentic_one import MagenticOne
Expand All @@ -36,12 +42,48 @@ async def example_usage():

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


.. code-block:: python

# Enable human-in-the-loop mode
import asyncio
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.teams.magentic_one import MagenticOne
from autogen_agentchat.ui import Console


async def example_usage_hil():
client = OpenAIChatCompletionClient(model="gpt-4o")
# to enable human-in-the-loop mode, set hil_mode=True
m1 = MagenticOne(client=client, hil_mode=True)
task = "Write a Python script to fetch data from an API."
result = await Console(m1.run_stream(task=task))
print(result)


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

References:
.. code-block:: bibtex

@article{fourney2024magentic,
title={Magentic-one: A generalist multi-agent system for solving complex tasks},
author={Fourney, Adam and Bansal, Gagan and Mozannar, Hussein and Tan, Cheng and Salinas, Eduardo and Niedtner, Friederike and Proebsting, Grace and Bassman, Griffin and Gerrits, Jack and Alber, Jacob and others},
journal={arXiv preprint arXiv:2411.04468},
year={2024}
}
"""

def __init__(self, client: OpenAIChatCompletionClient):
def __init__(self, client: OpenAIChatCompletionClient, hil_mode: bool = False):
self.client = client
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use autogen_core.models.ChatCompletionClient base class instead of concrete class for the argument type

Copy link
Collaborator Author

@gagb gagb Dec 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this because we only tested with openai. Do you still think I should change it?

Copy link
Collaborator

@ekzhu ekzhu Dec 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. Though this client has already been used by many for Ollama models. Also there is AzureOpenAIChatCompletionClient, which we also tested on. So I think we should still update it to use the base class.

Instead of rely on type, I think we need to validate the model capabilities in the constructor -- unless it has already been done in the base class. Sorry on mobile so a bit hard to switch page here.

We can also validate the model name, and raise warning if the model is something we haven't tested.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay good point. I will do this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

  1. I added a private method to the class that validates the client.
    image

  2. I had to expose the _create_args in BaseOpenAIChatCompletion to achieve this.
    image

fs = FileSurfer("FileSurfer", model_client=client)
ws = MultimodalWebSurfer("WebSurfer", model_client=client)
coder = MagenticOneCoderAgent("Coder", model_client=client)
executor = CodeExecutorAgent("Executor", code_executor=LocalCommandLineCodeExecutor())
super().__init__([fs, ws, coder, executor], model_client=client)
agents: List[ChatAgent] = [fs, ws, coder, executor]
if hil_mode:
user_proxy = UserProxyAgent("User")
agents.append(user_proxy)
super().__init__(agents, model_client=client)
Loading