创建身份&读写公私有数据
Github
https://github.com/auliwenjiang/agentcp/blob/master/create_profile.py
1、使用方法
1)、安装agentcp库
bash
pip install agentcp2)、修改create_profile.py中修改加密种子
seed_password修改为自定义的加密种子,agentcp库会根据加密种子对后续用户私钥进行加密
3)、修改create_profile.py中"profile_json_data"智能体描述信息
包括但不限于name(agent名称)、avaUrl(agent头像)、description(agent描述)、version(agent版本)、capabilities(agent能力)
4)、执行create_profile.py文件
bash
python create_profile.py2、详细介绍
1)、创建身份(aid)
a、create_profile.py
介绍:create_profile.py包含身份创建,身份管理,agentprofile.json自动生成
python
from datetime import datetime, timezone
import agentcp
from pathlib import Path
import json
def create_financial_analyzer_json(publisherInfo):
"""创建智能体能力、权限描述"""
profile_json_data = {
"publisherInfo": publisherInfo,
"avaUrl": "https://example.com/avatar.jpg",
"version": "1.0.0",
"lastUpdated": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
"name": "智能体搜索",
"description": "搜索网络中存在的各种能力的智能体",
"capabilities": {
"core": ["搜索智能体"],
"extended": []
},
"llm": {
"model": "qwen-plus",
"num_parameters": "",
"quantization_bits": "",
"context_length": "",
},
"references": {
"knowledgeBases": [""],
"tools": [""],
"companyInfo": [""],
"productInfo": [""]
},
"authorization": {
"modes": ["free"],
"fee": {},
"description": "当前智能体免费使用,无费用",
"sla": {}
},
"input": {
"types": ["content"],
"formats": ["json"],
"examples": {
"type": "content",
"format": "text",
"content": "搜索智能体:xxx"
},
"semantics": [""],
"compatibleAids": ["*"]
},
"output": {
"types": ["content"],
"formats": ["markdown"],
"examples": {
"type": "content",
"format": "markdown",
"content": ""
},
"semantics": [""],
"compatibleAids": [""]
},
"supportStream": True,
"supportAsync": True,
"permission": ["*"]
}
return profile_json_data
if __name__ == "__main__":
acp = agentcp.AgentCP(".", seed_password="888777", debug=False)
agentid_list = acp.get_aid_list()
# ... 身份选择和创建逻辑b、使用create_profile.py
bash
python create_profile.py2)、读写公有数据
python
import agentcp
acp = agentcp.AgentCP(".")
aid = acp.create_aid("aid.pub", "guest")
if aid == None:
print("aid创建失败,请打开日志查看")
exit(1)
public_data_path = aid.get_agent_public_path()
# todo3)、读写私有数据
python
import agentcp
acp = agentcp.AgentCP(".")
aid = acp.create_aid("aid.pub", "guest")
if aid == None:
print("aid创建失败,请打开日志查看")
exit(1)
private_data_path = aid.get_agent_private_path()
# todo4)、同步公有数据到ap
python
import agentcp
acp = agentcp.AgentCP(".")
aid = acp.create_aid("aid.pub", "guest")
if aid == None:
print("aid创建失败,请打开日志查看")
exit(1)
aid.sync_public_files()