@agentunion/kite 1.3.2 → 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 +302 -0
- package/cli.js +119 -4
- package/core/dependency_checker.py +250 -0
- package/core/env_checker.py +490 -0
- package/dependencies_lock.json +128 -0
- package/extensions/agents/assistant/entry.py +111 -1
- package/extensions/agents/assistant/server.py +279 -215
- package/extensions/channels/acp_channel/entry.py +111 -1
- package/extensions/channels/acp_channel/module.md +23 -22
- package/extensions/channels/acp_channel/server.py +279 -215
- package/extensions/event_hub_bench/entry.py +107 -1
- package/extensions/services/backup/entry.py +306 -21
- package/extensions/services/backup/module.md +24 -22
- 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 +167 -19
- package/extensions/services/model_service/module.md +21 -22
- 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 +215 -26
- package/extensions/services/watchdog/module.md +1 -0
- package/extensions/services/watchdog/monitor.py +178 -38
- package/extensions/services/web/WEBSOCKET_STATUS.md +143 -0
- package/extensions/services/web/config_example.py +35 -0
- package/extensions/services/web/config_loader.py +110 -0
- package/extensions/services/web/entry.py +114 -26
- package/extensions/services/web/module.md +35 -24
- package/extensions/services/web/pairing.py +250 -0
- package/extensions/services/web/pairing_codes.jsonl +16 -0
- package/extensions/services/web/relay.py +643 -0
- package/extensions/services/web/relay_config.json5 +67 -0
- package/extensions/services/web/routes/routes_management_ws.py +127 -0
- package/extensions/services/web/routes/routes_rpc.py +89 -0
- package/extensions/services/web/routes/routes_test.py +61 -0
- package/extensions/services/web/routes/schemas.py +0 -22
- package/extensions/services/web/server.py +434 -99
- package/extensions/services/web/static/css/style.css +67 -28
- package/extensions/services/web/static/index.html +234 -44
- package/extensions/services/web/static/js/app.js +1335 -48
- package/extensions/services/web/static/js/kernel-client-example.js +161 -0
- package/extensions/services/web/static/js/kernel-client.js +383 -0
- package/extensions/services/web/static/js/registry-tests.js +558 -0
- package/extensions/services/web/static/js/token-manager.js +175 -0
- package/extensions/services/web/static/pairing.html +248 -0
- package/extensions/services/web/static/test_registry.html +262 -0
- package/extensions/services/web/web_config.json5 +29 -0
- package/kernel/entry.py +120 -32
- package/kernel/event_hub.py +141 -16
- package/kernel/module.md +60 -33
- package/kernel/registry_store.py +45 -36
- package/kernel/rpc_router.py +152 -59
- package/kernel/server.py +322 -26
- package/kite_cli/__init__.py +3 -0
- package/kite_cli/__main__.py +5 -0
- package/kite_cli/commands/__init__.py +1 -0
- package/kite_cli/commands/clean.py +101 -0
- package/kite_cli/commands/deps_install.py +67 -0
- package/kite_cli/commands/doctor.py +35 -0
- package/kite_cli/commands/env_check.py +45 -0
- package/kite_cli/commands/history.py +111 -0
- package/kite_cli/commands/info.py +96 -0
- package/kite_cli/commands/install.py +313 -0
- package/kite_cli/commands/list.py +143 -0
- package/kite_cli/commands/log.py +81 -0
- package/kite_cli/commands/prepare.py +49 -0
- package/kite_cli/commands/rollback.py +88 -0
- package/kite_cli/commands/search.py +73 -0
- package/kite_cli/commands/uninstall.py +85 -0
- package/kite_cli/commands/update.py +118 -0
- package/kite_cli/commands/venv_setup.py +56 -0
- package/kite_cli/core/__init__.py +1 -0
- package/kite_cli/core/checker.py +142 -0
- package/kite_cli/core/dependency.py +229 -0
- package/kite_cli/core/downloader.py +209 -0
- package/kite_cli/core/install_info.py +40 -0
- package/kite_cli/core/tool_installer.py +397 -0
- package/kite_cli/core/validator.py +78 -0
- package/kite_cli/main.py +317 -0
- package/kite_cli/utils/__init__.py +1 -0
- package/kite_cli/utils/i18n.py +252 -0
- package/kite_cli/utils/interactive.py +63 -0
- package/kite_cli/utils/operation_log.py +77 -0
- package/kite_cli/utils/paths.py +34 -0
- package/kite_cli/utils/version.py +308 -0
- package/launcher/entry.py +1124 -178
- package/launcher/logging_setup.py +104 -0
- package/launcher/module.md +46 -37
- package/launcher/module_scanner.py +11 -1
- package/main.py +4 -1
- package/package.json +9 -1
- package/python_version.json +4 -0
- package/requirements.txt +38 -0
- package/scripts/env-manager.js +328 -0
- package/scripts/plan_manager.py +315 -0
- package/scripts/python-env.js +79 -0
- package/scripts/scan_dependencies.py +461 -0
- package/scripts/setup-python-env.js +191 -0
- package/extensions/services/web/routes/routes_modules.py +0 -249
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Copyright 2025 ModelUnion Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from datetime import datetime, timezone
|
|
16
|
+
import agentcp
|
|
17
|
+
from pathlib import Path # 新增导入
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
def create_financial_analyzer_json(publisherInfo):
|
|
21
|
+
"""创建智能体能力、权限描述"""
|
|
22
|
+
data = {
|
|
23
|
+
"publisherInfo": publisherInfo,
|
|
24
|
+
"version": "1.0.0",
|
|
25
|
+
"lastUpdated": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
26
|
+
"name": "文件读写",
|
|
27
|
+
"description": "读写agent目录下的文件",
|
|
28
|
+
"avaUrl": "https://t8.baidu.com/it/u=655275816,1648044724&fm=193",
|
|
29
|
+
"capabilities": {
|
|
30
|
+
"core": ["读取文件", "写入文件", "查询文件列表"],
|
|
31
|
+
"extended": [],
|
|
32
|
+
},
|
|
33
|
+
"llm": {
|
|
34
|
+
"model": "qwen-plus", # 模型名称,或使用aid
|
|
35
|
+
"num_parameters": "", # 模型参数量(如"7B"表示70亿参数)
|
|
36
|
+
"quantization_bits": "", # 量化位数(如Q4表示4位量化)
|
|
37
|
+
"context_length": "", # 上下文长度(如"4096"表示4096个token)
|
|
38
|
+
},
|
|
39
|
+
"references": {
|
|
40
|
+
"knowledgeBases": [""],
|
|
41
|
+
"tools": [""],
|
|
42
|
+
"companyInfo": [""],
|
|
43
|
+
"productInfo": [""],
|
|
44
|
+
},
|
|
45
|
+
"authorization": {
|
|
46
|
+
"modes": ["free"],
|
|
47
|
+
"fee": {},
|
|
48
|
+
"description": "",
|
|
49
|
+
"sla": {},
|
|
50
|
+
},
|
|
51
|
+
"input": {
|
|
52
|
+
"types": ["content"],
|
|
53
|
+
"formats": ["json"], # 详细类型
|
|
54
|
+
"examples": {
|
|
55
|
+
"type": "content",
|
|
56
|
+
"format": "text",
|
|
57
|
+
"content": "查询文件列表",
|
|
58
|
+
},
|
|
59
|
+
"semantics": [""],
|
|
60
|
+
"compatibleAids": ["*"],
|
|
61
|
+
},
|
|
62
|
+
"output": {
|
|
63
|
+
"types": ["content"],
|
|
64
|
+
"formats": ["markdown"],
|
|
65
|
+
"examples": {"type": "content", "format": "markdown", "content": ""},
|
|
66
|
+
"semantics": [""],
|
|
67
|
+
"compatibleAids": [""],
|
|
68
|
+
},
|
|
69
|
+
"supportStream": True, # False代表当前智能体不支持流式输出
|
|
70
|
+
"supportAsync": True,
|
|
71
|
+
"permission": ["*"],
|
|
72
|
+
}
|
|
73
|
+
return data
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def write_agent_profile_json(json_data):
|
|
77
|
+
try:
|
|
78
|
+
import os
|
|
79
|
+
|
|
80
|
+
json_path = Path(__file__).resolve()
|
|
81
|
+
json_dir = json_path.parent
|
|
82
|
+
json_file = os.path.join(json_dir, "agentprofile.json")
|
|
83
|
+
with open(json_file, "w", encoding="utf-8") as f:
|
|
84
|
+
json.dump(json_data, f, ensure_ascii=False, indent=2)
|
|
85
|
+
print("智能体描述文件已保存至当前目录下agentprofile.json")
|
|
86
|
+
except Exception as e:
|
|
87
|
+
print(f"文件写入失败: {str(e)}")
|
|
88
|
+
exit(1)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if __name__ == "__main__":
|
|
92
|
+
# 创建JSON数据
|
|
93
|
+
# 将加密种子修改为自己的加密种子,可以是随机字符串,也可以是固定字符串,只要保证一致即可。
|
|
94
|
+
acp = agentcp.AgentCP(".", seed_password="888777", debug=False)
|
|
95
|
+
agentid_list = acp.get_aid_list()
|
|
96
|
+
agentid: agentcp.AgentID = None
|
|
97
|
+
while agentid is None:
|
|
98
|
+
print("请选择一个身份(aid):")
|
|
99
|
+
for i, agentid in enumerate(agentid_list):
|
|
100
|
+
print(f"{i+1}. {agentid}")
|
|
101
|
+
print(f"{len(agentid_list)+1}. 创建一个新的身份(aid)")
|
|
102
|
+
choice = input("请输入数字选择一个身份(aid): ")
|
|
103
|
+
try:
|
|
104
|
+
choice = int(choice) - 1
|
|
105
|
+
if choice < 0 or choice > len(agentid_list):
|
|
106
|
+
raise ValueError
|
|
107
|
+
if choice == len(agentid_list):
|
|
108
|
+
aid = input("请输入名称: ")
|
|
109
|
+
agentid = acp.create_aid("agentunion.cn", aid)
|
|
110
|
+
if agentid is None:
|
|
111
|
+
print("创建身份(aid)失败,请打开日志查看原因")
|
|
112
|
+
exit(1)
|
|
113
|
+
agentid_list = acp.get_aid_list()
|
|
114
|
+
else:
|
|
115
|
+
agentid = acp.load_aid(agentid_list[choice])
|
|
116
|
+
if agentid is None:
|
|
117
|
+
print("加载身份(aid)失败,请打开日志查看原因")
|
|
118
|
+
exit(1)
|
|
119
|
+
except ValueError:
|
|
120
|
+
print("无效的选择,请重新输入。")
|
|
121
|
+
print(f"当前选择的身份(aid)是: {str(agentid)}")
|
|
122
|
+
agentid.init_ap_client()
|
|
123
|
+
json_data = create_financial_analyzer_json(agentid.get_publisher_info())
|
|
124
|
+
write_agent_profile_json(json_data)
|
|
125
|
+
select_result = input("是否将文件拷贝到agent公有数据目录下(Y/N): ")
|
|
126
|
+
if select_result.upper() != "Y":
|
|
127
|
+
print("程序运行结束")
|
|
128
|
+
exit(1)
|
|
129
|
+
agentid.create_agent_profile(json_data)
|
|
130
|
+
select_result = input("拷贝成功,是否同步到接入服务器(Y/N): ")
|
|
131
|
+
if select_result.upper() != "Y":
|
|
132
|
+
print("程序运行结束")
|
|
133
|
+
exit(1)
|
|
134
|
+
result = agentid.sync_public_files()
|
|
135
|
+
if result:
|
|
136
|
+
print("文件同步成功!")
|
|
137
|
+
else:
|
|
138
|
+
print("文件同步失败,请初始化ACP时打开日志查看")
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# Copyright 2025 ModelUnion Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from agentcp import AgentCP
|
|
16
|
+
import asyncio
|
|
17
|
+
import os
|
|
18
|
+
import re
|
|
19
|
+
import os
|
|
20
|
+
import json
|
|
21
|
+
|
|
22
|
+
class FileOperator:
|
|
23
|
+
"""文件操作类,负责安全地读取文本文件内容"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, sandbox_root: str = None):
|
|
26
|
+
self.sandbox_root = sandbox_root or os.getcwd() # 默认使用当前工作目录
|
|
27
|
+
|
|
28
|
+
def is_text_file(self, file_path: str) -> bool:
|
|
29
|
+
"""
|
|
30
|
+
通过检查文件内容判断是否为文本文件
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
file_path: 文件路径
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
bool: 是否为文本文件
|
|
37
|
+
"""
|
|
38
|
+
try:
|
|
39
|
+
# 尝试以文本模式打开文件
|
|
40
|
+
with open(file_path, 'r', encoding='utf-8') as f:
|
|
41
|
+
# 读取前1024个字符
|
|
42
|
+
f.read(1024)
|
|
43
|
+
return True
|
|
44
|
+
except UnicodeDecodeError:
|
|
45
|
+
# 如果解码失败,说明不是文本文件
|
|
46
|
+
return False
|
|
47
|
+
except Exception:
|
|
48
|
+
# 处理其他异常,如文件不存在等,默认不是文本文件
|
|
49
|
+
return False
|
|
50
|
+
|
|
51
|
+
def extract_file_path(self, text: str) -> str:
|
|
52
|
+
"""从文本中提取文件名(不需要完整路径)"""
|
|
53
|
+
match = re.search(r"(?:读取|打开|查看)文件\s*([^\s\/\\]+)", text)
|
|
54
|
+
return match.group(1) if match else None
|
|
55
|
+
|
|
56
|
+
def sanitize_path(self, filename: str) -> str:
|
|
57
|
+
"""遍历sandbox目录,找到这个文件"""
|
|
58
|
+
def recursive_search(root_dir):
|
|
59
|
+
try:
|
|
60
|
+
for root, dirs, files in os.walk(root_dir):
|
|
61
|
+
if filename in files:
|
|
62
|
+
full_path = os.path.join(root, filename)
|
|
63
|
+
normalized_path = os.path.normpath(full_path)
|
|
64
|
+
return normalized_path
|
|
65
|
+
except:
|
|
66
|
+
return None
|
|
67
|
+
return None
|
|
68
|
+
|
|
69
|
+
return recursive_search(self.sandbox_root)
|
|
70
|
+
|
|
71
|
+
def walk_directory(self):
|
|
72
|
+
"""
|
|
73
|
+
遍历目录并打印所有文件和文件夹
|
|
74
|
+
"""
|
|
75
|
+
filenamess = []
|
|
76
|
+
for root, dirs, files in os.walk(self.sandbox_root):
|
|
77
|
+
for file in files:
|
|
78
|
+
filenamess.append(file)
|
|
79
|
+
return filenamess
|
|
80
|
+
|
|
81
|
+
def exist_file(self, filename):
|
|
82
|
+
"""
|
|
83
|
+
检查文件是否存在
|
|
84
|
+
"""
|
|
85
|
+
safe_path = self.sanitize_path(filename)
|
|
86
|
+
return os.path.exists(safe_path)
|
|
87
|
+
|
|
88
|
+
def read_file(self, file_path: str) -> str:
|
|
89
|
+
"""
|
|
90
|
+
安全地读取文本文件内容
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
file_path: 文件路径
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
文件内容字符串
|
|
97
|
+
|
|
98
|
+
Raises:
|
|
99
|
+
ValueError: 如果文件不是文本格式
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
safe_path = self.sanitize_path(file_path)
|
|
103
|
+
if not safe_path:
|
|
104
|
+
raise ValueError("文件不存在")
|
|
105
|
+
if not self.is_text_file(safe_path):
|
|
106
|
+
raise ValueError("只能读取文本文件")
|
|
107
|
+
with open(safe_path, "r") as file:
|
|
108
|
+
return file.read()
|
|
109
|
+
|
|
110
|
+
def parse_command(text):
|
|
111
|
+
if not text:
|
|
112
|
+
return False
|
|
113
|
+
if text.find("查询") >=0 or text.find("列表") >=0:
|
|
114
|
+
return 'list'
|
|
115
|
+
if text.find("写入") >=0 or text.find("保存") >=0:
|
|
116
|
+
return 'write'
|
|
117
|
+
if text.find("读取") >= 0 or text.find("查看") >= 0:
|
|
118
|
+
return "read"
|
|
119
|
+
|
|
120
|
+
class FileAgent:
|
|
121
|
+
def __init__(self, endpoint: str, name: str):
|
|
122
|
+
"""
|
|
123
|
+
初始化文件Agent
|
|
124
|
+
"""
|
|
125
|
+
self.acp = AgentCP("./", seed_password="888777")
|
|
126
|
+
self.endpoint = endpoint
|
|
127
|
+
self.name = name
|
|
128
|
+
self.aid = None
|
|
129
|
+
self.last_command = ''
|
|
130
|
+
self.last_data = ''
|
|
131
|
+
async def message_handler(self, msg):
|
|
132
|
+
"""
|
|
133
|
+
消息处理器 - 根据消息内容安全地读取文件
|
|
134
|
+
{
|
|
135
|
+
'session_id': '1831173476580327424',
|
|
136
|
+
'request_id': '', 'message_id': '9',
|
|
137
|
+
'ref_msg_id': '', 'sender': 'samplesdeveloper.agentunion.cn',
|
|
138
|
+
'receiver': 'guest_1831158907166261248.agentunion.cn',
|
|
139
|
+
'message': '[{"type": "text", "status": "success", "timestamp": 1746343146261,
|
|
140
|
+
"content": "{\\"text\\":\\"\\u8bfb\\u53d6\\u6587\\u4ef6agentprofile.json\\",\\"files\\":[],\\"links\\":[],\\"search\\":false,\\"think\\":false}",
|
|
141
|
+
"stream": false, "prompt": null, "extra": null, "artifact": null}]',
|
|
142
|
+
'timestamp': '1746343146265'
|
|
143
|
+
}
|
|
144
|
+
"""
|
|
145
|
+
try:
|
|
146
|
+
ref_msg_id = msg.get("ref_msg_id")
|
|
147
|
+
content = msg.get("message", "\"{}\"")
|
|
148
|
+
content = json.loads(content)[0]["content"]
|
|
149
|
+
content = json.loads(content)
|
|
150
|
+
text = content.get("text", "")
|
|
151
|
+
command = parse_command(text)
|
|
152
|
+
print(f"收到消息: {content}")
|
|
153
|
+
|
|
154
|
+
if self.last_command:
|
|
155
|
+
if self.last_command == "write" and self.last_data:
|
|
156
|
+
ret = await self.write_file(msg, text, self.last_data)
|
|
157
|
+
if not ret:
|
|
158
|
+
await self._send_reply(msg, "文件已存在请重新输入名字")
|
|
159
|
+
return
|
|
160
|
+
self.last_data = ''
|
|
161
|
+
self.last_command = ""
|
|
162
|
+
return
|
|
163
|
+
elif self.last_command == "write":
|
|
164
|
+
self.last_data = text
|
|
165
|
+
await self._send_reply(msg, "请输入你要保存的文件名")
|
|
166
|
+
return True
|
|
167
|
+
elif self.last_command == "read":
|
|
168
|
+
self.last_command = ''
|
|
169
|
+
return await self.read_file(msg, text) # 调用 read_file 方法处理读取文件的逻辑
|
|
170
|
+
|
|
171
|
+
elif command == 'list':
|
|
172
|
+
files = self.file_operator.walk_directory()
|
|
173
|
+
if not files:
|
|
174
|
+
await self._send_reply(msg, "当前目录下没有文件")
|
|
175
|
+
return True
|
|
176
|
+
to = "文件列表<br>" + "<br>".join(files)
|
|
177
|
+
await self._send_reply(msg, to)
|
|
178
|
+
return True
|
|
179
|
+
elif command == 'write':
|
|
180
|
+
self.last_command = "write"
|
|
181
|
+
await self._send_reply(msg, "请输入你要写入的内容")
|
|
182
|
+
return True
|
|
183
|
+
elif command == "read":
|
|
184
|
+
self.last_command = "read"
|
|
185
|
+
files = self.file_operator.walk_directory()
|
|
186
|
+
if not files:
|
|
187
|
+
await self._send_reply(msg, "当前目录下没有文件")
|
|
188
|
+
return True
|
|
189
|
+
to = "读取哪一个文件?<br>" + "<br>".join(files)
|
|
190
|
+
print(f"send message: {to}")
|
|
191
|
+
await self._send_reply(msg, to)
|
|
192
|
+
return True
|
|
193
|
+
else:
|
|
194
|
+
await self._send_reply(
|
|
195
|
+
msg, "你可以对我说: <br>查询文件<br>读取文件<br>写入文件"
|
|
196
|
+
)
|
|
197
|
+
except Exception as e:
|
|
198
|
+
print(f"处理消息出错: {str(e)}")
|
|
199
|
+
await self._send_reply(msg, f"处理文件时出错: {str(e)}")
|
|
200
|
+
return False
|
|
201
|
+
|
|
202
|
+
async def write_file(self, msg, filename, text):
|
|
203
|
+
file_path = f"{self.aid.get_agent_public_path()}/{filename}"
|
|
204
|
+
# 检查文件是否已存在
|
|
205
|
+
if os.path.exists(file_path):
|
|
206
|
+
return False
|
|
207
|
+
try:
|
|
208
|
+
# 以写入模式打开文件,并写入内容
|
|
209
|
+
with open(file_path, 'w', encoding='utf-8') as file:
|
|
210
|
+
file.write(text)
|
|
211
|
+
await self._send_reply(msg, f"成功写入文件: {file_path}")
|
|
212
|
+
return True
|
|
213
|
+
except Exception as e:
|
|
214
|
+
print(f"写入文件时出错: {str(e)}")
|
|
215
|
+
await self._send_reply(msg, f"写入文件 {file_path} 时出错: {str(e)}")
|
|
216
|
+
return False
|
|
217
|
+
|
|
218
|
+
async def read_file(self, msg, text):
|
|
219
|
+
try:
|
|
220
|
+
filename = self.file_operator.extract_file_path(text) # 现在只获取文件名
|
|
221
|
+
if not filename:
|
|
222
|
+
try:
|
|
223
|
+
print(f"未提供文件名尝试读取: {text}")
|
|
224
|
+
file_content = self.file_operator.read_file(text) # 直接传入文件名
|
|
225
|
+
await self._send_reply(msg, f"文件内容:<br>{file_content}")
|
|
226
|
+
return
|
|
227
|
+
except Exception as e:
|
|
228
|
+
print(f"处理消息出错: {str(e)}")
|
|
229
|
+
try:
|
|
230
|
+
file_content = self.file_operator.read_file(filename) # 直接传入文件名
|
|
231
|
+
await self._send_reply(msg, f"文件内容:<br>{file_content}")
|
|
232
|
+
except PermissionError:
|
|
233
|
+
await self._send_reply(msg, "访问文件被拒绝")
|
|
234
|
+
except FileNotFoundError:
|
|
235
|
+
await self._send_reply(msg, f"文件不存在: {filename}")
|
|
236
|
+
except ValueError as e:
|
|
237
|
+
await self._send_reply(msg, f"{str(e)}")
|
|
238
|
+
return True
|
|
239
|
+
except Exception as e:
|
|
240
|
+
print(f"处理消息出错: {str(e)}")
|
|
241
|
+
await self._send_reply(msg, f"处理文件时出错: {str(e)}")
|
|
242
|
+
return False
|
|
243
|
+
|
|
244
|
+
async def _send_reply(self, original_msg, content: str):
|
|
245
|
+
"""
|
|
246
|
+
发送回复消息
|
|
247
|
+
"""
|
|
248
|
+
try:
|
|
249
|
+
self.aid.send_message_content(
|
|
250
|
+
to_aid_list=[original_msg.get("sender")],
|
|
251
|
+
session_id=original_msg.get("session_id"),
|
|
252
|
+
llm_content=content)
|
|
253
|
+
except Exception as e:
|
|
254
|
+
print(f"发送回复消息出错: {str(e)}")
|
|
255
|
+
|
|
256
|
+
async def run(self):
|
|
257
|
+
"""
|
|
258
|
+
运行Agent
|
|
259
|
+
"""
|
|
260
|
+
try:
|
|
261
|
+
self.aid = self.acp.create_aid(self.endpoint, self.name)
|
|
262
|
+
self.aid.add_message_handler(self.message_handler)
|
|
263
|
+
self.aid.online()
|
|
264
|
+
self.file_operator = FileOperator(self.aid.get_agent_public_path())
|
|
265
|
+
print("Agent已上线,等待文件读取指令...")
|
|
266
|
+
|
|
267
|
+
while True:
|
|
268
|
+
await asyncio.sleep(1)
|
|
269
|
+
|
|
270
|
+
except Exception as e:
|
|
271
|
+
print(f"发生错误: {str(e)}")
|
|
272
|
+
finally:
|
|
273
|
+
if self.aid:
|
|
274
|
+
self.aid.offline()
|
|
275
|
+
print("Agent已下线")
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
if __name__ == "__main__":
|
|
279
|
+
# 配置参数
|
|
280
|
+
ENDPOINT = "agentunion.cn"
|
|
281
|
+
AGENT_NAME = "w212" #guest 是一个临时aid会被定时清理,实际业务中请使用真实的aid
|
|
282
|
+
|
|
283
|
+
# 创建并运行Agent
|
|
284
|
+
agent = FileAgent(
|
|
285
|
+
ENDPOINT,
|
|
286
|
+
AGENT_NAME,
|
|
287
|
+
)
|
|
288
|
+
# agent.test()
|
|
289
|
+
asyncio.run(agent.run())
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
```markdown:d:/github_agentcp/samples/hcp/README.md
|
|
2
|
+
# 智能天气助手(HCP)
|
|
3
|
+
|
|
4
|
+
基于 agentcp 框架开发的智能天气助手,支持自然语言交互和上下文记忆,能够将用户作为外部工具回调获取必要信息。
|
|
5
|
+
|
|
6
|
+
## 🚀 使用指南
|
|
7
|
+
|
|
8
|
+
1. **创建agent身份(aid)**
|
|
9
|
+
- 参考文档:创建身份&读写公私有数据
|
|
10
|
+
|
|
11
|
+
2. **配置Agent参数**
|
|
12
|
+
```python:hcp.py
|
|
13
|
+
# 修改hcp.py中的agent_id配置项
|
|
14
|
+
agent_id = "your_agent_id" # 替换为实际创建的aid
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
3. **配置环境变量**
|
|
18
|
+
```bash:.env
|
|
19
|
+
OPENAI_API_KEY=your_api_key
|
|
20
|
+
BASE_URL=https://api.openai.com/v1
|
|
21
|
+
MODEL=gpt-3.5-turbo
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
4. **安装依赖**
|
|
25
|
+
```bash
|
|
26
|
+
pip install openai agentcp python-dotenv
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
5. **启动服务**
|
|
30
|
+
```bash
|
|
31
|
+
python hcp.py
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## ✨ 核心功能
|
|
35
|
+
|
|
36
|
+
- 🌦️ 多维度天气查询(当前天气/历史天气/天气预报)
|
|
37
|
+
- 🗣️ 上下文感知的对话管理
|
|
38
|
+
- 🔧 外部工具回调机制(用于获取缺失的位置/时间信息)
|
|
39
|
+
- ⏰ 自动时间推理(支持绝对时间、相对时间和年号纪年)
|
|
40
|
+
|
|
41
|
+
## 🧩 核心类说明:MCPClient
|
|
42
|
+
|
|
43
|
+
### 初始化方法
|
|
44
|
+
```python
|
|
45
|
+
def __init__(self):
|
|
46
|
+
# 初始化 OpenAI 客户端
|
|
47
|
+
self.client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
|
48
|
+
# 创建 AgentCP 实例
|
|
49
|
+
self.acp = agentcp.AgentCP(app_path)
|
|
50
|
+
# 消息存储器(按 session_id 隔离)
|
|
51
|
+
self.message_store = dict()
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 消息管理机制
|
|
55
|
+
```python
|
|
56
|
+
def record_message(self, session_id: str, role: str, content: str):
|
|
57
|
+
# 记录对话历史(支持 user/assistant/system 三种角色)
|
|
58
|
+
|
|
59
|
+
def get_messages_for_llm(self, session_id: str, max_messages=20, system_message=None):
|
|
60
|
+
# 构造符合 OpenAI 格式的对话历史(自动维护最近20条消息)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## 🔄 交互流程
|
|
64
|
+
|
|
65
|
+
```mermaid
|
|
66
|
+
graph TD
|
|
67
|
+
A[用户提问] --> B{是否天气相关?}
|
|
68
|
+
B -->|是| C[检查位置/时间信息]
|
|
69
|
+
B -->|否| D[简短回答并引导]
|
|
70
|
+
C --> E{信息完整?}
|
|
71
|
+
E -->|是| F[生成天气报告]
|
|
72
|
+
E -->|否| G[调用用户工具获取信息]
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 💬 示例对话
|
|
76
|
+
|
|
77
|
+
> **用户**:明天天气怎么样
|
|
78
|
+
> **Agent**:你想查询哪里的天气呢
|
|
79
|
+
> **用户**:上海
|
|
80
|
+
> **Agent**:上海的天气晴
|
|
81
|
+
> **用户**:上海
|
|
82
|
+
> **Agent**:你是想查询上海什么时候的天气呢
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
from datetime import datetime, timezone
|
|
2
|
+
import agentcp
|
|
3
|
+
from pathlib import Path # 新增导入
|
|
4
|
+
import json
|
|
5
|
+
def create_financial_analyzer_json(publisherInfo):
|
|
6
|
+
"""创建智能体能力、权限描述"""
|
|
7
|
+
profile_json_data = {
|
|
8
|
+
"publisherInfo": publisherInfo,
|
|
9
|
+
"avaUrl": "https://img1.baidu.com/it/u=4196730940,2454447876&fm=253&fmt=auto&app=120&f=JPEG?w=933&h=800",
|
|
10
|
+
"version": "1.0.0",
|
|
11
|
+
"lastUpdated": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
12
|
+
"name": "HCP 天气问答智能体",
|
|
13
|
+
"description": "智能查询天气信息,提供准确的天气数据。",
|
|
14
|
+
"capabilities": {
|
|
15
|
+
"core": ["智能查询天气信息,提供准确的天气数据。"],
|
|
16
|
+
"extended": []
|
|
17
|
+
},
|
|
18
|
+
"llm":{
|
|
19
|
+
"model":"qwen-plus", #模型名称,或使用aid
|
|
20
|
+
"num_parameters":"", #模型参数量(如"7B"表示70亿参数)
|
|
21
|
+
"quantization_bits":"", #量化位数(如Q4表示4位量化)
|
|
22
|
+
"context_length":"", #上下文长度(如"4096"表示4096个token)
|
|
23
|
+
},
|
|
24
|
+
"references": {
|
|
25
|
+
"knowledgeBases": [""],
|
|
26
|
+
"tools": [""],
|
|
27
|
+
"companyInfo": [""],
|
|
28
|
+
"productInfo": [""]
|
|
29
|
+
},
|
|
30
|
+
"authorization": {
|
|
31
|
+
"modes": ["free"],
|
|
32
|
+
"fee": {},
|
|
33
|
+
"description": "当前智能体免费使用,无费用",
|
|
34
|
+
"sla": {}
|
|
35
|
+
},
|
|
36
|
+
"input": {
|
|
37
|
+
"types": ["content"], # 目前支持"content", "search", "reasoning_content", "error", 'file',后续会支持语音视频流
|
|
38
|
+
"formats": ["json"], # 详细类型
|
|
39
|
+
"examples": {
|
|
40
|
+
"type": "content",
|
|
41
|
+
"format": "text",
|
|
42
|
+
"content": "搜索智能体:xxx"
|
|
43
|
+
},
|
|
44
|
+
"semantics": [""],
|
|
45
|
+
"compatibleAids": ["*"]
|
|
46
|
+
},
|
|
47
|
+
"output": {
|
|
48
|
+
"types": ["content"],
|
|
49
|
+
"formats": ["markdown"],
|
|
50
|
+
"examples": {
|
|
51
|
+
"type": "content",
|
|
52
|
+
"format": "markdown",
|
|
53
|
+
"content": ""
|
|
54
|
+
},
|
|
55
|
+
"semantics": [""],
|
|
56
|
+
"compatibleAids": [""]
|
|
57
|
+
},
|
|
58
|
+
"supportStream": True, # False代表当前智能体不支持流式输出
|
|
59
|
+
"supportAsync": True,
|
|
60
|
+
"permission": ["*"]
|
|
61
|
+
}
|
|
62
|
+
return profile_json_data
|
|
63
|
+
|
|
64
|
+
def write_agent_profile_json(json_data):
|
|
65
|
+
try:
|
|
66
|
+
import os
|
|
67
|
+
json_path = Path(__file__).resolve()
|
|
68
|
+
json_dir = json_path.parent
|
|
69
|
+
json_file = os.path.join(json_dir, 'agentprofile.json')
|
|
70
|
+
with open(json_file, 'w', encoding='utf-8') as f:
|
|
71
|
+
json.dump(json_data, f, ensure_ascii=False, indent=2)
|
|
72
|
+
print("智能体描述文件已保存至当前目录下agentprofile.json")
|
|
73
|
+
except Exception as e:
|
|
74
|
+
print(f"文件写入失败: {str(e)}")
|
|
75
|
+
exit(1)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
# 创建JSON数据
|
|
80
|
+
# 将加密种子修改为自己的加密种子,可以是随机字符串,也可以是固定字符串,只要保证一致即可。
|
|
81
|
+
acp = agentcp.AgentCP(".",seed_password="888777",debug=False)
|
|
82
|
+
agentid_list = acp.get_aid_list()
|
|
83
|
+
agentid:agentcp.AgentID = None
|
|
84
|
+
while agentid is None:
|
|
85
|
+
print("请选择一个身份(aid):")
|
|
86
|
+
for i, agentid in enumerate(agentid_list):
|
|
87
|
+
print(f"{i+1}. {agentid}")
|
|
88
|
+
print(f"{len(agentid_list)+1}. 创建一个新的身份(aid)")
|
|
89
|
+
choice = input("请输入数字选择一个身份(aid): ")
|
|
90
|
+
try:
|
|
91
|
+
choice = int(choice) - 1
|
|
92
|
+
if choice < 0 or choice > len(agentid_list):
|
|
93
|
+
raise ValueError
|
|
94
|
+
if choice == len(agentid_list):
|
|
95
|
+
aid = input("请输入名称: ")
|
|
96
|
+
agentid = acp.create_aid("agentunion.cn",aid)
|
|
97
|
+
if agentid is None:
|
|
98
|
+
print("创建身份(aid)失败,请打开日志查看原因")
|
|
99
|
+
exit(1)
|
|
100
|
+
agentid_list = acp.get_aid_list()
|
|
101
|
+
else:
|
|
102
|
+
agentid = acp.load_aid(agentid_list[choice])
|
|
103
|
+
if agentid is None:
|
|
104
|
+
print("加载身份(aid)失败,请打开日志查看原因")
|
|
105
|
+
exit(1)
|
|
106
|
+
except ValueError:
|
|
107
|
+
print("无效的选择,请重新输入。")
|
|
108
|
+
print(f"当前选择的身份(aid)是: {str(agentid)}")
|
|
109
|
+
agentid.init_ap_client()
|
|
110
|
+
json_data = create_financial_analyzer_json(agentid.get_publisher_info())
|
|
111
|
+
write_agent_profile_json(json_data)
|
|
112
|
+
select_result = input("是否将文件拷贝到agent公有数据目录下(Y/N): ")
|
|
113
|
+
if select_result.upper() != "Y":
|
|
114
|
+
print("程序运行结束")
|
|
115
|
+
exit(1)
|
|
116
|
+
agentid.create_agent_profile(json_data)
|
|
117
|
+
select_result = input("拷贝成功,是否同步到接入服务器(Y/N): ")
|
|
118
|
+
if select_result.upper() != "Y":
|
|
119
|
+
print("程序运行结束")
|
|
120
|
+
exit(1)
|
|
121
|
+
result = agentid.sync_public_files()
|
|
122
|
+
if result:
|
|
123
|
+
print("文件同步成功!")
|
|
124
|
+
else:
|
|
125
|
+
print("文件同步失败,请初始化ACP时打开日志查看")
|