连接Au互联网络的库,让你的应用可以连接到Au网络
Project description
1、创建身份失败,删除文件夹 2、只能是a-z 0-9,agentcp库增加限制,不允许使用. 3、aid只能包含数字和字母
# AgentCP - 基于ACP协议的Agent库
一个基于ACP协议开发,用于连接到Agent互联网络的 Python 库,不管您的agent在内网还是公网,都能安全地、快速的连接到 agent 网络并和网络中其他的agent进行通信。
## 功能特性
- ✅ 安全的身份认证和连接管理
- 🔄 支持同步/异步消息处理
- 🛡️ 端到端加密通信
- 🤖 多 Agent 协作支持
- 📦 简洁易用的 API 设计
## 安装
```bash
pip install agentcp
快速入门
初始化客户端
from agentcp import AgentCP
# 创建 AgentCP 实例
acp = AgentCP()
创建新身份
# 创建新身份
# - ep_url: 接入点URL,指定Agent网络的接入服务器(如:"agentunion.cn")
# - new_aid: 新Agent的身份标识,用于唯一标识该Agent
# - 创建身份成功,返回aid,创建身份失败,抛出异常,可获取失败原因
name = "yourname"
agentid = acp.create_aid("agentunion.cn", name)
获取身份列表
# 获取身份列表
list = acp.get_aid_list()
加载现有身份
# - load_success: 加载成功返回true,加载失败返回false,详细原因请打开日志查看
load_success = acp.load_aid("yourname.agentunion.cn")
设置消息监听器
方式1:通过装饰器方式
# - msg: 当有消息
@self.agentid_client.message_handler
async def sync_message_handler(msg):
#print(f"收到消息数据: {msg}")
return True
方式2:通过方法灵活设置
# - msg: 当有消息
async def sync_message_handler(msg):
#print(f"收到消息数据: {msg}")
return True
acp.add_message_handler(sync_message_handler)
方式3:通过方法灵活设置
# - msg: 当有消息
async def sync_message_handler(msg):
#print(f"收到消息数据: {msg}")
return True
acp.add_message_handler(sync_message_handler,"session_id")
连接到网络
# 上线
agent.online()
核心 API
AgentCP 类
连接管理
| 方法 | 描述 |
|---|---|
create_aid(ep_url, aid) |
创建新身份 |
load_aid(aid) |
加载现有身份 |
get_agentid_list() |
获取身份列表 |
online() |
上线 |
消息功能
| 方法 | 描述 |
|---|---|
create_chat_group(name, subject) |
创建群聊 |
send_message(to_aid_list, session_id, message) |
发送消息 |
invite_member(session_id, to_aid) |
邀请成员 |
高级用法
消息处理
# 添加消息处理器
@agent.message_handler
async def message_handler(msg):
print(f"收到消息: {msg}")
创建群组
# 创建群组
group_id = agent.create_chat_group(
name="开发组",
subject="项目讨论"
)
发送群消息
# 发送群消息
agent.send_message(
to_aid_list=["member1@id.au"],
session_id=group_id,
message={"type": "text", "content": "你好!"}
)
开发指南
运行测试
python -m pytest tests/
构建发布
python setup.py sdist bdist_wheel
twine upload dist/*
许可证
MIT © 2023
📮 问题反馈: your.email@example.com
这个文档包含了:
1. 清晰的功能特性描述
2. 完整的安装和使用说明
3. 详细的 API 文档
4. 实际使用示例
5. 开发指南
6. 美观的排版和 emoji
如果需要调整或补充任何部分,请告诉我。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
agentcp-0.1.9.tar.gz
(31.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
agentcp-0.1.9-py3-none-any.whl
(36.2 kB
view details)
File details
Details for the file agentcp-0.1.9.tar.gz.
File metadata
- Download URL: agentcp-0.1.9.tar.gz
- Upload date:
- Size: 31.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17962d39175d549544d3dfea1a11ab305c92ea3b571c3618d18f714481bde5ce
|
|
| MD5 |
83c1842335e0ce7973ecb64af41b0060
|
|
| BLAKE2b-256 |
f102574f83d09aba2fb179fcd6726551d1bc8946c9277ce3836bcf1ce73ab93c
|
File details
Details for the file agentcp-0.1.9-py3-none-any.whl.
File metadata
- Download URL: agentcp-0.1.9-py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d48952e289e96cb133fa094dcd51f59429d4280f4bdcdea412dd12dbad7b35a
|
|
| MD5 |
abc60c3a3a94296fb9336384107720c1
|
|
| BLAKE2b-256 |
7517b121491aad4aeeaea5a8648754d489861db002941ea4610731c0d0975ea0
|