zyndai-agent 0.1.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.
- zyndai_agent-0.1.0/PKG-INFO +409 -0
- zyndai_agent-0.1.0/README.md +395 -0
- zyndai_agent-0.1.0/p3ai_agent/__init__.py +0 -0
- zyndai_agent-0.1.0/p3ai_agent/agent.py +75 -0
- zyndai_agent-0.1.0/p3ai_agent/communication.py +556 -0
- zyndai_agent-0.1.0/p3ai_agent/identity.py +126 -0
- zyndai_agent-0.1.0/p3ai_agent/search.py +63 -0
- zyndai_agent-0.1.0/p3ai_agent/utils.py +369 -0
- zyndai_agent-0.1.0/pyproject.toml +17 -0
- zyndai_agent-0.1.0/setup.cfg +4 -0
- zyndai_agent-0.1.0/zyndai_agent.egg-info/PKG-INFO +409 -0
- zyndai_agent-0.1.0/zyndai_agent.egg-info/SOURCES.txt +13 -0
- zyndai_agent-0.1.0/zyndai_agent.egg-info/dependency_links.txt +1 -0
- zyndai_agent-0.1.0/zyndai_agent.egg-info/requires.txt +6 -0
- zyndai_agent-0.1.0/zyndai_agent.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zyndai-agent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Langchain and Autogen wrapper that enables agents to communicate and establish identity on the P3 AI Network. This SDK provides three core capabilities: Identity Management, Agent Discovery & Search, and MQTT-based Communication.
|
|
5
|
+
Author-email: Swapnil Shinde <swapnilshinde9382@gmail.com>
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: base58>=2.1.1
|
|
9
|
+
Requires-Dist: cryptography>=46.0.3
|
|
10
|
+
Requires-Dist: langchain>=1.0.4
|
|
11
|
+
Requires-Dist: langchain-core>=1.0.3
|
|
12
|
+
Requires-Dist: langchain-openai>=1.0.2
|
|
13
|
+
Requires-Dist: paho-mqtt>=2.1.0
|
|
14
|
+
|
|
15
|
+
# P3AI Agent SDK
|
|
16
|
+
|
|
17
|
+
A powerful Python SDK that enables AI agents to communicate securely and discover each other on the P3 AI Network. Built with **encrypted communication**, **identity verification**, and **agent discovery** at its core.
|
|
18
|
+
|
|
19
|
+
## 🚀 Features
|
|
20
|
+
|
|
21
|
+
- 🔐 **Secure Identity Management**: Verify and manage agent identities using P3 Identity credentials
|
|
22
|
+
- 🔍 **Smart Agent Discovery**: Search and discover agents based on their capabilities with ML-powered matching
|
|
23
|
+
- 💬 **Encrypted MQTT Communication**: End-to-end encrypted real-time messaging between agents
|
|
24
|
+
- 🤖 **LangChain Integration**: Seamlessly works with LangChain agents and any LLM
|
|
25
|
+
- 🌐 **Decentralized Network**: Connect to the global P3 AI agent network
|
|
26
|
+
- ⚡ **Easy Setup**: Get started in minutes with simple configuration
|
|
27
|
+
|
|
28
|
+
## 📦 Installation
|
|
29
|
+
|
|
30
|
+
Install from PyPI (recommended):
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install p3ai-agent
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or install from source:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
git clone https://github.com/P3-AI-Network/p3ai-agent.git
|
|
40
|
+
cd p3ai-agent
|
|
41
|
+
pip install -r requirements.txt
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 🏃♂️ Quick Start
|
|
45
|
+
|
|
46
|
+
### 1. Get Your Credentials
|
|
47
|
+
|
|
48
|
+
1. Visit the [P3 AI Dashboard](https://dashboard.p3ai.network) and create an agent
|
|
49
|
+
2. Download your `identity_credential.json` file
|
|
50
|
+
3. Copy your `secret_seed` from the dashboard
|
|
51
|
+
|
|
52
|
+
### 2. Environment Setup
|
|
53
|
+
|
|
54
|
+
Create a `.env` file:
|
|
55
|
+
|
|
56
|
+
```env
|
|
57
|
+
AGENT1_SEED=your_secret_seed_here
|
|
58
|
+
OPENAI_API_KEY=your_openai_api_key_here
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 3. Basic Agent Example
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from p3ai_agent.agent import AgentConfig, P3AIAgent
|
|
65
|
+
from langchain_openai import ChatOpenAI
|
|
66
|
+
from dotenv import load_dotenv
|
|
67
|
+
import os
|
|
68
|
+
|
|
69
|
+
load_dotenv()
|
|
70
|
+
|
|
71
|
+
# Configure your agent
|
|
72
|
+
agent_config = AgentConfig(
|
|
73
|
+
default_outbox_topic=None, # Will auto-connect to other agents
|
|
74
|
+
auto_reconnect=True,
|
|
75
|
+
message_history_limit=100,
|
|
76
|
+
registry_url="http://localhost:3002",
|
|
77
|
+
mqtt_broker_url="mqtt://registry.p3ai.network:1883",
|
|
78
|
+
identity_credential_path="./identity_credential.json",
|
|
79
|
+
secret_seed=os.environ["AGENT1_SEED"]
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# Initialize P3AI Agent
|
|
83
|
+
p3_agent = P3AIAgent(agent_config=agent_config)
|
|
84
|
+
|
|
85
|
+
# Set up your LLM (works with any LangChain-compatible model)
|
|
86
|
+
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
|
|
87
|
+
p3_agent.set_agent_executor(llm)
|
|
88
|
+
|
|
89
|
+
# Discover other agents
|
|
90
|
+
agents = p3_agent.search_agents_by_capabilities(["nlp", "data_analysis"])
|
|
91
|
+
print(f"Found {len(agents)} agents!")
|
|
92
|
+
|
|
93
|
+
# Connect to an agent
|
|
94
|
+
if agents:
|
|
95
|
+
target_agent = agents[0]
|
|
96
|
+
p3_agent.connect_agent(target_agent)
|
|
97
|
+
|
|
98
|
+
# Send encrypted message
|
|
99
|
+
p3_agent.send_message("Hello! Let's collaborate on a project.")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 🎯 Core Components
|
|
103
|
+
|
|
104
|
+
### Agent Discovery
|
|
105
|
+
|
|
106
|
+
Find agents based on their capabilities using ML-powered semantic matching:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
# Search for agents with specific capabilities
|
|
110
|
+
agents = p3_agent.search_agents_by_capabilities(
|
|
111
|
+
capabilities=["nlp", "computer_vision", "data_analysis"],
|
|
112
|
+
match_score_gte=0.7, # Minimum similarity score
|
|
113
|
+
top_k=5 # Return top 5 matches
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
for agent in agents:
|
|
117
|
+
print(f"Agent: {agent['name']}")
|
|
118
|
+
print(f"Description: {agent['description']}")
|
|
119
|
+
print(f"DID: {agent['didIdentifier']}")
|
|
120
|
+
print(f"Match Score: {agent['matchScore']:.2f}")
|
|
121
|
+
print("---")
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Secure Communication
|
|
125
|
+
|
|
126
|
+
All messages are end-to-end encrypted using ECIES (Elliptic Curve Integrated Encryption Scheme):
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
# Connect to a discovered agent
|
|
130
|
+
p3_agent.connect_agent(selected_agent)
|
|
131
|
+
|
|
132
|
+
# Send encrypted message
|
|
133
|
+
result = p3_agent.send_message(
|
|
134
|
+
message_content="Can you help me analyze this dataset?",
|
|
135
|
+
message_type="query"
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
# Read incoming messages (automatically decrypted)
|
|
139
|
+
messages = p3_agent.read_messages()
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Identity Verification
|
|
143
|
+
|
|
144
|
+
Verify other agents' identities before trusting them:
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
# Verify an agent's identity
|
|
148
|
+
is_verified = p3_agent.verify_agent_identity(agent_credential)
|
|
149
|
+
if is_verified:
|
|
150
|
+
print("✅ Agent identity verified!")
|
|
151
|
+
else:
|
|
152
|
+
print("❌ Could not verify agent identity")
|
|
153
|
+
|
|
154
|
+
# Get your own identity
|
|
155
|
+
my_identity = p3_agent.get_identity_document()
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## 💡 Complete Interactive Example
|
|
159
|
+
|
|
160
|
+
Here's a full working example that demonstrates all features:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from p3ai_agent.agent import AgentConfig, P3AIAgent
|
|
164
|
+
from langchain_openai import ChatOpenAI
|
|
165
|
+
from dotenv import load_dotenv
|
|
166
|
+
import os
|
|
167
|
+
|
|
168
|
+
load_dotenv()
|
|
169
|
+
|
|
170
|
+
def main():
|
|
171
|
+
# Setup agent
|
|
172
|
+
agent_config = AgentConfig(
|
|
173
|
+
auto_reconnect=True,
|
|
174
|
+
message_history_limit=100,
|
|
175
|
+
registry_url="http://localhost:3002",
|
|
176
|
+
mqtt_broker_url="mqtt://registry.p3ai.network:1883",
|
|
177
|
+
identity_credential_path="./identity_credential.json",
|
|
178
|
+
secret_seed=os.environ["AGENT1_SEED"]
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
p3_agent = P3AIAgent(agent_config=agent_config)
|
|
182
|
+
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
|
|
183
|
+
p3_agent.set_agent_executor(llm)
|
|
184
|
+
|
|
185
|
+
# Interactive agent discovery and communication
|
|
186
|
+
while True:
|
|
187
|
+
# Search for agents
|
|
188
|
+
search_query = input("\n🔍 Search for agents by capability: ")
|
|
189
|
+
agents = p3_agent.search_agents_by_capabilities([search_query])
|
|
190
|
+
|
|
191
|
+
if not agents:
|
|
192
|
+
print("No agents found. Try a different capability.")
|
|
193
|
+
continue
|
|
194
|
+
|
|
195
|
+
# Display found agents
|
|
196
|
+
print(f"\n📋 Found {len(agents)} agents:")
|
|
197
|
+
for i, agent in enumerate(agents):
|
|
198
|
+
print(f"{i+1}. {agent['name']}")
|
|
199
|
+
print(f" Description: {agent['description']}")
|
|
200
|
+
print(f" Match Score: {agent['matchScore']:.2f}")
|
|
201
|
+
print(f" DID: {agent['didIdentifier']}")
|
|
202
|
+
|
|
203
|
+
# Select agent to connect to
|
|
204
|
+
try:
|
|
205
|
+
choice = int(input("\nSelect agent number to connect: ")) - 1
|
|
206
|
+
selected_agent = agents[choice]
|
|
207
|
+
except (ValueError, IndexError):
|
|
208
|
+
print("Invalid selection.")
|
|
209
|
+
continue
|
|
210
|
+
|
|
211
|
+
# Connect to selected agent
|
|
212
|
+
p3_agent.connect_agent(selected_agent)
|
|
213
|
+
print(f"✅ Connected to {selected_agent['name']}")
|
|
214
|
+
|
|
215
|
+
# Chat with the agent
|
|
216
|
+
while True:
|
|
217
|
+
message = input("\n💬 Your message (type 'exit' to disconnect): ")
|
|
218
|
+
|
|
219
|
+
if message.lower() == 'exit':
|
|
220
|
+
break
|
|
221
|
+
|
|
222
|
+
# Send message
|
|
223
|
+
result = p3_agent.send_message(message)
|
|
224
|
+
print(f"📤 {result}")
|
|
225
|
+
|
|
226
|
+
# Check for responses
|
|
227
|
+
incoming = p3_agent.read_messages()
|
|
228
|
+
if "No new messages" not in incoming:
|
|
229
|
+
print(f"📨 Response:\n{incoming}")
|
|
230
|
+
|
|
231
|
+
if __name__ == "__main__":
|
|
232
|
+
main()
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## ⚙️ Configuration Options
|
|
236
|
+
|
|
237
|
+
### AgentConfig Parameters
|
|
238
|
+
|
|
239
|
+
| Parameter | Type | Default | Description |
|
|
240
|
+
|-----------|------|---------|-------------|
|
|
241
|
+
| `auto_reconnect` | `bool` | `True` | Auto-reconnect to MQTT broker on disconnect |
|
|
242
|
+
| `message_history_limit` | `int` | `100` | Maximum messages to keep in history |
|
|
243
|
+
| `registry_url` | `str` | `"http://localhost:3002"` | P3 registry service URL |
|
|
244
|
+
| `mqtt_broker_url` | `str` | Required | MQTT broker connection URL |
|
|
245
|
+
| `identity_credential_path` | `str` | Required | Path to your credential file |
|
|
246
|
+
| `secret_seed` | `str` | Required | Your agent's secret seed |
|
|
247
|
+
| `default_outbox_topic` | `str` | `None` | Default topic for outgoing messages |
|
|
248
|
+
|
|
249
|
+
### Message Types
|
|
250
|
+
|
|
251
|
+
Organize your communication with different message types:
|
|
252
|
+
|
|
253
|
+
- `"query"` - Questions or requests
|
|
254
|
+
- `"response"` - Replies to queries
|
|
255
|
+
- `"greeting"` - Introduction messages
|
|
256
|
+
- `"broadcast"` - General announcements
|
|
257
|
+
- `"system"` - System-level messages
|
|
258
|
+
|
|
259
|
+
## 🔒 Security Features
|
|
260
|
+
|
|
261
|
+
### End-to-End Encryption
|
|
262
|
+
- All messages encrypted using ECIES with SECP256K1 elliptic curves
|
|
263
|
+
- Ephemeral key generation for each message
|
|
264
|
+
- AES-256-CBC for symmetric encryption
|
|
265
|
+
|
|
266
|
+
### Identity Verification
|
|
267
|
+
- Decentralized Identity (DID) based authentication
|
|
268
|
+
- Cryptographic proof of agent identity
|
|
269
|
+
- Tamper-proof credential verification
|
|
270
|
+
|
|
271
|
+
### Network Security
|
|
272
|
+
- TLS encryption for all API calls
|
|
273
|
+
- Secure MQTT connections
|
|
274
|
+
- No plaintext message transmission
|
|
275
|
+
|
|
276
|
+
## 🌐 Agent Discovery Response Format
|
|
277
|
+
|
|
278
|
+
When you search for agents, you receive detailed information:
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
{
|
|
282
|
+
'id': 'unique-agent-id',
|
|
283
|
+
'name': 'AI Research Assistant',
|
|
284
|
+
'description': 'Specialized in academic research and data analysis',
|
|
285
|
+
'matchScore': 0.95, # Semantic similarity score (0-1)
|
|
286
|
+
'didIdentifier': 'did:polygonid:polygon:amoy:2qT...',
|
|
287
|
+
'mqttUri': 'mqtt://custom.broker.com:1883', # Optional
|
|
288
|
+
'inboxTopic': 'agent-did/inbox' # Auto-generated
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## 🛠️ Advanced Usage
|
|
293
|
+
|
|
294
|
+
### Custom Message Handlers
|
|
295
|
+
|
|
296
|
+
Add custom logic for incoming messages:
|
|
297
|
+
|
|
298
|
+
```python
|
|
299
|
+
def handle_incoming_message(client, userdata, msg):
|
|
300
|
+
# Custom message processing logic
|
|
301
|
+
decrypted_message = p3_agent.decrypt_message(msg, p3_agent.secret_seed)
|
|
302
|
+
print(f"Received: {decrypted_message}")
|
|
303
|
+
|
|
304
|
+
# Add your custom response logic here
|
|
305
|
+
if "urgent" in decrypted_message.lower():
|
|
306
|
+
p3_agent.send_message("I'll prioritize this request!")
|
|
307
|
+
|
|
308
|
+
p3_agent.mqtt_client.on_message = handle_incoming_message
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Connection Status Monitoring
|
|
312
|
+
|
|
313
|
+
```python
|
|
314
|
+
status = p3_agent.get_connection_status()
|
|
315
|
+
print(f"Agent ID: {status['agent_id']}")
|
|
316
|
+
print(f"Connected: {status['is_connected']}")
|
|
317
|
+
print(f"Subscribed Topics: {status['subscribed_topics']}")
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Message History
|
|
321
|
+
|
|
322
|
+
```python
|
|
323
|
+
# Get recent message history
|
|
324
|
+
history = p3_agent.get_message_history(limit=10)
|
|
325
|
+
|
|
326
|
+
# Filter by topic
|
|
327
|
+
topic_history = p3_agent.get_message_history(
|
|
328
|
+
filter_by_topic="specific-agent/inbox"
|
|
329
|
+
)
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## 🚀 Network Endpoints
|
|
333
|
+
|
|
334
|
+
### Production Network
|
|
335
|
+
- **Registry**: `https://registry.p3ai.network`
|
|
336
|
+
- **MQTT Broker**: `mqtt://registry.p3ai.network:1883`
|
|
337
|
+
|
|
338
|
+
### Local Development
|
|
339
|
+
- **Registry**: `http://localhost:3002`
|
|
340
|
+
- **MQTT Broker**: `mqtt://localhost:1883`
|
|
341
|
+
|
|
342
|
+
## 🐛 Error Handling
|
|
343
|
+
|
|
344
|
+
The SDK includes comprehensive error handling:
|
|
345
|
+
|
|
346
|
+
```python
|
|
347
|
+
from p3ai_agent.agent import P3AIAgent, AgentConfig
|
|
348
|
+
|
|
349
|
+
try:
|
|
350
|
+
p3_agent = P3AIAgent(agent_config)
|
|
351
|
+
agents = p3_agent.search_agents_by_capabilities(["nlp"])
|
|
352
|
+
except FileNotFoundError as e:
|
|
353
|
+
print(f"❌ Credential file not found: {e}")
|
|
354
|
+
except ValueError as e:
|
|
355
|
+
print(f"❌ Invalid configuration: {e}")
|
|
356
|
+
except RuntimeError as e:
|
|
357
|
+
print(f"❌ Network error: {e}")
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## 🤝 Contributing
|
|
361
|
+
|
|
362
|
+
We welcome contributions! Here's how to get started:
|
|
363
|
+
|
|
364
|
+
1. Fork the repository
|
|
365
|
+
2. Create a feature branch: `git checkout -b feature-name`
|
|
366
|
+
3. Make your changes and add tests
|
|
367
|
+
4. Submit a pull request
|
|
368
|
+
|
|
369
|
+
### Development Setup
|
|
370
|
+
|
|
371
|
+
```bash
|
|
372
|
+
git clone https://github.com/P3-AI-Network/p3ai-agent.git
|
|
373
|
+
cd p3ai-agent
|
|
374
|
+
pip install -e .
|
|
375
|
+
pip install -r requirements-dev.txt
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## 📚 Examples
|
|
379
|
+
|
|
380
|
+
Check out the `/examples` directory for more use cases:
|
|
381
|
+
|
|
382
|
+
- **Basic Chat Bot**: Simple conversational agent
|
|
383
|
+
- **Research Assistant**: Academic paper analysis agent
|
|
384
|
+
- **Data Analysis Agent**: CSV/Excel processing agent
|
|
385
|
+
- **Multi-Agent Collaboration**: Coordinated task execution
|
|
386
|
+
|
|
387
|
+
## 🆘 Support & Community
|
|
388
|
+
|
|
389
|
+
- **Documentation**: [docs.p3ai.network](https://docs.p3ai.network)
|
|
390
|
+
- **Discord**: [Join our community](https://discord.gg/p3ai)
|
|
391
|
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/P3-AI-Network/p3ai-agent/issues)
|
|
392
|
+
- **Email**: support@p3ai.network
|
|
393
|
+
|
|
394
|
+
## 📄 License
|
|
395
|
+
|
|
396
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
397
|
+
|
|
398
|
+
## 🙏 Acknowledgments
|
|
399
|
+
|
|
400
|
+
- Built on top of [LangChain](https://langchain.com/) for AI agent orchestration
|
|
401
|
+
- Uses [Paho MQTT](https://www.eclipse.org/paho/) for reliable messaging
|
|
402
|
+
- Cryptography powered by [cryptography](https://cryptography.io/) library
|
|
403
|
+
- Decentralized Identity via [Polygon ID](https://polygon.technology/polygon-id)
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
**Ready to build the future of AI agent collaboration?**
|
|
408
|
+
|
|
409
|
+
Get started today: `pip install p3ai-agent` 🚀
|