编排器客户端-智能代理命令行界面
用于与Aichestra多代理系统交互的命令行客户端。 最好与 智能编排代理 用于无缝代理交互和智能路由。
🚀 智能编排器集成
客户端现在支持 智能代理路由:
自动代理选择
# Intelligent routing to best agent
> "Convert 100 USD to EUR" → Currency Agent (100% confidence)
> "What is 2+3?" → Math Agent (95% confidence)
> "List ArgoCD applications" → ArgoCD Agent (100% confidence)动态代理发现
# Discover available agents
> LIST_AGENTS → Show all registered agents
> REGISTER_AGENT:http://localhost:8001 → Register a new agent
> UNREGISTER_AGENT:http://localhost:8001 → Unregister an existing agent
> UNREGISTER_AGENT:currency → Remove agent🏗️ 系统集成
客户端与编排器系统集成以实现智能路由:
graph TD
A[User Input] --> B[🔧 Orchestrator Client]
B --> C[🤖 Smart Orchestrator]
C --> D[A2A Card Resolver]
D --> E[Skill Analysis]
E --> F{Confidence Scoring}
F -->|High Score| G[Route to Best Agent]
F -->|Low Score| H[Fallback Response]
G --> I[☸️ ArgoCD Agent]
G --> J[💰 Currency Agent]
G --> K[🧮 Math Agent]
I --> L[Response]
J --> L
K --> L
L --> B
B --> M[Formatted Output]
subgraph "Intelligent Routing"
C
D
E
F
G
end
subgraph "Agent Ecosystem"
I
J
K
end✨ 主要特点
🤖 智能代理路由
- 自动选择:根据请求内容路由到最佳代理
- 信心评分:显示路由信心和推理能力
- 实时发现:动态发现可用代理
- 基于技能的匹配:将请求与代理功能相匹配
💬 增强的用户体验
- 自然语言:使用简单的英语进行交互
- 干净的回应:格式化输出而不是原始JSON
- 代理发现:显示可用代理及其功能
- 会话管理:保持对话上下文
🔧 高级客户端功能
- WebSocket支持:实时推送通知
- 历史跟踪:可选对话历史记录
- 自定义头:支持身份验证和元数据
- 灵活的配置:多种连接选项
🚀 快速开始
选项1:智能编排器(推荐)
连接到编排器以进行智能代理路由:
# Terminal 1: Start Currency Agent
cd currencyAgent && uv run -m app
# Terminal 2: Start Math Agent
cd mathAgent && uv run -m app
# Terminal 3: Start ArgoCD Agent
cd argocdAgent && uv run -m app
# Terminal 4: Start Orchestrator
cd orchestrator && uv run -m app
# Terminal 5: Connect Client
cd orchestrator_client && uv run . --agent http://localhost:8000
# Natural language interactions:
# > "Convert 100 USD to EUR" → Currency Agent (100%)
# > "What is 2+3?" → Math Agent (95%)
# > "List ArgoCD applications" → ArgoCD Agent (100%)选项2:直接代理连接
直接连接到特定代理:
# Connect to ArgoCD agent directly
uv run . --agent http://localhost:8001
# Connect to Currency agent directly
uv run . --agent http://localhost:8002
# Connect to Math agent directly
uv run . --agent http://localhost:8003选项3:定制代理
连接到任何A2A兼容代理:
uv run . --agent http://your-custom-agent:port📖 使用选项
先决条件
- Python 3.10+(A2A SDK兼容性所需)
- 正在运行的A2A代理服务器(建议使用编排器)
- uv包管理器
安装
cd orchestrator_client
uv sync命令行选项
# Basic usage
uv run . --agent http://localhost:8000
# With custom session ID
uv run . --agent http://localhost:8000 --session 12345
# With history tracking
uv run . --agent http://localhost:8000 --history
# With push notifications
uv run . --agent http://localhost:8000 --use_push_notifications
# With custom headers
uv run . --agent http://localhost:8000 --header "Authorization=Bearer token"
# With custom push notification receiver
uv run . --agent http://localhost:8000 --push_notification_receiver http://localhost:5000🌐 FastAPI集成
编排器客户端现在支持 FastAPI端点 用于代理管理,提供更快、更可靠的操作。
FastAPI代理管理
# List agents via FastAPI (faster than A2A protocol)
uv run . --agent http://localhost:8000 --list_agent --use_fastapi
# Register agent via FastAPI
uv run . --agent http://localhost:8000 --register_agent http://localhost:8001 --use_fastapi
# Unregister agent via FastAPI
uv run . --agent http://localhost:8000 --unregister_agent "Math Agent" --use_fastapi
# Show API documentation URLs
uv run . --agent http://localhost:8000 --show_api_docs测试FastAPI集成
# Run comprehensive FastAPI tests
python test_fastapi_integration.py
# Run interactive demo
python test_fastapi_integration.py --interactive
# Show usage help
python test_fastapi_integration.py --helpFastAPI功能
- ✅ 更快的操作:直接HTTP调用,而不是A2A协议开销
- ✅ 更好的错误处理:带详细信息的结构化错误响应
- ✅ 自动回退:如果FastAPI不可用,则返回A2A协议
- ✅ 交互式文档:Swagger用户界面位于
/management/docs - ✅ 混合客户端:支持FastAPI和A2A协议
- ✅ 类型安全:用于请求/响应验证的Pydantic模型
FastAPI与A2A协议
| 功能 | FastAPI | A2A协议 |
|---|---|---|
| 速度 | ⚡ 快速 | 🐌 慢一点 |
| 错误处理 | 📋 结构化 | 📝 基础 |
| 文档 | 📖 互动 | ❌ 没有 |
| 后退 | ✅ 是 | 不适用 |
| 类型安全 | ✅ Pydantic | ❌ 有限 |
🧪 互动体验
代理发现显示
连接后,您将看到可用的代理:
% uv run . --agent http://localhost:8000
Will use headers: {}
======= Agent Card ========
{"capabilities":{"pushNotifications":true,"stateTransitionHistory":false,"streaming":false},"defaultInputModes":["text"],"defaultOutputModes":["text"],"description":"Intelligent agent that routes requests to specialized agents using LangGraph and A2A protocol","name":"Smart Orchestrator Agent","skills":[{"description":"Intelligent request routing to specialized agents","id":"request_routing","name":"Request Routing","tags":["routing","orchestration"]},{"description":"Multi-agent system coordination and management","id":"agent_coordination","name":"Agent Coordination","tags":["coordination","management"]},{"description":"Skill-based agent selection and matching","id":"skill_matching","name":"Skill Matching","tags":["matching","selection"]},{"description":"Confidence scoring for routing decisions","id":"confidence_scoring","name":"Confidence Scoring","tags":["scoring","confidence"]}],"url":"http://localhost:8000/","version":"1.0.0"}
============================================================
🤖 AVAILABLE AGENTS
============================================================
Found 3 available agents:
1. ArgoCD Agent (http://localhost:8001)
Description: Handles ArgoCD and Kubernetes operations via MCP protocol
Skills: Kubernetes Management, GitOps, Application Deployment (+3 more)
2. Currency Agent (http://localhost:8002/)
Description: Handles currency exchange and financial data
Skills: Currency exchange operations, Financial data analysis, Market analysis and trends (+2 more)
3. Math Agent (http://localhost:8003/)
Description: Advanced mathematical assistant for calculations, equation solving, calculus, statistics, and matrix operations via MCP
Skills: Arithmetic Calculation, Equation Solving, Calculus Operations (+2 more)
============================================================
💡 The orchestrator will automatically route your requests to the best agent!
============================================================
========= starting a new task ========
What do you want to send to the agent? (:q or quit to exit):智能路由示例
# Financial operations → Currency Agent
> "Convert 100 USD to EUR"
🎯 Routing to Currency Agent (100% confidence)
💰 Response: 100 USD = 85.32 EUR (current rate: 0.8532)
# Mathematical operations → Math Agent
> "What is 2+3?"
🎯 Routing to Math Agent (95% confidence)
🧮 Response: 2 + 3 = 5
# Kubernetes operations → ArgoCD Agent
> "List all applications"
🎯 Routing to ArgoCD Agent (100% confidence)
☸️ Response: Found 5 applications: guestbook, web-app, api-service...代理商注册
% uv run . --register_agent http://localhost:8003
Will use headers: {}
======= Agent Card ========
{"capabilities":{"pushNotifications":true,"stateTransitionHistory":false,"streaming":false},"defaultInputModes":["text"],"defaultOutputModes":["text"],"description":"Intelligent agent that routes requests to specialized agents using LangGraph and A2A protocol","name":"Smart Orchestrator Agent","skills":[{"description":"Intelligent request routing to specialized agents","id":"request_routing","name":"Request Routing","tags":["routing","orchestration"]},{"description":"Multi-agent system coordination and management","id":"agent_coordination","name":"Agent Coordination","tags":["coordination","management"]},{"description":"Skill-based agent selection and matching","id":"skill_matching","name":"Skill Matching","tags":["matching","selection"]},{"description":"Confidence scoring for routing decisions","id":"confidence_scoring","name":"Confidence Scoring","tags":["scoring","confidence"]}],"url":"http://localhost:8000/","version":"1.0.0"}
🔄 Registering agent http://localhost:8003 with orchestrator http://localhost:8000
📤 Sending registration request...
🎉 Registration completed successfully!
📄 ✅ Successfully registered Math Agent from http://localhost:8003
Agent ID: Math Agent
Agent Name: Math Agent
Total agents: 3代理注销
% uv run . --unregister_agent http://localhost:8003
Will use headers: {}
======= Agent Card ========
{"capabilities":{"pushNotifications":true,"stateTransitionHistory":false,"streaming":false},"defaultInputModes":["text"],"defaultOutputModes":["text"],"description":"Intelligent agent that routes requests to specialized agents using LangGraph and A2A protocol","name":"Smart Orchestrator Agent","skills":[{"description":"Intelligent request routing to specialized agents","id":"request_routing","name":"Request Routing","tags":["routing","orchestration"]},{"description":"Multi-agent system coordination and management","id":"agent_coordination","name":"Agent Coordination","tags":["coordination","management"]},{"description":"Skill-based agent selection and matching","id":"skill_matching","name":"Skill Matching","tags":["matching","selection"]},{"description":"Confidence scoring for routing decisions","id":"confidence_scoring","name":"Confidence Scoring","tags":["scoring","confidence"]}],"url":"http://localhost:8000/","version":"1.0.0"}
🔄 Unregistering agent http://localhost:8003 from orchestrator http://localhost:8000
📤 Sending unregistration request...
🎉 Unregistration completed successfully!
📄 ✅ Successfully unregistered Math Agent (ID: Math Agent)
Agent ID: Math Agent
Remaining agents: 2代理列表
% uv run . --list_agent
Will use headers: {}
======= Agent Card ========
{"capabilities":{"pushNotifications":true,"stateTransitionHistory":false,"streaming":false},"defaultInputModes":["text"],"defaultOutputModes":["text"],"description":"Intelligent agent that routes requests to specialized agents using LangGraph and A2A protocol","name":"Smart Orchestrator Agent","skills":[{"description":"Intelligent request routing to specialized agents","id":"request_routing","name":"Request Routing","tags":["routing","orchestration"]},{"description":"Multi-agent system coordination and management","id":"agent_coordination","name":"Agent Coordination","tags":["coordination","management"]},{"description":"Skill-based agent selection and matching","id":"skill_matching","name":"Skill Matching","tags":["matching","selection"]},{"description":"Confidence scoring for routing decisions","id":"confidence_scoring","name":"Confidence Scoring","tags":["scoring","confidence"]}],"url":"http://localhost:8000/","version":"1.0.0"}
============================================================
🤖 AVAILABLE AGENTS
============================================================
Found 3 available agents:
1. ArgoCD Agent (http://localhost:8001)
Description: Handles ArgoCD and Kubernetes operations via MCP protocol
Skills: Kubernetes Management, GitOps, Application Deployment (+3 more)
2. Currency Agent (http://localhost:8002/)
Description: Handles currency exchange and financial data
Skills: Currency exchange operations, Financial data analysis, Market analysis and trends (+2 more)
3. Math Agent (http://localhost:8003/)
Description: Advanced mathematical assistant for calculations, equation solving, calculus, statistics, and matrix operations via MCP
Skills: Arithmetic Calculation, Equation Solving, Calculus Operations (+2 more)
============================================================
💡 The orchestrator will automatically route your requests to the best agent!
============================================================🛠️ 技术实现
A2A协议集成
客户端使用A2A SDK进行标准化的代理通信:
from a2a.client import A2AClient
from a2a.utils import new_agent_text_message
# Create A2A client
client = A2AClient(base_url=agent_url)
# Send message to agent
message = new_agent_text_message(user_input, context_id)
response = await client.send_message(message)推送通知支持
from orchestrator_client.utils.push_notification_listener import PushNotificationListener
# Start push notification listener
listener = PushNotificationListener(
host="localhost",
port=5000,
notification_receiver_auth=auth
)
listener.start()会话管理
# Session ID handling
session_id = args.session or str(uuid.uuid4())
context_id = f"session-{session_id}"
# Maintain conversation context
conversation_history = []📚 发展
项目结构
orchestrator_client/
├── __init__.py
├── __main__.py # CLI entry point
├── pyproject.toml # Dependencies
├── utils/
│ ├── __init__.py
│ ├── push_notification_auth.py # Push notification authentication
│ └── push_notification_listener.py # WebSocket listener
└── README.md # This file依赖项
dependencies = [
"a2a-sdk>=0.2.6,=0.25.0", # HTTP client
"starlette>=0.27.0", # WebSocket server
"uvicorn>=0.24.0", # ASGI server
"pydantic>=2.0.0", # Data validation
]🔮 未来的增强功能
- GUI界面:用于代理交互的基于Web的用户界面
- 批处理:支持批处理操作和脚本
- 代理监控:实时代理健康和性能监控
- 插件系统:用于自定义功能的可扩展插件架构
- 多语言支持:支持多种编程语言
- 高级分析:使用分析和性能洞察
📚 API 参考
主要功能
# Client initialization
client = A2AClient(base_url=agent_url)
# Send message
response = await client.send_message(message)
# Stream responses
async for chunk in client.stream_message(message):
process_chunk(chunk)命令行参数
% uv run . --help
Usage: . [OPTIONS]
Options:
--agent TEXT
--list_agent List all available agents from orchestrator
--register_agent TEXT
--unregister_agent TEXT
--session INTEGER
--history BOOLEAN
--use_push_notifications BOOLEAN
--push_notification_receiver TEXT
--header TEXT
--help Show this message and exit.🤝 贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
📄 许可证
该项目是Aichestra多智能体生态系统的一部分。有关详细信息,请参阅主存储库LICENSE文件。
______________________________________________________________________
采用A2A协议、智能路由和无缝代理集成构建 🚀
