agentnexus-sdk 0.8.0__tar.gz

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.
@@ -0,0 +1,37 @@
1
+ # --- Python 基础 ---
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ .pytest_cache/
6
+ .venv/
7
+ venv/
8
+ env/
9
+ build/
10
+ dist/
11
+
12
+ # --- 操作系统与 IDE ---
13
+ .DS_Store
14
+ .idea/
15
+ .vscode/
16
+ *.swp
17
+
18
+ # --- AgentNexus 运行时数据 ---
19
+ data/ # 运行时生成:DB、token、白/黑名单、配置
20
+
21
+ # --- AgentNexus 核心安全 (非常重要!) ---
22
+ # 绝不要上传任何包含私钥的文件
23
+ *.key
24
+ *.pem
25
+ identity/*.json
26
+ !identity/profile.example.json # 允许上传示例模板
27
+ *.db # 排除本地 SQLite 数据库
28
+ *.log # 排除运行日志
29
+
30
+ # --- AI 助手上下文 ---
31
+ claude.md
32
+ trae.md
33
+ .claudecode/
34
+
35
+ # --- 配置文件 ---
36
+ .env
37
+ config.local.yaml
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentnexus-sdk
3
+ Version: 0.8.0
4
+ Summary: AgentNexus Python SDK - 3 lines to connect your AI Agent to the decentralized network
5
+ Project-URL: Homepage, https://github.com/anthropics/agentnexus
6
+ Project-URL: Documentation, https://github.com/anthropics/agentnexus#readme
7
+ Author: AgentNexus Team
8
+ License-Expression: MIT
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Requires-Python: >=3.10
18
+ Requires-Dist: aiohttp>=3.9.0
19
+ Requires-Dist: pydantic>=2.0.0
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
22
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
File without changes
@@ -0,0 +1,86 @@
1
+ """
2
+ Example: Multi-Agent Discussion Demo
3
+
4
+ Demonstrates how to start a discussion, vote, and conclude.
5
+ """
6
+ import asyncio
7
+ import agentnexus
8
+ from agentnexus import (
9
+ Consensus,
10
+ ConsensusMode,
11
+ TimeoutAction,
12
+ ActionItem,
13
+ ConclusionType,
14
+ DiscussionManager,
15
+ )
16
+
17
+
18
+ async def main():
19
+ # Connect to AgentNexus network
20
+ nexus = await agentnexus.connect(
21
+ name="DiscussionLeader",
22
+ caps=["Chat", "Discussion"],
23
+ )
24
+
25
+ print(f"Connected as: {nexus.agent_info.did}")
26
+
27
+ # Create discussion manager
28
+ discussion_mgr = DiscussionManager(nexus)
29
+
30
+ # Start a discussion with majority voting
31
+ topic_id = await discussion_mgr.start_discussion(
32
+ title="Should we use async or sync API?",
33
+ participants=[
34
+ "did:agentnexus:z6Mk...dev1", # Replace with actual DIDs
35
+ "did:agentnexus:z6Mk...dev2",
36
+ ],
37
+ context="We need to decide on the API style for the SDK.",
38
+ consensus=Consensus(
39
+ mode=ConsensusMode.MAJORITY,
40
+ timeout_seconds=300, # 5 minutes
41
+ timeout_action=TimeoutAction.AUTO_REJECT,
42
+ ),
43
+ related_task_id="task_sdk_design",
44
+ )
45
+
46
+ print(f"Started discussion: {topic_id}")
47
+
48
+ # Simulate discussion flow
49
+ await asyncio.sleep(2)
50
+
51
+ # Reply to discussion
52
+ await discussion_mgr.reply(
53
+ topic_id=topic_id,
54
+ content="I prefer async API because it's more flexible.",
55
+ )
56
+
57
+ # Cast vote
58
+ await discussion_mgr.vote(
59
+ topic_id=topic_id,
60
+ vote="approve",
61
+ reason="Async is the way to go",
62
+ )
63
+
64
+ # After voting completes (simulated), conclude
65
+ await asyncio.sleep(2)
66
+
67
+ await discussion_mgr.conclude(
68
+ topic_id=topic_id,
69
+ conclusion="We will use async API with sync wrapper as optional",
70
+ conclusion_type=ConclusionType.CONSENSUS,
71
+ action_items=[
72
+ ActionItem(
73
+ type="update_document",
74
+ ref="adr-006",
75
+ description="Update SDK architecture doc with async-first approach",
76
+ ),
77
+ ],
78
+ )
79
+
80
+ print("Discussion concluded!")
81
+
82
+ await nexus.close()
83
+
84
+
85
+ if __name__ == "__main__":
86
+ asyncio.run(main())
@@ -0,0 +1,71 @@
1
+ """
2
+ Example: Echo Bot with Discussion Protocol
3
+
4
+ A simple bot that echoes messages and demonstrates discussion capabilities.
5
+ """
6
+ import asyncio
7
+ import agentnexus
8
+ from agentnexus import (
9
+ Consensus,
10
+ ConsensusMode,
11
+ TimeoutAction,
12
+ ActionItem,
13
+ ConclusionType,
14
+ )
15
+
16
+
17
+ async def main():
18
+ # Connect to AgentNexus network
19
+ nexus = await agentnexus.connect(
20
+ name="EchoBot",
21
+ caps=["Chat", "Discussion"],
22
+ )
23
+
24
+ print(f"Connected as: {nexus.agent_info.did}")
25
+
26
+ # Message handler
27
+ @nexus.on_message
28
+ async def handle_message(msg):
29
+ print(f"[MSG] From {msg.from_did}: {msg.content}")
30
+
31
+ # Echo back
32
+ await nexus.send(
33
+ to_did=msg.from_did,
34
+ content=f"Echo: {msg.content}",
35
+ )
36
+
37
+ # Task proposal handler
38
+ @nexus.on_task_propose
39
+ async def handle_task_propose(action):
40
+ print(f"[TASK] New task: {action.content['title']}")
41
+
42
+ # Claim the task
43
+ await nexus.claim_task(
44
+ to_did=action.from_did,
45
+ task_id=action.content["task_id"],
46
+ message="I'll handle this!",
47
+ )
48
+
49
+ # Simulate work
50
+ await asyncio.sleep(1)
51
+
52
+ # Notify completion
53
+ await nexus.notify_state(
54
+ to_did=action.from_did,
55
+ status="completed",
56
+ task_id=action.content["task_id"],
57
+ )
58
+
59
+ # Keep running
60
+ print("EchoBot is running. Press Ctrl+C to stop.")
61
+ try:
62
+ while True:
63
+ await asyncio.sleep(1)
64
+ except KeyboardInterrupt:
65
+ pass
66
+ finally:
67
+ await nexus.close()
68
+
69
+
70
+ if __name__ == "__main__":
71
+ asyncio.run(main())
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "agentnexus-sdk"
7
+ version = "0.8.0"
8
+ description = "AgentNexus Python SDK - 3 lines to connect your AI Agent to the decentralized network"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
12
+ authors = [
13
+ { name = "AgentNexus Team" }
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ ]
25
+ dependencies = [
26
+ "aiohttp>=3.9.0",
27
+ "pydantic>=2.0.0",
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ dev = [
32
+ "pytest>=8.0.0",
33
+ "pytest-asyncio>=0.23.0",
34
+ ]
35
+
36
+ [project.urls]
37
+ Homepage = "https://github.com/anthropics/agentnexus"
38
+ Documentation = "https://github.com/anthropics/agentnexus#readme"
39
+
40
+ [tool.hatch.build.targets.wheel]
41
+ packages = ["src/agentnexus"]
42
+
43
+ [tool.pytest.ini_options]
44
+ asyncio_mode = "auto"
@@ -0,0 +1,109 @@
1
+ # AgentNexus Skill
2
+ #
3
+ # 标准化能力描述文件,供 AI Agent 框架自动发现和安装 AgentNexus 通信能力。
4
+ # 兼容 OpenClaw Skill 规范。
5
+
6
+ name: agentnexus
7
+ version: 0.1.0
8
+ description: "给你的 AI Agent 接入去中心化通信网络 — DID 身份、加密消息、联邦发现、协作协议"
9
+ description_en: "Connect your AI Agent to a decentralized communication network — DID identity, encrypted messaging, federated discovery, collaboration protocol"
10
+
11
+ author: AgentNexus Team
12
+ license: Apache-2.0
13
+ homepage: https://github.com/kevinkaylie/AgentNexus
14
+ repository: https://github.com/kevinkaylie/AgentNexus
15
+
16
+ # 运行要求
17
+ requirements:
18
+ python: ">=3.10"
19
+ packages:
20
+ - agentnexus-sdk>=0.1.0
21
+ services:
22
+ - name: agentnexus-daemon
23
+ description: "AgentNexus Node Daemon(本地通信节点)"
24
+ start_command: "python main.py node start"
25
+ health_check: "http://localhost:8765/health"
26
+
27
+ # Skill 提供的能力
28
+ capabilities:
29
+ - id: messaging
30
+ name: "Agent 消息收发"
31
+ description: "向任意 DID 地址发送加密消息,接收离线消息"
32
+ actions:
33
+ - send_message
34
+ - receive_message
35
+
36
+ - id: discovery
37
+ name: "Agent 发现"
38
+ description: "按能力关键词搜索其他 Agent,联邦 Relay 跨网查找"
39
+ actions:
40
+ - search_agents
41
+
42
+ - id: collaboration
43
+ name: "协作协议"
44
+ description: "四种基础协作动作:任务发布/认领/资源同步/状态汇报"
45
+ actions:
46
+ - propose_task
47
+ - claim_task
48
+ - sync_resource
49
+ - notify_state
50
+
51
+ - id: trust
52
+ name: "信任验证"
53
+ description: "L1-L4 信任等级验证,CA 认证签发与查询"
54
+ actions:
55
+ - verify_agent
56
+ - certify_agent
57
+
58
+ # 快速接入(Agent 框架读取此段自动初始化)
59
+ quickstart:
60
+ async: |
61
+ import agentnexus
62
+
63
+ nexus = await agentnexus.connect("${AGENT_NAME}", caps=${AGENT_CAPS})
64
+
65
+ # 发消息
66
+ await nexus.send(to_did="${TARGET_DID}", content="Hello from ${AGENT_NAME}!")
67
+
68
+ # 收消息
69
+ @nexus.on_message
70
+ async def handle(msg):
71
+ print(f"From {msg.from_did}: {msg.content}")
72
+
73
+ # 协作
74
+ task_id = await nexus.propose_task(to_did="${TARGET_DID}", title="协作任务")
75
+
76
+ sync: |
77
+ import agentnexus.sync
78
+
79
+ nexus = agentnexus.sync.connect("${AGENT_NAME}", caps=${AGENT_CAPS})
80
+ nexus.send(to_did="${TARGET_DID}", content="Hello!")
81
+ nexus.close()
82
+
83
+ # 变量说明(框架在安装时提示用户填写或自动推断)
84
+ variables:
85
+ AGENT_NAME:
86
+ description: "Agent 名称"
87
+ required: true
88
+ example: "MyAssistant"
89
+ AGENT_CAPS:
90
+ description: "Agent 能力列表"
91
+ required: false
92
+ default: '["Chat"]'
93
+ example: '["Chat", "Search", "Translation"]'
94
+ TARGET_DID:
95
+ description: "目标 Agent 的 DID 地址"
96
+ required: false
97
+ example: "did:agentnexus:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"
98
+
99
+ # MCP 集成(已有 MCP Server 的 Agent 可直接用 MCP 工具)
100
+ mcp:
101
+ enabled: true
102
+ config:
103
+ command: "python"
104
+ args: ["main.py", "node", "mcp", "--name", "${AGENT_NAME}", "--caps", "${AGENT_CAPS}"]
105
+ tools_count: 15
106
+ compatible_clients:
107
+ - Claude Desktop
108
+ - Cursor
109
+ - Claude Code
@@ -0,0 +1,102 @@
1
+ """
2
+ AgentNexus Python SDK
3
+
4
+ 3 lines to connect your AI Agent to the decentralized network.
5
+
6
+ Usage:
7
+ import agentnexus
8
+
9
+ # Register new identity
10
+ nexus = await agentnexus.connect("MyAgent", caps=["Chat", "Search"])
11
+
12
+ # Or use existing identity
13
+ nexus = await agentnexus.connect(did="did:agentnexus:z6Mk...")
14
+
15
+ # Send message
16
+ await nexus.send(to_did="did:agentnexus:z6Mk...", content="Hello!")
17
+
18
+ # Receive messages
19
+ @nexus.on_message
20
+ async def handle(msg):
21
+ print(f"From {msg.from_did}: {msg.content}")
22
+
23
+ # Close connection
24
+ await nexus.close()
25
+ """
26
+
27
+ from .client import AgentNexusClient, connect
28
+ from .exceptions import (
29
+ AgentNexusError,
30
+ DaemonNotFoundError,
31
+ AuthenticationError,
32
+ AgentNotFoundError,
33
+ MessageDeliveryError,
34
+ InvalidActionError,
35
+ DIDNotFoundError,
36
+ )
37
+ from .models import Message, VerificationResult, Certification
38
+ from .actions import (
39
+ TaskPropose,
40
+ TaskClaim,
41
+ ResourceSync,
42
+ StateNotify,
43
+ )
44
+ from .discussion import (
45
+ DiscussionStart,
46
+ DiscussionReply,
47
+ DiscussionVote,
48
+ DiscussionConclude,
49
+ Consensus,
50
+ ActionItem,
51
+ ConsensusMode,
52
+ TimeoutAction,
53
+ ConclusionType,
54
+ DiscussionStateMachine,
55
+ DiscussionManager,
56
+ )
57
+ from .emergency import (
58
+ EmergencyConfig,
59
+ EmergencyController,
60
+ create_emergency_controller,
61
+ )
62
+
63
+ __all__ = [
64
+ # Core
65
+ "connect",
66
+ "AgentNexusClient",
67
+ # Exceptions
68
+ "AgentNexusError",
69
+ "DaemonNotFoundError",
70
+ "AuthenticationError",
71
+ "AgentNotFoundError",
72
+ "MessageDeliveryError",
73
+ "InvalidActionError",
74
+ "DIDNotFoundError",
75
+ # Models
76
+ "Message",
77
+ "VerificationResult",
78
+ "Certification",
79
+ # Actions
80
+ "TaskPropose",
81
+ "TaskClaim",
82
+ "ResourceSync",
83
+ "StateNotify",
84
+ # Discussion
85
+ "DiscussionStart",
86
+ "DiscussionReply",
87
+ "DiscussionVote",
88
+ "DiscussionConclude",
89
+ "Consensus",
90
+ "ActionItem",
91
+ "ConsensusMode",
92
+ "TimeoutAction",
93
+ "ConclusionType",
94
+ "DiscussionStateMachine",
95
+ "DiscussionManager",
96
+ # Emergency
97
+ "EmergencyConfig",
98
+ "EmergencyController",
99
+ "create_emergency_controller",
100
+ ]
101
+
102
+ __version__ = "0.1.0"