1、官网

 https://microsoft.github.io/autogen/stable//index.html 


2、建立环境

uv init magentic-one-demo
cd .\magentic-one-demo\
uv add magentic-one-cli


3、运行demo

激活环境:

.venv\Scripts\activate

运行命令:

m1 "Find flights from Seattle to Paris and format the result in a table"

直接报错

对啊,我压根没配置API_KEY啊


4、支持deepseek

 https://microsoft.github.io/autogen/stable//reference/python/autogen_ext.models.openai.html 

 uv pip install "autogen-ext[openai]"
import os
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_core.models import ModelFamily

LLM_MODEL = 'deepseek-ai/DeepSeek-V3'  # 'gpt-3.5-turbo' #'gpt-4o'
LLM_base_url="https://api.siliconflow.cn/v1"
# 获取环境变量中的 SILICONFLOW API 密钥
SILICONFLOW_API_KEY = os.getenv('SILICONFLOW_API_KEY')

if not SILICONFLOW_API_KEY:
    raise ValueError("SILICONFLOW API key is not set. Please set the SILICONFLOW_API_KEY environment variable.")

custom_model_client = OpenAIChatCompletionClient(
    model=LLM_MODEL,
    base_url=LLM_base_url,
    api_key=SILICONFLOW_API_KEY,
    model_info={
        "vision": False,
        "function_calling": False,
        "json_output": False,
        "family": ModelFamily.V3,
    },
)

 https://microsoft.github.io/autogen/stable//user-guide/agentchat-user-guide/magentic-one.html 



5、整合第一个例子


import os
import asyncio
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_core.models import ModelFamily
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import MagenticOneGroupChat
from autogen_agentchat.ui import Console

LLM_MODEL = 'deepseek-ai/DeepSeek-R1'  # 'gpt-3.5-turbo' #'gpt-4o'
LLM_base_url="https://api.siliconflow.cn/v1"
# 获取环境变量中的 SILICONFLOW API 密钥
SILICONFLOW_API_KEY = os.getenv('SILICONFLOW_API_KEY')

if not SILICONFLOW_API_KEY:
    raise ValueError("SILICONFLOW API key is not set. Please set the SILICONFLOW_API_KEY environment variable.")

custom_model_client = OpenAIChatCompletionClient(
    model=LLM_MODEL,
    base_url=LLM_base_url,
    api_key=SILICONFLOW_API_KEY,
    model_info={
        "vision": False,
        "function_calling": False,
        "json_output": False,
        "family": ModelFamily.R1,
    },
)

async def main() -> None:
    model_client = custom_model_client

    assistant = AssistantAgent(
        "Assistant",
        model_client=model_client,
    )
    team = MagenticOneGroupChat([assistant], model_client=model_client)
    await Console(team.run_stream(task="Find flights from Seattle to Paris and format the result in a table"))


asyncio.run(main())

受够了,API都不稳定