健康健身多代理系统

一个用于健康与健身指导的多代理系统,通过数据收集和处理提供个性化建议。

  • by amanichopra
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 amanichopra/mcp-a2a-fitness-wellness-multi-agent-system

使用说明

健康/健身代理多智能体系统

这是我在研讨会上分享的代码,旨在揭秘MCP/A2A并展示如何利用它们构建一个用于健康与健身指导的多智能体系统。视频链接如下: 这里.

项目结构

WELLNESS-TRACKING-SYSTEM/
├── agents/                             # Contains agents responsible for data collection and processing
│   ├── data_collection_agent/          # Main data collection logic
│   │   ├── mcp_clients/                # Clients for connecting to MCP servers
│   │   │   └── client.py               # Handles client-side communication
│   │   ├── mcp_servers/                # MCP server implementations
│   │   │   ├── hana.py                 # Connects to SAP HANA for data retrieval
│   │   │   └── agent.py                # Core MCP server agent logic
│   │   └── host_agent/                 # Host-side coordination agent
│   │       └── agent.py                # Manages communication with host application
│   └── __pycache__/                    # Compiled Python cache files
│
├── common/                             # Shared modules and interfaces
│   ├── a2a/                            # Agent-to-agent communication layer
│   │   ├── client.py                   # Client implementation for A2A messaging
│   │   ├── server.py                   # Server for A2A communication
│   │   ├── types.py                    # Shared type definitions for A2A protocol
│   │   └── __init__.py
│   └── __pycache__/
│
├── data/                               # Sample data and datasets
│   ├── fitness_activity.csv            # Fitness activity sample data
│   └── sleep_recovery.csv              # Sleep recovery sample data
│
├── host_app/                           # Host application entrypoint
│   ├── app.py                          # Main application logic for the host
│   └── __init__.py
│
├── .env                                # Environment variables
├── .python-version                     # Python version configuration
├── load_hana.ipynb                     # Notebook for loading SAP HANA data from files in `data/`
├── main.py                             # Root script to spin up all agents at once
├── Makefile                            # Command shortcuts for build/run tasks
├── pyproject.toml                      # Project configuration and dependencies
├── README.md                           # Project documentation
├── requirements.txt                    # Python dependencies
├── run_host_app.py                     # Scri

环境设置

  1. 确保 .env 在根目录中,以下填充了值。请用您的SAP AI Core和SAP HANA凭据替换占位符。
HANA_HOST='...'
HANA_PORT='...'
HANA_USER='...'
HANA_PASSWORD='...'
AICORE_AUTH_URL='...'
AICORE_CLIENT_ID='...'
AICORE_CLIENT_SECRET='...'
AICORE_RESOURCE_GROUP='...'
AICORE_BASE_URL='...'
  1. 跑 uv sync 从(某个来源)安装需求 uv.lock.
  2. 要使用Claude Desktop测试HANA MCP服务器,请运行 make run-data-collection-agent-hana-mcp-server 随后是 make add-data-collection-agent-mcp-server-claude-desktop 在您的Claude桌面配置中注册服务器。例如, ~/Library/Application Support/Claude/claude_desktop_config.json 将会查看下面的内容。请注意,您也可以使用 make run-mcp-inspector 在连接到Claude Desktop之前,先测试MCP服务器。
{
  "mcpServers": {
    "hana-mcp-server": {
      "command": "~/.local/bin/uv",
      "args": [
        "run",
        "--with",
        "fastmcp",
        "--with-requirements",
        "~/Documents/Code/wellness-tracking-system/requirements.txt",
        "fastmcp",
        "run",
        "~/Documents/Code/wellness-tracking-system/data_collection_agent/mcp_servers/hana.py:app"
      ],
      "env": {
        "HANA_HOST": "...",
        "HANA_PORT": "...",
        "HANA_USER": "...",
        "HANA_PASSWORD": "..."
      },
      "transport": "stdio",
      "type": null,
      "cwd": null,
      "timeout": null,
      "description": null,
      "icon": null,
      "authentication": null
    }
  }
}
  1. 要运行MCP客户端以测试自定义设置,且不将Claude Desktop作为主机应用程序,可执行 make run-data-collection-agent-hana-mcp-client您可以通过这个命令行界面(CLI)与代理进行交互。
  2. 要运行A2A服务器,您可以先关闭MCP服务器和客户端,因为数据收集代理中的A2A客户端会再次启动MCP服务器。
  3. 跑 make run_data_collecition_agent_a2a_server 并且 make run_host_agent_a2a_server 启动每个A2A服务器。然后,运行带有(界面)的UI(用户界面) run_host_app 并且参观 http://localhost:7860 访问用户界面。