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 CLI #4788

Open
wants to merge 4 commits into
base: gagb-magentic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion python/packages/autogen-ext/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ dependencies = [
"autogen-core==0.4.0.dev11",
]

[project.scripts]
m1 = "autogen_ext.teams.magentic_one_cli:main"

[project.optional-dependencies]
langchain = ["langchain_core~= 0.3.3"]
Expand Down Expand Up @@ -59,7 +61,6 @@ dev-dependencies = [
"autogen_test_utils"
]


[tool.ruff]
extend = "../../pyproject.toml"
include = ["src/**", "tests/*.py"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import asyncio
import argparse
import shlex
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.teams.magentic_one import MagenticOne
from autogen_agentchat.ui import Console

def main():
"""
Command-line interface for running a complex task using MagenticOne.

This script accepts a single task string and an optional flag to disable
human-in-the-loop mode. It initializes the necessary clients and runs the
task using the MagenticOne class.

Arguments:
task (str): The task to be executed by MagenticOne.
--no-hil: Optional flag to disable human-in-the-loop mode.

Example usage:
python magentic_one_cli.py "example task"
python magentic_one_cli.py --no-hil "example task"
"""
parser = argparse.ArgumentParser(
description=(
"Run a complex task using MagenticOne.\n\n"
"For more information, refer to the following paper: https://arxiv.org/abs/2411.04468"
)
)
parser.add_argument('task', type=str, nargs=1, help='The task to be executed by MagenticOne.')
parser.add_argument('--no-hil', action='store_true', help='Disable human-in-the-loop mode.')
args = parser.parse_args()

async def run_task(task, hil_mode):
client = OpenAIChatCompletionClient(model="gpt-4o")
m1 = MagenticOne(client=client, hil_mode=hil_mode)
await Console(m1.run_stream(task=task))

task = args.task[0]
asyncio.run(run_task(task, not args.no_hil))

if __name__ == "__main__":
main()
Loading