Content
# Contract Review Multi-Agent System / 合同审查多智能体系统
A professional contract analysis and review system built on Google's A2A (Agent-to-Agent) protocol, providing comprehensive contract review services through collaborative specialized agents.
## System Architecture / 系统架构
```
┌─────────────────────────────────────────────────────────────┐
│ User Layer / 用户层 │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Contract Review Request │ │
│ │ 合同审查请求 │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ Coordinator Layer / 协调器层 │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ ContractCoordinator (Port 7000) │ │
│ │ │ │
│ │ • Receive requests / 接收用户请求 │ │
│ │ • Task distribution / 任务分发调度 │ │
│ │ • Result integration / 结果整合输出 │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ A2A Protocol Layer / A2A协议层 │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ BaseAgent │ │
│ │ │ │
│ │ • A2A protocol implementation / A2A通信协议实现 │ │
│ │ • Unified task interface / 统一任务处理接口 │ │
│ │ • LLM integration wrapper / 大模型调用封装 │ │
│ │ • Error handling / 错误处理 │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ Specialized Agent Layer / 专业Agent层 │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ DocumentAgent │ │ LegalAgent │ │ BusinessAgent │ │
│ │ (Port 7005) │ │ (Port 7002) │ │ (Port 7003) │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ FormatAgent │ │ HighlightAgent│ │ IntegrationAgt│ │
│ │ (Port 7004) │ │ (Port 7006) │ │ (Port 7007) │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
```
## Features / 功能特点
### 🔍 Professional Analysis / 专业分析能力
- **Document Processing**: Intelligent parsing of contract structure, extracting key information
- **Legal Analysis**: Compliance checks, risk identification, legal advice
- **Business Analysis**: Financial terms analysis, business value assessment
- **Format Check**: Document standardization, professionalism assessment
- **Highlighting**: Key clauses highlighting, risk point marking
- **Result Integration**: Comprehensive report generation, decision support
### 🚀 Technical Features / 技术特性
- **A2A Protocol**: Standardized communication between agents
- **Parallel Processing**: Collaborative work of multiple agents
- **Modular**: Loosely coupled architecture, easy to extend
- **Scalable**: Supports the addition of new specialized agents
- **Fault Tolerance**: Robust error handling and recovery
## Quick Start / 快速开始
### 1. Requirements / 环境要求
```bash
Python 3.8+
```
### 2. Install Dependencies / 安装依赖
```bash
pip install -r requirements.txt
```
### 3. Configuration / 配置系统
Edit the `config.py` file to configure the LLM API:
LLM API activation link: https://console.bce.baidu.com/qianfan/modelcenter/model/buildIn/detail/am-c8fe1b412vwn?tab=version#ERNIE-4.5-21B-A3B
```python
LLM_CONFIG = LLMConfig(
api_key="your-api-key", # Replace with your API key
model="ernie-4.5-21b-a3b",
base_url="https://qianfan.baidubce.com/v2/chat/completions"
)
```
### 4. Start System / 启动系统
```bash
python start_system.py start
```
### 5. Usage / 使用系统
Send a contract review request to the coordinator:
```python
from python_a2a import A2AClient, Message, TextContent, MessageRole
# Connect to the coordinator
client = A2AClient("http://localhost:7000/a2a")
# Send contract text for review
contract_text = "Your contract content..."
message = Message(
content=TextContent(text=contract_text),
role=MessageRole.USER
)
# Get review results
response = client.send_message(message)
print(response.content.text)
```
## Agent Description / 智能体说明
### ContractCoordinator (Port 7000) / 协调器
- **Responsibilities**: Main coordinator responsible for receiving user requests, distributing tasks, and integrating results
- **Functions**: Workflow planning, task scheduling, result summarization
- **Input**: User's contract review request
- **Output**: Comprehensive contract review report
### DocumentProcessingAgent (Port 7005) / 文档处理智能体
- **Responsibilities**: Document parsing and structural analysis
- **Functions**:
- Document structure recognition (sections, clauses, attachments)
- Key information extraction (parties, amounts, dates)
- Contract type identification
- Text statistical analysis
- **Output**: Structured document analysis report
### LegalAgent (Port 7002) / 法律智能体
- **Responsibilities**: Legal compliance analysis and risk assessment
- **Functions**:
- Contract validity requirement checks
- Necessary clause completeness analysis
- Legal risk identification and rating
- Breach liability clause analysis
- Dispute resolution mechanism assessment
- **Output**: Legal risk report and compliance recommendations
### BusinessAgent (Port 7003) / 商业智能体
- **Responsibilities**: Business terms and financial analysis
- **Functions**:
- Financial terms analysis (price, payment conditions)
- Business risk assessment
- Return on investment analysis
- Market conditions assessment
- Operational requirements analysis
- **Output**: Business value and risk assessment report
### FormatAgent (Port 7004) / 格式智能体
- **Responsibilities**: Document format and standardization checks
- **Functions**:
- Contract structure standardization checks
- Section numbering system analysis
- Format consistency assessment
- Professionalism and readability assessment
- **Output**: Format standardization report and improvement suggestions
### HighlightAgent (Port 7006) / 高亮智能体
- **Responsibilities**: Highlighting key content and risk alerts
- **Functions**:
- Key clause identification and marking
- Risk point highlighting
- Important information classification marking
- Attention reminders
- **Output**: Annotated contract document and key notes
### IntegrationAgent (Port 7007) / 整合智能体
- **Responsibilities**: Integration of analysis results and final report generation
- **Functions**:
- Multi-dimensional analysis result integration
- Comprehensive risk rating
- Decision support information generation
- Standardized report output
- **Output**: Comprehensive analysis report and action recommendations
## System Management / 系统管理
### Start System / 启动系统
```bash
python start_system.py start
```
### Check Status / 查看状态
```bash
python start_system.py status
```
### Stop System / 停止系统
```bash
python start_system.py stop
```
### Help / 帮助信息
```bash
python start_system.py help
```
## API Interface / API 接口
All agents provide standard A2A interfaces:
### Endpoints / 端点
- Coordinator: `http://localhost:7000/a2a`
- Legal Agent: `http://localhost:7002/a2a`
- Business Agent: `http://localhost:7003/a2a`
- Format Agent: `http://localhost:7004/a2a`
- Document Agent: `http://localhost:7005/a2a`
- Highlight Agent: `http://localhost:7006/a2a`
- Integration Agent: `http://localhost:7007/a2a`
### Message Format / 消息格式
```python
{
"content": {
"type": "text",
"text": "Contract content or analysis request"
},
"role": "user",
"message_id": "uuid",
"conversation_id": "uuid"
}
```
## Configuration / 配置说明
### Environment Variables / 环境变量
```bash
# LLM API configuration
QIANFAN_API_KEY=your-api-key
OPENAI_API_KEY=your-openai-key
ANTHROPIC_API_KEY=your-anthropic-key
```
### Configuration File / 配置文件
Edit `config.py` to modify:
- LLM model configuration
- Agent port settings
- System parameter adjustments
## Development Guide / 开发指南
### Adding New Agents / 添加新智能体
1. Inherit from the `BaseAgent` class
2. Implement the `process_text_message` method
3. Add configuration in `config.py`
4. Register in `start_system.py`
Example:
```python
from base_agent import BaseAgent
class CustomAgent(BaseAgent):
def __init__(self):
super().__init__("CustomAgent", "Your system prompt")
def process_text_message(self, message):
# Implement your business logic
return self.create_response_message(message, "Analysis result")
```
### Extending Coordinator / 扩展协调器
Modify the workflow logic in `coordinator.py` to integrate new agents.
## Troubleshooting / 故障排除
### Common Issues / 常见问题
1. **Port Conflict**: Modify port settings in `config.py`
2. **Missing Dependencies**: Run `pip install -r requirements.txt`
3. **API Key**: Check LLM API configuration in `config.py`
4. **Startup Failure**: Check log output and file permissions
### Logging / 日志查看
The system will output detailed runtime logs to the console, including:
- Agent startup status
- Request processing details
- Error messages and warnings
## Performance Optimization / 性能优化
### Recommended Configuration / 建议配置
- **Memory**: At least 4GB RAM
- **CPU**: Multi-core processor recommended
- **Network**: Stable network connection (for LLM API calls)
### Optimization Tips / 优化建议
1. Use high-performance LLM API services
2. Adjust the number of concurrent processes appropriately
3. Cache frequently used analysis results
4. Monitor system resource usage
## Security Considerations / 安全考虑
### Data Security / 数据安全
- Contract data is processed only in memory, not persistently stored
- Supports local deployment, data does not leave your environment
- LLM API calls use encrypted transmission
### Access Control / 访问控制
- Access can be restricted at the network level
- Supports adding authentication mechanisms
- Audit logs record all operations
## License / 许可证
This project is open-sourced under the MIT License.
## Contributing / 贡献
Feel free to submit Issues and Pull Requests to improve this project.
## Contact / 联系方式
If you have any questions or suggestions, please submit a GitHub Issue.
---
**Note**: This is a demonstration system. Please configure and optimize security settings appropriately based on actual needs. Ensure thorough testing and compliance with your security and regulatory requirements before using in a production environment.