A2A RAG代理系统

基于IBM watsonx Orchestrate的A2A RAG代理系统,实现生产级检索增强生成功能,集成Watsonx.ai和Milvus向量数据库。

  • by binnes
  • Python
  • 本地部署
  • 更新于

使用说明

AI代理项目

使用IBM watsonx Orchestrate实现代理到代理(A2A)和模型上下文协议(MCP)标准,其特点是具有watsonx.ai和Milvus的生产就绪RAG代理。

概述

此存储库包含:

  • A2A RAG代理:使用A2A 0.3.0协议进行生产实施 a2a-server 框架
  • IBM Watson Orchestrate集成:企业代理编排和工作流管理
  • MCP 服务器:实现模型上下文协议的RESTful API
  • Watsonx.ai集成:IBM的嵌入式和LLM服务人工智能平台
  • Milvus矢量商店:高性能语义搜索
  • LangGraph工作流:代理状态机编排

快速开始

cd RAG
./deployment/setup.sh
# Edit config/.env with Watsonx.ai credentials
./scripts/start_services.sh

# Test
curl -X POST http://localhost:8000/tools/rag_query \
  -H "Content-Type: application/json" \
  -d '{"query": "What is the A2A protocol?"}'

仓库结构

.
├── RAG/                    # A2A RAG Agent implementation
│   ├── agent/              # LangGraph-based A2A agent
│   ├── mcp_server/         # FastAPI MCP server
│   ├── services/           # Watsonx.ai, Milvus, document processing
│   ├── config/             # Configuration management
│   ├── deployment/         # Podman/Docker deployment
│   ├── scripts/            # Automation scripts
│   └── tests/              # Test suite (34 tests, 100% passing)
│
├── orchestrate/            # IBM watsonx Orchestrate integration
│   ├── rag-agent-config.yml  # Agent configuration
│   ├── scripts/            # Orchestrate startup scripts
│   └── .env                # Orchestrate credentials
│
└── docs/                   # MkDocs documentation
    └── docs/
        ├── rag/            # RAG agent documentation
        ├── architecture/   # System architecture
        ├── protocols/      # A2A and MCP specifications
        └── deployment/     # Deployment guides

建筑

graph TB
    subgraph "IBM watsonx Orchestrate"
        UI[Chat Interface]
        WF[Workflow Engine]
        AR[Agent Registry]
    end
    
    subgraph "A2A Agent Server"
        AC[Agent Card<br/>/.well-known/agent-card.json]
        RH[Request Handler]
        AE[Agent Executor]
        EQ[Event Queue]
    end
    
    subgraph "RAG Agent Core"
        LG[LangGraph Workflow]
        MCP[MCP Tool Client]
    end
    
    subgraph "Backend Services"
        MCPS[MCP Server<br/>FastAPI]
        MILVUS[Milvus<br/>Vector DB]
        WX[Watsonx.ai<br/>LLM + Embeddings]
    end
    
    UI --> WF
    WF -->|A2A 0.3.0<br/>JSON-RPC 2.0| AC
    AC --> RH
    RH --> AE
    AE --> LG
    AE --> EQ
    EQ -->|Task Updates| WF
    
    LG --> MCP
    MCP -->|HTTP/REST| MCPS
    MCPS --> MILVUS
    MCPS --> WX
    
    AR -.->|Discovery| AC
    
    style UI fill:#0f62fe
    style WF fill:#0f62fe
    style AC fill:#ff832b
    style RH fill:#ff832b
    style AE fill:#ff832b

文档

完整的文档可在以下网址获得: https://binnes.github.io/a2a/

RAG代理

部署

平台

安装

先决条件

  • Python 3.11-3.13
  • Podman或Docker
  • IBM Watsonx.ai帐户(API密钥和项目ID)

设置

  1. 克隆仓库

    git clone https://github.com/binnes/a2a.git
    cd a2a
    
  2. 配置RAG代理

    cd RAG
    ./deployment/setup.sh
    cp config/.env.example config/.env
    # Edit config/.env with your credentials
    
  3. 启动服务

    ./scripts/start_services.sh
    
  4. 验证安装

    curl http://localhost:8000/health
    

配置

中的关键设置 RAG/config/.env:

# Watsonx.ai
WATSONX_API_KEY=your_api_key
WATSONX_PROJECT_ID=your_project_id
WATSONX_URL=https://us-south.ml.cloud.ibm.com

# Models
EMBEDDING_MODEL=ibm/granite-embedding-278m-multilingual
EMBEDDING_DIMENSION=768
LLM_MODEL=openai/gpt-oss-120b
LLM_MAX_TOKENS=16384

# RAG
RAG_CHUNK_SIZE=80          # words
RAG_CHUNK_OVERLAP=10       # words
RAG_TOP_K=5

# Milvus
MILVUS_HOST=localhost
MILVUS_PORT=19530
MILVUS_COLLECTION=rag_knowledge_base

测试

cd RAG

# Run all tests
./scripts/run_tests.sh

# Run specific test suites
pytest tests/test_document_processor.py -v
pytest tests/test_e2e_shakespeare.py -v

# Run by marker
pytest -m unit -v
pytest -m integration -v

测试结果:34/34通过(100%覆盖率)

技术栈

组件 技术
A2A协议 A2A服务器(A2A 0.3.0)
代理框架 LangGraph
编排 IBM Watson Orchestrate
MCP服务器 FastAPI
人工智能平台 IBM Watsonx.AI
矢量数据库 Milvus
文档处理 PyPDF、python-docx
部署 Podman/Docker
测试 pytest
文档 MkDocs材料

演出

度量 值
文档索引 196K行为0.37秒
查询响应 <5秒
并发查询 10+并发
矢量搜索 <1秒

项目状态

组件 状态 测试
A2A RAG代理(0.3.0) 完成 34/34通过
IBM编排集成 已完成 已测试
MCP服务器 完成 18/18通过
Watsonx.ai集成 完成 测试
Milvus矢量存储 已完成 已测试
LangGraph工作流 已完成 已测试

贡献

  1. 分叉存储库
  2. 创建要素分支
  3. 通过测试进行更改
  4. 提交拉取请求

开发设置:

cd RAG
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pytest tests/ -v

构建于

此项目是使用创建的 IBM Bob -一个由人工智能驱动的开发助手,帮助构建具有最佳实践和全面文档的生产就绪应用程序。

许可证

Apache许可证2.0

参考文献