简介

Magentic-UI:
https://github.com/microsoft/Magentic-UI?tab=readme-ov-file#%EF%B8%8F-installation


安装

环境准备

  1. 需要docker环境,安装可参照docker 安装
  2. 安装python3.12、python3.12-venv
    • 导入 Python 的稳定版 PPA,如果遇到网络问题可以使用代理proxychains4,不需要代理删除proxychains4即可:
      1
      proxychains4 add-apt-repository ppa:deadsnakes/ppa
      deadsnakes PPA 是由 Python 社区维护的一个软件源,专门用于提供不同版本的 Python(包括一些较新的版本),这些版本可能不在 Ubuntu 的默认软件源中。
    • 更新 APT 缓存:
      1
      sudo apt update
      • 安装 Python 3.12
        1
        apt install python3.12 python3.12-venv
      • 检查版本
        1
        python3.12 --version

Magentic-UI 安装

  1. 使用虚拟环境以避免与其他软件包冲突
    • linux
      1
      2
      3
      python3 -m venv .venv
      source .venv/bin/activate
      pip install magentic-ui
    • windows
      1
      2
      3
      python -m venv venv
      venv\Scripts\activate
      pip install magentic-ui
  2. 如果使用 uv 进行依赖项管理(较快),则可以使用以下命令安装 Magentic-UI:
    1
    2
    3
    uv venv --python=3.12 .venv
    . .venv/bin/activate
    uv pip install magentic-ui
  3. 运行 Magentic-UI
    第一次运行此命令时,会构建 Docker 镜像,时间比较久;
    要运行 Magentic-UI,请确保 Docker 正在运行,然后运行以下命令:
    1
    magentic-ui --port 8081 --host 0.0.0.0

venv虚拟环境进入退出

  1. linux
    • 要退出虚拟环境,只需运行以下命令:
      1
      deactivate
    • 想再次进入虚拟环境,只需重新激活它。到达.venv的根目录后,进入虚拟环境的命令如下:
      1
      source .venv/bin/activate
  2. windows
    • 退出相同,进入为
      1
      venv\Scripts\activate

配置

模型客户端配置

  • 如果要使用不同的 OpenAI 密钥,或者想要配置与 Azure OpenAI 或 Ollama 的使用,可以在 UI 中执行此作,方法是导航到设置(右上角图标)并使用下面的文件格式更改模型配置。
  • 您还可以在 UI 中创建并导入它,或在启动时将 Magentic-UI 指向其路径:config.yamlconfig.yaml
    1
    magentic-ui --config path/to/config.yaml
    官方给出了 OpenAI 的示例:config.yaml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    # config.yaml

    ######################################
    # Default OpenAI model configuration #
    ######################################
    model_config: &client
    provider: autogen_ext.models.openai.OpenAIChatCompletionClient
    config:
    model: gpt-4o
    api_key: <YOUR API KEY>
    max_retries: 10

    ##########################
    # Clients for each agent #
    ##########################
    orchestrator_client: *client
    coder_client: *client
    web_surfer_client: *client
    file_surfer_client: *client
    action_guard_client: *client

MCP 服务器配置

可以通过向多代理团队添加自定义 “McpAgents” 来扩展 Magentic-UI 的功能。每个 McpAgent 都可以访问一个或多个 MCP 服务器。可以通过 .mcp_agent_configsconfig.yaml

官网给出的示例:
例如,这里有一个名为“airbnb_surfer”的代理,它可以通过 Stdio 访问本地运行的 OpenBnb MCP 服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
mcp_agent_configs:
- name: airbnb_surfer
description: "The airbnb_surfer has direct access to AirBnB."
model_client:
provider: OpenAIChatCompletionClient
config:
model: gpt-4.1-2025-04-14
max_retries: 10
system_message: |-
You are AirBnb Surfer, a helpful digital assistant that can help users acces AirBnB.

You have access to a suite of tools provided by the AirBnB API. Use those tools to satisfy the users requests.
reflect_on_tool_use: false
mcp_servers:
- server_name: AirBnB
server_params:
type: StdioServerParams
command: npx
args:
- -y
- "@openbnb/mcp-server-airbnb"
- --ignore-robots-txt