@agentunion/kite 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +102 -0
- package/cli.js +44 -5
- package/core/dependency_checker.py +250 -0
- package/core/env_checker.py +490 -0
- package/dependencies_lock.json +128 -0
- package/extensions/agents/assistant/server.py +33 -17
- package/extensions/channels/acp_channel/server.py +33 -17
- package/extensions/services/backup/entry.py +23 -16
- package/extensions/services/evol/auth_manager.py +443 -0
- package/extensions/services/evol/config.yaml +149 -0
- package/extensions/services/evol/config_loader.py +117 -0
- package/extensions/services/evol/entry.py +406 -0
- package/extensions/services/evol/evol_api.py +173 -0
- package/extensions/services/evol/evol_config.json5 +29 -0
- package/extensions/services/evol/migrate_tokens.py +122 -0
- package/extensions/services/evol/module.md +32 -0
- package/extensions/services/evol/pairing.py +250 -0
- package/extensions/services/evol/pairing_codes.jsonl +1 -0
- package/extensions/services/evol/relay.py +682 -0
- package/extensions/services/evol/relay_config.json5 +67 -0
- package/extensions/services/evol/routes/__init__.py +1 -0
- package/extensions/services/evol/routes/routes_management_ws.py +127 -0
- package/extensions/services/evol/routes/routes_rpc.py +89 -0
- package/extensions/services/evol/routes/routes_test.py +61 -0
- package/extensions/services/evol/server.py +875 -0
- package/extensions/services/evol/static/css/style.css +1200 -0
- package/extensions/services/evol/static/index.html +781 -0
- package/extensions/services/evol/static/index_evol.html +14 -0
- package/extensions/services/evol/static/js/app.js +6304 -0
- package/extensions/services/evol/static/js/auth.js +326 -0
- package/extensions/services/evol/static/js/dialog.js +285 -0
- package/extensions/services/evol/static/js/evol-app-fixed.js +50 -0
- package/extensions/services/evol/static/js/evol-app.js +1949 -0
- package/extensions/services/evol/static/js/evol-app.js.bak +1800 -0
- package/extensions/services/evol/static/js/kernel-client-example.js +228 -0
- package/extensions/services/evol/static/js/kernel-client.js +396 -0
- package/extensions/services/evol/static/js/main.js +141 -0
- package/extensions/services/evol/static/js/registry-tests.js +585 -0
- package/extensions/services/evol/static/js/stats.js +217 -0
- package/extensions/services/evol/static/js/token-manager.js +175 -0
- package/extensions/services/evol/static/pairing.html +248 -0
- package/extensions/services/evol/static/test_registry.html +262 -0
- package/extensions/services/evol/static/test_relay.html +462 -0
- package/extensions/services/evol/stats_manager.py +240 -0
- package/extensions/services/model_service/entry.py +23 -1
- package/extensions/services/proxy/.claude/settings.local.json +13 -0
- package/extensions/services/proxy/CHANGELOG_20260308.md +258 -0
- package/extensions/services/proxy/_fix_prints.py +133 -0
- package/extensions/services/proxy/_fix_prints2.py +87 -0
- package/extensions/services/proxy/agentcp/LICENCE +178 -0
- package/extensions/services/proxy/agentcp/README copy.md +85 -0
- package/extensions/services/proxy/agentcp/README.md +260 -0
- package/extensions/services/proxy/agentcp/__init__.py +16 -0
- package/extensions/services/proxy/agentcp/agent.py +4 -0
- package/extensions/services/proxy/agentcp/agentcp.py +2494 -0
- package/extensions/services/proxy/agentcp/agentprofile.json +89 -0
- package/extensions/services/proxy/agentcp/ap/__init__.py +16 -0
- package/extensions/services/proxy/agentcp/ap/ap_client.py +316 -0
- package/extensions/services/proxy/agentcp/assets/images/wechat_qr.png +0 -0
- package/extensions/services/proxy/agentcp/backup/metrics.json +31 -0
- package/extensions/services/proxy/agentcp/base/__init__.py +20 -0
- package/extensions/services/proxy/agentcp/base/auth_client.py +257 -0
- package/extensions/services/proxy/agentcp/base/client.py +112 -0
- package/extensions/services/proxy/agentcp/base/env.py +34 -0
- package/extensions/services/proxy/agentcp/base/html_util.py +336 -0
- package/extensions/services/proxy/agentcp/base/log.py +98 -0
- package/extensions/services/proxy/agentcp/ca/__init__.py +17 -0
- package/extensions/services/proxy/agentcp/ca/ca_client.py +414 -0
- package/extensions/services/proxy/agentcp/ca/ca_root.py +74 -0
- package/extensions/services/proxy/agentcp/context/__init__.py +20 -0
- package/extensions/services/proxy/agentcp/context/context.py +73 -0
- package/extensions/services/proxy/agentcp/context/exceptions.py +114 -0
- package/extensions/services/proxy/agentcp/create_profile.py +125 -0
- package/extensions/services/proxy/agentcp/create_profile_weather.py +125 -0
- package/extensions/services/proxy/agentcp/db/__init__.py +15 -0
- package/extensions/services/proxy/agentcp/db/db_mananger.py +550 -0
- package/extensions/services/proxy/agentcp/docs/UDP_HEARTBEAT_FIX_REPORT.md +265 -0
- package/extensions/services/proxy/agentcp/docs/heartbeat_issue_analysis.md +291 -0
- package/extensions/services/proxy/agentcp/file/__init__.py +16 -0
- package/extensions/services/proxy/agentcp/file/file_client.py +141 -0
- package/extensions/services/proxy/agentcp/file/wss_binary_message.py +137 -0
- package/extensions/services/proxy/agentcp/hcp.py +299 -0
- package/extensions/services/proxy/agentcp/heartbeat/__init__.py +16 -0
- package/extensions/services/proxy/agentcp/heartbeat/heartbeat_client.py +360 -0
- package/extensions/services/proxy/agentcp/improved_scheduler.py +498 -0
- package/extensions/services/proxy/agentcp/llm_agent_utils.py +249 -0
- package/extensions/services/proxy/agentcp/llm_server.py +172 -0
- package/extensions/services/proxy/agentcp/mermaid.py +210 -0
- package/extensions/services/proxy/agentcp/message.py +149 -0
- package/extensions/services/proxy/agentcp/metrics.py +256 -0
- package/extensions/services/proxy/agentcp/monitoring/__init__.py +20 -0
- package/extensions/services/proxy/agentcp/monitoring/global_monitor.py +27 -0
- package/extensions/services/proxy/agentcp/monitoring/metrics_store.py +325 -0
- package/extensions/services/proxy/agentcp/monitoring/monitoring_service.py +269 -0
- package/extensions/services/proxy/agentcp/monitoring/sliding_window.py +222 -0
- package/extensions/services/proxy/agentcp/monitoring/standalone_reader.py +224 -0
- package/extensions/services/proxy/agentcp/msg/__init__.py +21 -0
- package/extensions/services/proxy/agentcp/msg/connection_manager.py +456 -0
- package/extensions/services/proxy/agentcp/msg/message_client.py +2058 -0
- package/extensions/services/proxy/agentcp/msg/message_serialize.py +263 -0
- package/extensions/services/proxy/agentcp/msg/open_ai_message.py +88 -0
- package/extensions/services/proxy/agentcp/msg/session_manager.py +1062 -0
- package/extensions/services/proxy/agentcp/msg/stream_client.py +267 -0
- package/extensions/services/proxy/agentcp/msg/websocket_file_receiver.py +89 -0
- package/extensions/services/proxy/agentcp/msg/ws_logger.py +685 -0
- package/extensions/services/proxy/agentcp/msg/wss_binary_message.py +137 -0
- package/extensions/services/proxy/agentcp/requirements.txt +7 -0
- package/extensions/services/proxy/agentcp/samples/agent_graph/README.md +37 -0
- package/extensions/services/proxy/agentcp/samples/agent_graph/agentprofile.json +89 -0
- package/extensions/services/proxy/agentcp/samples/agent_graph/create_profile.py +138 -0
- package/extensions/services/proxy/agentcp/samples/agent_graph/main.py +164 -0
- package/extensions/services/proxy/agentcp/samples/agent_use/create_profile.py +123 -0
- package/extensions/services/proxy/agentcp/samples/agent_use/llm/create_profile.py +129 -0
- package/extensions/services/proxy/agentcp/samples/agent_use/llm/env.json +5 -0
- package/extensions/services/proxy/agentcp/samples/agent_use/llm/main.py +146 -0
- package/extensions/services/proxy/agentcp/samples/agent_use/main.py +123 -0
- package/extensions/services/proxy/agentcp/samples/agent_use/readme.md +379 -0
- package/extensions/services/proxy/agentcp/samples/agent_use/search/create_profile.py +129 -0
- package/extensions/services/proxy/agentcp/samples/agent_use/search/main.py +28 -0
- package/extensions/services/proxy/agentcp/samples/agent_use/tool/create_profile.py +129 -0
- package/extensions/services/proxy/agentcp/samples/agent_use/tool/main.py +20 -0
- package/extensions/services/proxy/agentcp/samples/ali_amap/README.md +97 -0
- package/extensions/services/proxy/agentcp/samples/ali_amap/amap_agent.py +88 -0
- package/extensions/services/proxy/agentcp/samples/ali_amap/create_profile.py +125 -0
- package/extensions/services/proxy/agentcp/samples/compute_agent/agent/powershell.py +228 -0
- package/extensions/services/proxy/agentcp/samples/compute_agent/agent/software.py +63 -0
- package/extensions/services/proxy/agentcp/samples/compute_agent/agent/tools.py +36 -0
- package/extensions/services/proxy/agentcp/samples/compute_agent/browser_user.py +41 -0
- package/extensions/services/proxy/agentcp/samples/deepseek/README.md +79 -0
- package/extensions/services/proxy/agentcp/samples/deepseek/create_profile.py +126 -0
- package/extensions/services/proxy/agentcp/samples/deepseek/deepseek.py +42 -0
- package/extensions/services/proxy/agentcp/samples/dify_chat/README.md +78 -0
- package/extensions/services/proxy/agentcp/samples/dify_chat/create_profile.py +126 -0
- package/extensions/services/proxy/agentcp/samples/dify_chat/dify_chat.py +47 -0
- package/extensions/services/proxy/agentcp/samples/dify_workflow/README.md +78 -0
- package/extensions/services/proxy/agentcp/samples/dify_workflow/create_profile.py +126 -0
- package/extensions/services/proxy/agentcp/samples/dify_workflow/dify_workflow.py +46 -0
- package/extensions/services/proxy/agentcp/samples/executor/README.md +44 -0
- package/extensions/services/proxy/agentcp/samples/executor/agentprofile.json +89 -0
- package/extensions/services/proxy/agentcp/samples/executor/create_profile.py +139 -0
- package/extensions/services/proxy/agentcp/samples/executor/main.py +160 -0
- package/extensions/services/proxy/agentcp/samples/filereader/README.md +45 -0
- package/extensions/services/proxy/agentcp/samples/filereader/agentprofile.json +90 -0
- package/extensions/services/proxy/agentcp/samples/filereader/create_profile.py +137 -0
- package/extensions/services/proxy/agentcp/samples/filereader/main.py +253 -0
- package/extensions/services/proxy/agentcp/samples/filewriter/README.md +38 -0
- package/extensions/services/proxy/agentcp/samples/filewriter/agentprofile.json +91 -0
- package/extensions/services/proxy/agentcp/samples/filewriter/create_profile.py +138 -0
- package/extensions/services/proxy/agentcp/samples/filewriter/main.py +289 -0
- package/extensions/services/proxy/agentcp/samples/hcp/README.md +85 -0
- package/extensions/services/proxy/agentcp/samples/hcp/acp_weather_agent.zip +0 -0
- package/extensions/services/proxy/agentcp/samples/hcp/create_profile.py +125 -0
- package/extensions/services/proxy/agentcp/samples/hcp/hcp.py +237 -0
- package/extensions/services/proxy/agentcp/samples/helloworld/README.md +68 -0
- package/extensions/services/proxy/agentcp/samples/helloworld/hello_world.py +40 -0
- package/extensions/services/proxy/agentcp/samples/llm_agent/MEADME.md +117 -0
- package/extensions/services/proxy/agentcp/samples/llm_agent/create_profile.py +125 -0
- package/extensions/services/proxy/agentcp/samples/llm_agent/qwen_agent.py +136 -0
- package/extensions/services/proxy/agentcp/samples/local_llm_agent/README.md +90 -0
- package/extensions/services/proxy/agentcp/samples/local_llm_agent/create_profile.py +125 -0
- package/extensions/services/proxy/agentcp/samples/local_llm_agent/main.py +49 -0
- package/extensions/services/proxy/agentcp/samples/query_llm_from_agent/README.md +55 -0
- package/extensions/services/proxy/agentcp/samples/query_llm_from_agent/create_profile.py +125 -0
- package/extensions/services/proxy/agentcp/samples/query_llm_from_agent/main.py +23 -0
- package/extensions/services/proxy/agentcp/samples/query_weather_api_agent/README.md +103 -0
- package/extensions/services/proxy/agentcp/samples/query_weather_api_agent/create_profile.py +125 -0
- package/extensions/services/proxy/agentcp/samples/query_weather_api_agent/main.py +69 -0
- package/extensions/services/proxy/agentcp/samples/query_weather_from_agent/README.md +58 -0
- package/extensions/services/proxy/agentcp/samples/query_weather_from_agent/create_profile.py +125 -0
- package/extensions/services/proxy/agentcp/samples/query_weather_from_agent/main.py +25 -0
- package/extensions/services/proxy/agentcp/samples/qwen3/README.md +71 -0
- package/extensions/services/proxy/agentcp/samples/qwen3/create_profile.py +126 -0
- package/extensions/services/proxy/agentcp/samples/qwen3/qwen3.py +37 -0
- package/extensions/services/proxy/agentcp/samples/qwen3_tools/README.md +133 -0
- package/extensions/services/proxy/agentcp/samples/qwen3_tools/create_profile.py +126 -0
- package/extensions/services/proxy/agentcp/samples/qwen3_tools/qwen3_tools.py +98 -0
- package/extensions/services/proxy/agentcp/samples/search/create_profile_qwen.py +125 -0
- package/extensions/services/proxy/agentcp/samples/search/create_profile_search.py +125 -0
- package/extensions/services/proxy/agentcp/samples/search/qwen_agent.py +136 -0
- package/extensions/services/proxy/agentcp/samples/search/search_agent.py +170 -0
- package/extensions/services/proxy/agentcp/samples/wrapper_agently_to_agent/README.md +89 -0
- package/extensions/services/proxy/agentcp/samples/wrapper_agently_to_agent/create_profile.py +125 -0
- package/extensions/services/proxy/agentcp/samples/wrapper_agently_to_agent/main.py +44 -0
- package/extensions/services/proxy/agentcp/utils/__init__.py +15 -0
- package/extensions/services/proxy/agentcp/utils/file_util.py +117 -0
- package/extensions/services/proxy/agentcp/utils/proxy_bypass.py +99 -0
- package/extensions/services/proxy/agentcp/workflow.py +203 -0
- package/extensions/services/proxy/console_auth.py +109 -0
- package/extensions/services/proxy/evol/__init__.py +1 -0
- package/extensions/services/proxy/evol/config.py +37 -0
- package/extensions/services/proxy/evol/http/__init__.py +1 -0
- package/extensions/services/proxy/evol/http/async_http.py +551 -0
- package/extensions/services/proxy/evol/log.py +28 -0
- package/extensions/services/proxy/evol/presenter/__init__.py +2 -0
- package/extensions/services/proxy/evol/presenter/agentIdPresenter.py +1031 -0
- package/extensions/services/proxy/evol/presenter/apikeyPresenter.py +106 -0
- package/extensions/services/proxy/evol/presenter/configPresenter.py +1281 -0
- package/extensions/services/proxy/evol/presenter/userPresenter.py +477 -0
- package/extensions/services/proxy/evol/server/__init__.py +1 -0
- package/extensions/services/proxy/evol/server/claude_proxy_async.py +3430 -0
- package/extensions/services/proxy/evol/server/openclaw_proxy.py +1861 -0
- package/extensions/services/proxy/evol/server/proxy_config.py +15 -0
- package/extensions/services/proxy/evol/server/proxy_engine.py +501 -0
- package/extensions/services/proxy/evol/version.py +24 -0
- package/extensions/services/proxy/logs/websocket.log +260 -0
- package/extensions/services/proxy/main.py +240 -0
- package/extensions/services/proxy/requirements.txt +13 -0
- package/extensions/services/proxy/server.py +271 -0
- package/extensions/services/watchdog/entry.py +42 -16
- package/extensions/services/watchdog/module.md +1 -0
- package/extensions/services/watchdog/monitor.py +34 -4
- package/extensions/services/web/module.md +1 -1
- package/extensions/services/web/server.py +30 -18
- package/extensions/services/web/static/js/token-manager.js +10 -10
- package/kernel/entry.py +1 -1
- package/kernel/module.md +25 -1
- package/kernel/registry_store.py +2 -26
- package/kernel/rpc_router.py +36 -10
- package/kernel/server.py +106 -17
- package/kite_cli/commands/deps_install.py +67 -0
- package/kite_cli/commands/env_check.py +45 -0
- package/kite_cli/commands/prepare.py +49 -0
- package/kite_cli/commands/venv_setup.py +56 -0
- package/kite_cli/main.py +29 -1
- package/launcher/entry.py +306 -21
- package/launcher/module.md +9 -0
- package/launcher/module_scanner.py +11 -1
- package/main.py +4 -1
- package/package.json +8 -1
- package/python_version.json +4 -0
- package/requirements.txt +38 -0
- package/scripts/env-manager.js +328 -0
- package/scripts/python-env.js +79 -0
- package/scripts/scan_dependencies.py +461 -0
- package/scripts/setup-python-env.js +191 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
# github
|
|
2
|
+
[https://github.com/auliwenjiang/agentcp/blob/master/samples/agent_use/main.py](https://github.com/auliwenjiang/agentcp/blob/master/samples/agent_use/main.py)
|
|
3
|
+
|
|
4
|
+
# README.md
|
|
5
|
+
|
|
6
|
+
## 1、使用指南
|
|
7
|
+
### 1)、创建4个agent身份
|
|
8
|
+
请参考[一、创建身份,读写公有私有数据](https://ccnz88r91l2y.feishu.cn/wiki/I5F4whGuFioqwNkfJ45c8ZQ3nGf)
|
|
9
|
+
- 运行create_profile.py,创建DEMO_AGENT_AID
|
|
10
|
+
- 运行llm/create_profile.py,创建大模型Agent LLM_AGENT_AID
|
|
11
|
+
- 运行search/create_profile.py,创建智能体发现Agent SEARCH_AGENT_AID
|
|
12
|
+
- 运行tool/create_profile.py,创建工具Agent TOOL_AGENT_AID
|
|
13
|
+
|
|
14
|
+
### 2)、修改main.py文件
|
|
15
|
+
- 将main.py llm/main.py search/main.py tool/main.py里的seed_password、_my_aid修改为步骤1)创建的身份信息
|
|
16
|
+
- 将main.py里的llm_agent_id修改为LLM_AGENT_AID,search_agent_id修改为SEARCH_AGENT_AID
|
|
17
|
+
- 将search/main.py里的agent_id修改为TOOL_AGENT_AID
|
|
18
|
+
- 注意同级目录里的main.py和create_profile.py里的 AgentCP()参数要保持一致
|
|
19
|
+
### 3)、 配置文件
|
|
20
|
+
在llm目录下创建env.json,添加大模型的配置
|
|
21
|
+
``` json
|
|
22
|
+
{
|
|
23
|
+
"API_KEY":"大模型的api_key",
|
|
24
|
+
"BASE_URL":"大模型Api接口URL",
|
|
25
|
+
"MODEL":"模型名称"
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
### 4)、安装依赖项
|
|
29
|
+
```bash
|
|
30
|
+
pip install agentcp OpenAI
|
|
31
|
+
```
|
|
32
|
+
### 5)、执行代码
|
|
33
|
+
```bash
|
|
34
|
+
cd tool && python main.py
|
|
35
|
+
cd llm && python main.py
|
|
36
|
+
cd search && python main.py
|
|
37
|
+
python main.py
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 2、功能简介
|
|
41
|
+
该Agent基于agentcp库实现了一个串并行调用的智能体(Agent),支持消息处理、工具检索、多工具并行调用以及与外部Agent的通信。
|
|
42
|
+
- 创建一个Agent身份(_my_aid)
|
|
43
|
+
- 实现Agent接收用户输入的自然语言文本
|
|
44
|
+
- 根据用户输入调用智能体发现Agent(search_agent_id),寻找相关的Agent
|
|
45
|
+
- 把相关的Agent按照function call方式组装,发给大模型Agent(llm_agent_id)进行工具选择
|
|
46
|
+
- 根据大模型Agent返回的工具集列(tool_agent_id)表进行回调,把结果返回给用户
|
|
47
|
+
|
|
48
|
+
## 3、完整示例代码
|
|
49
|
+
### 1)、main.py
|
|
50
|
+
```python
|
|
51
|
+
import json
|
|
52
|
+
import time
|
|
53
|
+
import traceback
|
|
54
|
+
|
|
55
|
+
import agentcp
|
|
56
|
+
|
|
57
|
+
"""
|
|
58
|
+
智能体搜索 使用大模型agent实现工具选择 多工具并行调用
|
|
59
|
+
"""
|
|
60
|
+
class Agent:
|
|
61
|
+
def __init__(self):
|
|
62
|
+
self.agentid = None
|
|
63
|
+
self.acp = agentcp.AgentCP("../data",seed_password="")
|
|
64
|
+
self.llm_agent_id = "llmdemo007.agentunion.cn"
|
|
65
|
+
self.search_agent_id = "search007.agentunion.cn"
|
|
66
|
+
async def async_message_handler(self, msg):
|
|
67
|
+
try:
|
|
68
|
+
receiver = self.agentid.get_receiver_from_message(msg)
|
|
69
|
+
if self.agentid.id not in receiver:
|
|
70
|
+
print("不是发给我的消息,不处理")
|
|
71
|
+
return
|
|
72
|
+
sender = self.agentid.get_sender_from_message(msg)
|
|
73
|
+
session_id = self.agentid.get_session_id_from_message(msg)
|
|
74
|
+
to_aid_list = [sender]
|
|
75
|
+
|
|
76
|
+
# 获取输入
|
|
77
|
+
llm_content = self.agentid.get_content_from_message(msg)
|
|
78
|
+
print(f"llm_content={llm_content}\n")
|
|
79
|
+
|
|
80
|
+
# 调用工具选择agent
|
|
81
|
+
self.mult_tool_choose(llm_content,session_id,to_aid_list)
|
|
82
|
+
except Exception as e:
|
|
83
|
+
print(f"处理消息时发生错误: {e}\n完整堆栈跟踪:\n{traceback.format_exc()}")
|
|
84
|
+
|
|
85
|
+
async def reply_message_handler(self,reply_msg,session_id,to_aid_list):
|
|
86
|
+
content = []
|
|
87
|
+
print(f"模型返回结果{reply_msg}")
|
|
88
|
+
message_json = json.loads(reply_msg.get("message"))
|
|
89
|
+
if isinstance(message_json, list) and len(message_json) > 0:
|
|
90
|
+
content = message_json
|
|
91
|
+
message_json = message_json[0]
|
|
92
|
+
# 根据大模型返回结果 决定是否调用其他agent
|
|
93
|
+
if message_json.get("type") == "tool_call":
|
|
94
|
+
print(f"使用工具 {content}")
|
|
95
|
+
await self.mult_tool_call(content,session_id, to_aid_list)
|
|
96
|
+
else:
|
|
97
|
+
self.agentid.send_message_content(session_id, to_aid_list, self.agentid.get_content_from_message(reply_msg))
|
|
98
|
+
return
|
|
99
|
+
|
|
100
|
+
def mult_tool_choose(self,llm_content,session_id,to_aid_list):
|
|
101
|
+
def search_agent_handler(search_msg):
|
|
102
|
+
result = self.agentid.get_content_from_message(search_msg)
|
|
103
|
+
print(f"search result={result}")
|
|
104
|
+
agents = json.loads(result)
|
|
105
|
+
tools = []
|
|
106
|
+
for ainfo in agents:
|
|
107
|
+
description = f"我是{ainfo['agent_id']},我能提供[{ainfo['description']}]服务,我的aid是{ainfo['agent_id']}"
|
|
108
|
+
tools.append({
|
|
109
|
+
"type": "function",
|
|
110
|
+
"function": {
|
|
111
|
+
"name": "agent_" + ainfo['agent_id'],
|
|
112
|
+
"description": description,
|
|
113
|
+
"parameters": {
|
|
114
|
+
"type": "object",
|
|
115
|
+
"properties": {
|
|
116
|
+
"aid": {
|
|
117
|
+
"type": "string",
|
|
118
|
+
"description": "",
|
|
119
|
+
},
|
|
120
|
+
"text": {
|
|
121
|
+
"type": "string",
|
|
122
|
+
"description": ""
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"required": ["aid", "text"]
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
msg_block = {
|
|
131
|
+
"type": "content",
|
|
132
|
+
"status": "success",
|
|
133
|
+
"timestamp": int(time.time() * 1000),
|
|
134
|
+
"content": llm_content,
|
|
135
|
+
"tools": tools,
|
|
136
|
+
"prompt": ""
|
|
137
|
+
}
|
|
138
|
+
self.agentid.quick_send_messsage(self.llm_agent_id, msg_block,
|
|
139
|
+
lambda reply_msg: self.reply_message_handler(reply_msg, session_id,
|
|
140
|
+
to_aid_list))
|
|
141
|
+
|
|
142
|
+
self.agentid.quick_send_messsage_content(self.search_agent_id, llm_content,search_agent_handler)
|
|
143
|
+
|
|
144
|
+
async def mult_tool_call(self,content,session_id, to_aid_list) :
|
|
145
|
+
for tool_call in content:
|
|
146
|
+
tool = json.loads(tool_call.get("content"))
|
|
147
|
+
tool_args = tool.get("tool_args")
|
|
148
|
+
print(f"aiddddddd={tool_args['aid']} text={tool_args['text']}")
|
|
149
|
+
async def async_func_call_result(message):
|
|
150
|
+
tool_result = self.agentid.get_content_from_message(message)
|
|
151
|
+
print(f"工具返回的结果={tool_result}")
|
|
152
|
+
self.agentid.send_message_content(session_id,to_aid_list, tool_result)
|
|
153
|
+
# self.agentid.quick_send_messsage_content(self.llm_agent_id, tool_result,
|
|
154
|
+
# lambda reply_msg: self.reply_message_handler(reply_msg,session_id,to_aid_list))
|
|
155
|
+
return
|
|
156
|
+
self.agentid.quick_send_messsage_content(tool_args["aid"], tool_args["text"], async_func_call_result)
|
|
157
|
+
|
|
158
|
+
if __name__ == "__main__":
|
|
159
|
+
_my_aid = "mc58009.aid.pub"
|
|
160
|
+
|
|
161
|
+
agent = Agent()
|
|
162
|
+
agent.agentid =agent.acp.load_aid(_my_aid)
|
|
163
|
+
async def sync_message_handler(msg):
|
|
164
|
+
print(f"收到消息数据: {msg}")
|
|
165
|
+
await agent.async_message_handler(msg) # 添加await关键字
|
|
166
|
+
return True
|
|
167
|
+
try:
|
|
168
|
+
agent.agentid.online()
|
|
169
|
+
# agent.agentid.sync_public_files()
|
|
170
|
+
agent.agentid.add_message_handler(sync_message_handler)
|
|
171
|
+
agent.acp.serve_forever()
|
|
172
|
+
except Exception as e:
|
|
173
|
+
print(f"AgentID未正确初始化: {e}")
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 2)、tool/main.py
|
|
177
|
+
```
|
|
178
|
+
import agentcp
|
|
179
|
+
|
|
180
|
+
if __name__ == "__main__":
|
|
181
|
+
acp = agentcp.AgentCP("../../data")
|
|
182
|
+
_my_aid = "testdemo11.aid.pub"
|
|
183
|
+
aid = acp.load_aid(_my_aid)
|
|
184
|
+
@aid.message_handler()
|
|
185
|
+
async def sync_message_handler(msg):
|
|
186
|
+
receiver = aid.get_receiver_from_message(msg)
|
|
187
|
+
if aid.id not in receiver:
|
|
188
|
+
return None
|
|
189
|
+
session_id = aid.get_session_id_from_message(msg)
|
|
190
|
+
sender = aid.get_sender_from_message(msg)
|
|
191
|
+
content = "我是天气Agent,今天气温39摄氏度,晴天"
|
|
192
|
+
aid.send_message_content(session_id, [sender], content)
|
|
193
|
+
return True
|
|
194
|
+
aid.online()
|
|
195
|
+
# aid.sync_public_files()
|
|
196
|
+
print("已上线完成")
|
|
197
|
+
acp.serve_forever()
|
|
198
|
+
```
|
|
199
|
+
### 3)、llm/main.py
|
|
200
|
+
```
|
|
201
|
+
import json
|
|
202
|
+
import time
|
|
203
|
+
|
|
204
|
+
import agentcp
|
|
205
|
+
from openai import OpenAI
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class QwenClient:
|
|
209
|
+
def __init__(self):
|
|
210
|
+
self.openai_api_key = None
|
|
211
|
+
self.base_url = None
|
|
212
|
+
self.model = None
|
|
213
|
+
self.client = None
|
|
214
|
+
self.acp = agentcp.AgentCP("../../data", seed_password="", debug=True)
|
|
215
|
+
self.agentid: agentcp.AgentID = None
|
|
216
|
+
|
|
217
|
+
def init_ai_client(self, json_data):
|
|
218
|
+
# 从环境变量中获取 API Key 和 Base URL
|
|
219
|
+
self.openai_api_key = json_data.get("API_KEY", "")
|
|
220
|
+
self.base_url = json_data.get("BASE_URL", "")
|
|
221
|
+
self.model = json_data.get("MODEL", "")
|
|
222
|
+
self.client = OpenAI(api_key=self.openai_api_key, base_url=self.base_url)
|
|
223
|
+
|
|
224
|
+
async def async_message_handler(self, message_data):
|
|
225
|
+
try:
|
|
226
|
+
receiver = message_data.get("receiver")
|
|
227
|
+
sender = message_data.get("sender", "") # 获取工具信息
|
|
228
|
+
if self.agentid.id not in receiver:
|
|
229
|
+
print("不是发给我的消息,不处理")
|
|
230
|
+
return
|
|
231
|
+
message_array = self.agentid.get_content_array_from_message(message_data)
|
|
232
|
+
if len(message_array) == 0:
|
|
233
|
+
print("消息内容为空,不处理")
|
|
234
|
+
return
|
|
235
|
+
llm_content = self.agentid.get_content_from_message(message_data)
|
|
236
|
+
stream = message_array[0].get("stream", False) # 获取stream信息
|
|
237
|
+
tools = message_array[0].get("tools", []) # 获取工具信息
|
|
238
|
+
rolesetting = message_array[0].get("prompt", "") # 获取工具信息
|
|
239
|
+
if rolesetting != "" and rolesetting != None:
|
|
240
|
+
messages = [{"role": "system", "content": rolesetting}, {"role": "user", "content": llm_content}]
|
|
241
|
+
else:
|
|
242
|
+
messages = [{"role": "user", "content": llm_content}]
|
|
243
|
+
print(f"\n[处理消息: {sender} : {llm_content}]\n")
|
|
244
|
+
await self.stream_process_query(message_data, messages, sender, stream, tools) # 添加await关键字
|
|
245
|
+
except Exception as e:
|
|
246
|
+
import traceback
|
|
247
|
+
print(f"处理消息时发生错误: {e}\n完整堆栈跟踪:\n{traceback.format_exc()}")
|
|
248
|
+
|
|
249
|
+
def send_message_tools_call(self, session_id, sender, llm_content: str, funcallback):
|
|
250
|
+
to_aid_list = [sender]
|
|
251
|
+
msg_block = {
|
|
252
|
+
"type": "tool_call",
|
|
253
|
+
"status": "success",
|
|
254
|
+
"timestamp": int(time.time() * 1000),
|
|
255
|
+
"content": llm_content,
|
|
256
|
+
}
|
|
257
|
+
self.agentid.add_message_handler(funcallback, session_id)
|
|
258
|
+
self.agentid.send_message(session_id, to_aid_list, msg_block)
|
|
259
|
+
|
|
260
|
+
async def stream_process_query(self, message_data: dict, messages: list, sender: str, stream: bool,
|
|
261
|
+
user_tools: list):
|
|
262
|
+
if user_tools is None:
|
|
263
|
+
user_tools = [] # 确保tools是一个列表,即使它为空
|
|
264
|
+
if len(user_tools) > 0:
|
|
265
|
+
response = self.client.chat.completions.create(
|
|
266
|
+
model=self.model,
|
|
267
|
+
messages=messages,
|
|
268
|
+
stream=stream,
|
|
269
|
+
tools=user_tools
|
|
270
|
+
)
|
|
271
|
+
else:
|
|
272
|
+
response = self.client.chat.completions.create(
|
|
273
|
+
model=self.model,
|
|
274
|
+
messages=messages,
|
|
275
|
+
stream=stream
|
|
276
|
+
)
|
|
277
|
+
session_id = message_data.get("session_id", "") # 获取session_id
|
|
278
|
+
content = response.choices[0]
|
|
279
|
+
if content.finish_reason == "tool_calls":
|
|
280
|
+
tool_call = content.message.tool_calls[0]
|
|
281
|
+
tool_name = tool_call.function.name
|
|
282
|
+
tool_args = json.loads(tool_call.function.arguments)
|
|
283
|
+
print(f"\n[Calling tool {tool_name} with args {tool_args}]\n")
|
|
284
|
+
|
|
285
|
+
async def funcallback(result_content):
|
|
286
|
+
self.agentid.remove_message_handler(funcallback, session_id)
|
|
287
|
+
messages.append(content.message.model_dump())
|
|
288
|
+
messages.append({
|
|
289
|
+
"role": "tool",
|
|
290
|
+
"content": self.agentid.get_content_from_message(result_content),
|
|
291
|
+
"tool_call_id": tool_call.id,
|
|
292
|
+
})
|
|
293
|
+
await self.stream_process_query(message_data, messages, sender, stream, user_tools)
|
|
294
|
+
|
|
295
|
+
tool_content = {
|
|
296
|
+
'tool_name': tool_name,
|
|
297
|
+
'tool_args': tool_args,
|
|
298
|
+
}
|
|
299
|
+
self.send_message_tools_call(session_id, sender, json.dumps(tool_content), funcallback)
|
|
300
|
+
return
|
|
301
|
+
if stream:
|
|
302
|
+
await self.agentid.send_stream_message(message_data.get("session_id"), [sender], response) # 确保正确调用
|
|
303
|
+
else:
|
|
304
|
+
return self.agentid.reply_message(message_data, content.message.content)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def main():
|
|
308
|
+
client = QwenClient()
|
|
309
|
+
print("欢迎使用 AGENT!")
|
|
310
|
+
_my_aid = "llmdemo007.aid.pub"
|
|
311
|
+
try:
|
|
312
|
+
client.agentid = client.acp.load_aid(_my_aid)
|
|
313
|
+
|
|
314
|
+
@client.agentid.message_handler()
|
|
315
|
+
async def sync_message_handler(msg):
|
|
316
|
+
await client.async_message_handler(msg) # 添加await关键字
|
|
317
|
+
return True
|
|
318
|
+
|
|
319
|
+
print("开始在线...")
|
|
320
|
+
env_path = "./env.json"
|
|
321
|
+
# 新增文件读取逻辑
|
|
322
|
+
try:
|
|
323
|
+
with open(env_path, 'r', encoding='utf-8') as f:
|
|
324
|
+
env_data = json.load(f)
|
|
325
|
+
client.init_ai_client(env_data)
|
|
326
|
+
print(f"成功加载配置文件: {env_path}")
|
|
327
|
+
except FileNotFoundError:
|
|
328
|
+
print(f"配置文件 {env_path} 未找到")
|
|
329
|
+
exit(1)
|
|
330
|
+
except json.JSONDecodeError:
|
|
331
|
+
print(f"配置文件 {env_path} 格式错误")
|
|
332
|
+
exit(1)
|
|
333
|
+
except Exception as e:
|
|
334
|
+
print(f"加载配置失败: {str(e)}")
|
|
335
|
+
exit(1)
|
|
336
|
+
client.agentid.online() # 确保self.agentid不为None
|
|
337
|
+
private_path = client.agentid.get_agent_private_path() # 获取私钥路径
|
|
338
|
+
print("开始监听消息...")
|
|
339
|
+
client.acp.serve_forever()
|
|
340
|
+
except Exception as e:
|
|
341
|
+
import traceback
|
|
342
|
+
print(f"\n⚠️ 发生错误: {traceback.format_exc()}") # 添加堆栈信息打印
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
if __name__ == "__main__":
|
|
346
|
+
main()
|
|
347
|
+
```
|
|
348
|
+
### 4)、search/main.py
|
|
349
|
+
```
|
|
350
|
+
import json
|
|
351
|
+
|
|
352
|
+
import agentcp
|
|
353
|
+
|
|
354
|
+
if __name__ == "__main__":
|
|
355
|
+
acp = agentcp.AgentCP("../data")
|
|
356
|
+
_my_aid = "search007.aid.pub"
|
|
357
|
+
aid = acp.load_aid(_my_aid)
|
|
358
|
+
@aid.message_handler()
|
|
359
|
+
async def sync_message_handler(msg):
|
|
360
|
+
receiver = aid.get_receiver_from_message(msg)
|
|
361
|
+
if aid.id not in receiver:
|
|
362
|
+
return None
|
|
363
|
+
session_id = aid.get_session_id_from_message(msg)
|
|
364
|
+
sender = aid.get_sender_from_message(msg)
|
|
365
|
+
agents = [
|
|
366
|
+
{
|
|
367
|
+
"agent_id": "testdemo11.aid.pub",
|
|
368
|
+
"name":"我是天气Agent,我提供天气信息",
|
|
369
|
+
"description":"我是天气Agent,我提供天气信息",
|
|
370
|
+
},
|
|
371
|
+
]
|
|
372
|
+
aid.send_message_content(session_id, [sender], json.dumps(agents))
|
|
373
|
+
return True
|
|
374
|
+
aid.online()
|
|
375
|
+
# aid.sync_public_files()
|
|
376
|
+
print("已上线完成")
|
|
377
|
+
acp.serve_forever()
|
|
378
|
+
```
|
|
379
|
+
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from datetime import datetime, timezone
|
|
3
|
+
from pathlib import Path # 新增导入
|
|
4
|
+
|
|
5
|
+
import agentcp
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def create_financial_analyzer_json(publisherInfo):
|
|
9
|
+
"""创建智能体能力、权限描述"""
|
|
10
|
+
name = "模拟智能体搜索Agent"
|
|
11
|
+
profile_json_data = {
|
|
12
|
+
"publisherInfo": publisherInfo,
|
|
13
|
+
"avaUrl": "https://t8.baidu.com/it/u=532698156,91822327&fm=193",
|
|
14
|
+
"version": "1.0.0",
|
|
15
|
+
"lastUpdated": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
16
|
+
"name": name,
|
|
17
|
+
"description": name,
|
|
18
|
+
"capabilities": {
|
|
19
|
+
"core": [name],
|
|
20
|
+
"extended": []
|
|
21
|
+
},
|
|
22
|
+
"llm":{
|
|
23
|
+
"model":"", #模型名称,或使用aid
|
|
24
|
+
"num_parameters":"", #模型参数量(如"7B"表示70亿参数)
|
|
25
|
+
"quantization_bits":"", #量化位数(如Q4表示4位量化)
|
|
26
|
+
"context_length":"", #上下文长度(如"4096"表示4096个token)
|
|
27
|
+
},
|
|
28
|
+
"references": {
|
|
29
|
+
"knowledgeBases": [""],
|
|
30
|
+
"tools": [""],
|
|
31
|
+
"companyInfo": [""],
|
|
32
|
+
"productInfo": [""]
|
|
33
|
+
},
|
|
34
|
+
"authorization": {
|
|
35
|
+
"modes": ["free"],
|
|
36
|
+
"fee": {},
|
|
37
|
+
"description": "当前智能体免费使用,无费用",
|
|
38
|
+
"sla": {}
|
|
39
|
+
},
|
|
40
|
+
"input": {
|
|
41
|
+
"types": ["content"], # 目前支持"content", "search", "reasoning_content", "error", 'file',后续会支持语音视频流
|
|
42
|
+
"formats": ["json"], # 详细类型
|
|
43
|
+
"examples": {
|
|
44
|
+
"type": "content",
|
|
45
|
+
"format": "text",
|
|
46
|
+
"content": "搜索智能体:xxx"
|
|
47
|
+
},
|
|
48
|
+
"semantics": [""],
|
|
49
|
+
"compatibleAids": ["*"]
|
|
50
|
+
},
|
|
51
|
+
"output": {
|
|
52
|
+
"types": ["content"],
|
|
53
|
+
"formats": ["markdown"],
|
|
54
|
+
"examples": {
|
|
55
|
+
"type": "content",
|
|
56
|
+
"format": "markdown",
|
|
57
|
+
"content": ""
|
|
58
|
+
},
|
|
59
|
+
"semantics": [""],
|
|
60
|
+
"compatibleAids": [""]
|
|
61
|
+
},
|
|
62
|
+
"supportStream": True, # False代表当前智能体不支持流式输出
|
|
63
|
+
"supportAsync": True,
|
|
64
|
+
"permission": ["*"]
|
|
65
|
+
}
|
|
66
|
+
return profile_json_data
|
|
67
|
+
|
|
68
|
+
def write_agent_profile_json(json_data):
|
|
69
|
+
try:
|
|
70
|
+
import os
|
|
71
|
+
json_path = Path(__file__).resolve()
|
|
72
|
+
json_dir = json_path.parent
|
|
73
|
+
json_file = os.path.join(json_dir, 'agentprofile.json')
|
|
74
|
+
with open(json_file, 'w', encoding='utf-8') as f:
|
|
75
|
+
json.dump(json_data, f, ensure_ascii=False, indent=2)
|
|
76
|
+
print("智能体描述文件已保存至当前目录下agentprofile.json")
|
|
77
|
+
except Exception as e:
|
|
78
|
+
print(f"文件写入失败: {str(e)}")
|
|
79
|
+
exit(1)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if __name__ == "__main__":
|
|
83
|
+
# 创建JSON数据
|
|
84
|
+
# 将加密种子修改为自己的加密种子,可以是随机字符串,也可以是固定字符串,只要保证一致即可。
|
|
85
|
+
acp = agentcp.AgentCP("../../../../data","",debug=False)
|
|
86
|
+
agentid_list = acp.get_aid_list()
|
|
87
|
+
agentid:agentcp.AgentID = None
|
|
88
|
+
while agentid is None:
|
|
89
|
+
print("请选择一个身份(aid):")
|
|
90
|
+
for i, agentid in enumerate(agentid_list):
|
|
91
|
+
print(f"{i+1}. {agentid}")
|
|
92
|
+
print(f"{len(agentid_list)+1}. 创建一个新的身份(aid)")
|
|
93
|
+
choice = input("请输入数字选择一个身份(aid): ")
|
|
94
|
+
try:
|
|
95
|
+
choice = int(choice) - 1
|
|
96
|
+
if choice < 0 or choice > len(agentid_list):
|
|
97
|
+
raise ValueError
|
|
98
|
+
if choice == len(agentid_list):
|
|
99
|
+
aid = input("请输入名称: ")
|
|
100
|
+
agentid = acp.create_aid("agentunion.cn",aid)
|
|
101
|
+
if agentid is None:
|
|
102
|
+
print("创建身份(aid)失败,请打开日志查看原因")
|
|
103
|
+
exit(1)
|
|
104
|
+
agentid_list = acp.get_aid_list()
|
|
105
|
+
else:
|
|
106
|
+
agentid = acp.load_aid(agentid_list[choice])
|
|
107
|
+
if agentid is None:
|
|
108
|
+
print("加载身份(aid)失败,请打开日志查看原因")
|
|
109
|
+
exit(1)
|
|
110
|
+
except ValueError:
|
|
111
|
+
print("无效的选择,请重新输入。")
|
|
112
|
+
print(f"当前选择的身份(aid)是: {str(agentid)}")
|
|
113
|
+
agentid.init_ap_client()
|
|
114
|
+
json_data = create_financial_analyzer_json(agentid.get_publisher_info())
|
|
115
|
+
write_agent_profile_json(json_data)
|
|
116
|
+
select_result = input("是否将文件拷贝到agent公有数据目录下(Y/N): ")
|
|
117
|
+
if select_result.upper() != "Y":
|
|
118
|
+
print("程序运行结束")
|
|
119
|
+
exit(1)
|
|
120
|
+
agentid.create_agent_profile(json_data)
|
|
121
|
+
select_result = input("拷贝成功,是否同步到接入服务器(Y/N): ")
|
|
122
|
+
if select_result.upper() != "Y":
|
|
123
|
+
print("程序运行结束")
|
|
124
|
+
exit(1)
|
|
125
|
+
result = agentid.sync_public_files()
|
|
126
|
+
if result:
|
|
127
|
+
print("文件同步成功!")
|
|
128
|
+
else:
|
|
129
|
+
print("文件同步失败,请初始化ACP时打开日志查看")
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import agentcp
|
|
4
|
+
|
|
5
|
+
if __name__ == "__main__":
|
|
6
|
+
acp = agentcp.AgentCP("../../../../data")
|
|
7
|
+
_my_aid = "search007.agentunion.cn"
|
|
8
|
+
aid = acp.load_aid(_my_aid)
|
|
9
|
+
@aid.message_handler()
|
|
10
|
+
async def sync_message_handler(msg):
|
|
11
|
+
receiver = aid.get_receiver_from_message(msg)
|
|
12
|
+
if aid.id not in receiver:
|
|
13
|
+
return None
|
|
14
|
+
session_id = aid.get_session_id_from_message(msg)
|
|
15
|
+
sender = aid.get_sender_from_message(msg)
|
|
16
|
+
agents = [
|
|
17
|
+
{
|
|
18
|
+
"agent_id": "testdemo11.agentunion.cn",
|
|
19
|
+
"name":"我是天气Agent,我提供天气信息",
|
|
20
|
+
"description":"我是天气Agent,我提供天气信息",
|
|
21
|
+
},
|
|
22
|
+
]
|
|
23
|
+
aid.send_message_content(session_id, [sender], json.dumps(agents))
|
|
24
|
+
return True
|
|
25
|
+
aid.online()
|
|
26
|
+
# aid.sync_public_files()
|
|
27
|
+
print("已上线完成")
|
|
28
|
+
acp.serve_forever()
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from datetime import datetime, timezone
|
|
3
|
+
from pathlib import Path # 新增导入
|
|
4
|
+
|
|
5
|
+
import agentcp
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def create_financial_analyzer_json(publisherInfo):
|
|
9
|
+
"""创建智能体能力、权限描述"""
|
|
10
|
+
name = "模拟天气Agent"
|
|
11
|
+
profile_json_data = {
|
|
12
|
+
"publisherInfo": publisherInfo,
|
|
13
|
+
"avaUrl": "https://pic.rmb.bdstatic.com/6534865873a0800e74f2399a14bcf515@h_1280",
|
|
14
|
+
"version": "1.0.0",
|
|
15
|
+
"lastUpdated": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
16
|
+
"name": name,
|
|
17
|
+
"description": name,
|
|
18
|
+
"capabilities": {
|
|
19
|
+
"core": [name],
|
|
20
|
+
"extended": []
|
|
21
|
+
},
|
|
22
|
+
"llm":{
|
|
23
|
+
"model":"", #模型名称,或使用aid
|
|
24
|
+
"num_parameters":"", #模型参数量(如"7B"表示70亿参数)
|
|
25
|
+
"quantization_bits":"", #量化位数(如Q4表示4位量化)
|
|
26
|
+
"context_length":"", #上下文长度(如"4096"表示4096个token)
|
|
27
|
+
},
|
|
28
|
+
"references": {
|
|
29
|
+
"knowledgeBases": [""],
|
|
30
|
+
"tools": [""],
|
|
31
|
+
"companyInfo": [""],
|
|
32
|
+
"productInfo": [""]
|
|
33
|
+
},
|
|
34
|
+
"authorization": {
|
|
35
|
+
"modes": ["free"],
|
|
36
|
+
"fee": {},
|
|
37
|
+
"description": "当前智能体免费使用,无费用",
|
|
38
|
+
"sla": {}
|
|
39
|
+
},
|
|
40
|
+
"input": {
|
|
41
|
+
"types": ["content"], # 目前支持"content", "search", "reasoning_content", "error", 'file',后续会支持语音视频流
|
|
42
|
+
"formats": ["json"], # 详细类型
|
|
43
|
+
"examples": {
|
|
44
|
+
"type": "content",
|
|
45
|
+
"format": "text",
|
|
46
|
+
"content": "搜索智能体:xxx"
|
|
47
|
+
},
|
|
48
|
+
"semantics": [""],
|
|
49
|
+
"compatibleAids": ["*"]
|
|
50
|
+
},
|
|
51
|
+
"output": {
|
|
52
|
+
"types": ["content"],
|
|
53
|
+
"formats": ["markdown"],
|
|
54
|
+
"examples": {
|
|
55
|
+
"type": "content",
|
|
56
|
+
"format": "markdown",
|
|
57
|
+
"content": ""
|
|
58
|
+
},
|
|
59
|
+
"semantics": [""],
|
|
60
|
+
"compatibleAids": [""]
|
|
61
|
+
},
|
|
62
|
+
"supportStream": True, # False代表当前智能体不支持流式输出
|
|
63
|
+
"supportAsync": True,
|
|
64
|
+
"permission": ["*"]
|
|
65
|
+
}
|
|
66
|
+
return profile_json_data
|
|
67
|
+
|
|
68
|
+
def write_agent_profile_json(json_data):
|
|
69
|
+
try:
|
|
70
|
+
import os
|
|
71
|
+
json_path = Path(__file__).resolve()
|
|
72
|
+
json_dir = json_path.parent
|
|
73
|
+
json_file = os.path.join(json_dir, 'agentprofile.json')
|
|
74
|
+
with open(json_file, 'w', encoding='utf-8') as f:
|
|
75
|
+
json.dump(json_data, f, ensure_ascii=False, indent=2)
|
|
76
|
+
print("智能体描述文件已保存至当前目录下agentprofile.json")
|
|
77
|
+
except Exception as e:
|
|
78
|
+
print(f"文件写入失败: {str(e)}")
|
|
79
|
+
exit(1)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if __name__ == "__main__":
|
|
83
|
+
# 创建JSON数据
|
|
84
|
+
# 将加密种子修改为自己的加密种子,可以是随机字符串,也可以是固定字符串,只要保证一致即可。
|
|
85
|
+
acp = agentcp.AgentCP("../../../../data","",debug=False)
|
|
86
|
+
agentid_list = acp.get_aid_list()
|
|
87
|
+
agentid:agentcp.AgentID = None
|
|
88
|
+
while agentid is None:
|
|
89
|
+
print("请选择一个身份(aid):")
|
|
90
|
+
for i, agentid in enumerate(agentid_list):
|
|
91
|
+
print(f"{i+1}. {agentid}")
|
|
92
|
+
print(f"{len(agentid_list)+1}. 创建一个新的身份(aid)")
|
|
93
|
+
choice = input("请输入数字选择一个身份(aid): ")
|
|
94
|
+
try:
|
|
95
|
+
choice = int(choice) - 1
|
|
96
|
+
if choice < 0 or choice > len(agentid_list):
|
|
97
|
+
raise ValueError
|
|
98
|
+
if choice == len(agentid_list):
|
|
99
|
+
aid = input("请输入名称: ")
|
|
100
|
+
agentid = acp.create_aid("agentunion.cn",aid)
|
|
101
|
+
if agentid is None:
|
|
102
|
+
print("创建身份(aid)失败,请打开日志查看原因")
|
|
103
|
+
exit(1)
|
|
104
|
+
agentid_list = acp.get_aid_list()
|
|
105
|
+
else:
|
|
106
|
+
agentid = acp.load_aid(agentid_list[choice])
|
|
107
|
+
if agentid is None:
|
|
108
|
+
print("加载身份(aid)失败,请打开日志查看原因")
|
|
109
|
+
exit(1)
|
|
110
|
+
except ValueError:
|
|
111
|
+
print("无效的选择,请重新输入。")
|
|
112
|
+
print(f"当前选择的身份(aid)是: {str(agentid)}")
|
|
113
|
+
agentid.init_ap_client()
|
|
114
|
+
json_data = create_financial_analyzer_json(agentid.get_publisher_info())
|
|
115
|
+
write_agent_profile_json(json_data)
|
|
116
|
+
select_result = input("是否将文件拷贝到agent公有数据目录下(Y/N): ")
|
|
117
|
+
if select_result.upper() != "Y":
|
|
118
|
+
print("程序运行结束")
|
|
119
|
+
exit(1)
|
|
120
|
+
agentid.create_agent_profile(json_data)
|
|
121
|
+
select_result = input("拷贝成功,是否同步到接入服务器(Y/N): ")
|
|
122
|
+
if select_result.upper() != "Y":
|
|
123
|
+
print("程序运行结束")
|
|
124
|
+
exit(1)
|
|
125
|
+
result = agentid.sync_public_files()
|
|
126
|
+
if result:
|
|
127
|
+
print("文件同步成功!")
|
|
128
|
+
else:
|
|
129
|
+
print("文件同步失败,请初始化ACP时打开日志查看")
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import agentcp
|
|
2
|
+
|
|
3
|
+
if __name__ == "__main__":
|
|
4
|
+
acp = agentcp.AgentCP("../../../../data")
|
|
5
|
+
_my_aid = "testdemo11.agentunion.cn"
|
|
6
|
+
aid = acp.load_aid(_my_aid)
|
|
7
|
+
@aid.message_handler()
|
|
8
|
+
async def sync_message_handler(msg):
|
|
9
|
+
receiver = aid.get_receiver_from_message(msg)
|
|
10
|
+
if aid.id not in receiver:
|
|
11
|
+
return None
|
|
12
|
+
session_id = aid.get_session_id_from_message(msg)
|
|
13
|
+
sender = aid.get_sender_from_message(msg)
|
|
14
|
+
content = "我是天气Agent,今天气温39摄氏度,晴天"
|
|
15
|
+
aid.send_message_content(session_id, [sender], content)
|
|
16
|
+
return True
|
|
17
|
+
aid.online()
|
|
18
|
+
# aid.sync_public_files()
|
|
19
|
+
print("已上线完成")
|
|
20
|
+
acp.serve_forever()
|