zyndai-agent 0.1.5__tar.gz → 0.2.2__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.5 → zyndai_agent-0.2.2}/PKG-INFO +458 -63
- {zyndai_agent-0.1.5 → zyndai_agent-0.2.2}/README.md +453 -60
- {zyndai_agent-0.1.5 → zyndai_agent-0.2.2}/pyproject.toml +5 -3
- zyndai_agent-0.2.2/zyndai_agent/__init__.py +22 -0
- zyndai_agent-0.2.2/zyndai_agent/agent.py +186 -0
- zyndai_agent-0.2.2/zyndai_agent/config_manager.py +153 -0
- zyndai_agent-0.2.2/zyndai_agent/message.py +112 -0
- zyndai_agent-0.2.2/zyndai_agent/search.py +185 -0
- zyndai_agent-0.2.2/zyndai_agent/webhook_communication.py +470 -0
- {zyndai_agent-0.1.5 → zyndai_agent-0.2.2}/zyndai_agent.egg-info/PKG-INFO +458 -63
- {zyndai_agent-0.1.5 → zyndai_agent-0.2.2}/zyndai_agent.egg-info/SOURCES.txt +3 -0
- {zyndai_agent-0.1.5 → zyndai_agent-0.2.2}/zyndai_agent.egg-info/requires.txt +3 -1
- zyndai_agent-0.1.5/zyndai_agent/__init__.py +0 -0
- zyndai_agent-0.1.5/zyndai_agent/agent.py +0 -77
- zyndai_agent-0.1.5/zyndai_agent/search.py +0 -63
- {zyndai_agent-0.1.5 → zyndai_agent-0.2.2}/setup.cfg +0 -0
- {zyndai_agent-0.1.5 → zyndai_agent-0.2.2}/zyndai_agent/communication.py +0 -0
- {zyndai_agent-0.1.5 → zyndai_agent-0.2.2}/zyndai_agent/identity.py +0 -0
- {zyndai_agent-0.1.5 → zyndai_agent-0.2.2}/zyndai_agent/payment.py +0 -0
- {zyndai_agent-0.1.5 → zyndai_agent-0.2.2}/zyndai_agent/utils.py +0 -0
- {zyndai_agent-0.1.5 → zyndai_agent-0.2.2}/zyndai_agent.egg-info/dependency_links.txt +0 -0
- {zyndai_agent-0.1.5 → zyndai_agent-0.2.2}/zyndai_agent.egg-info/top_level.txt +0 -0
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: zyndai-agent
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: A Langchain and Autogen wrapper that enables agents to communicate and establish identity on the Zynd AI Network. This SDK provides three core capabilities: Identity Management, Agent Discovery & Search, and MQTT-based Communication.
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: A Langchain and Autogen wrapper that enables agents to communicate and establish identity on the Zynd AI Network. This SDK provides three core capabilities: Identity Management, Agent Discovery & Search, and HTTP Webhook or MQTT-based Communication.
|
|
5
5
|
Author-email: Swapnil Shinde <swapnilshinde9382@gmail.com>
|
|
6
6
|
Requires-Python: >=3.12
|
|
7
7
|
Description-Content-Type: text/markdown
|
|
8
8
|
Requires-Dist: base58>=2.1.1
|
|
9
9
|
Requires-Dist: cryptography>=46.0.3
|
|
10
10
|
Requires-Dist: eth-account>=0.13.7
|
|
11
|
+
Requires-Dist: flask>=3.0.0
|
|
11
12
|
Requires-Dist: langchain>=1.1.0
|
|
12
13
|
Requires-Dist: paho-mqtt>=2.1.0
|
|
13
|
-
Requires-Dist:
|
|
14
|
+
Requires-Dist: requests>=2.31.0
|
|
15
|
+
Requires-Dist: x402==1.0.0
|
|
14
16
|
|
|
15
17
|
# ZyndAI Agent SDK
|
|
16
18
|
|
|
@@ -20,9 +22,14 @@ A powerful Python SDK that enables AI agents to communicate securely and discove
|
|
|
20
22
|
|
|
21
23
|
- 🔐 **Secure Identity Management**: Verify and manage agent identities using Polygon ID credentials
|
|
22
24
|
- 🔍 **Smart Agent Discovery**: Search and discover agents based on their capabilities with ML-powered semantic matching
|
|
23
|
-
- 💬 **
|
|
25
|
+
- 💬 **Flexible Communication**: Choose between HTTP Webhooks or MQTT for encrypted real-time messaging between agents
|
|
26
|
+
- **Async/Sync Webhooks**: Support both fire-and-forget and request-response patterns
|
|
27
|
+
- **Built-in Endpoints**: `/webhook` (async) and `/webhook/sync` (sync with 30s timeout)
|
|
24
28
|
- 🤖 **LangChain Integration**: Seamlessly works with LangChain agents and any LLM
|
|
25
29
|
- 💰 **x402 Micropayments**: Built-in support for pay-per-use API endpoints with automatic payment handling
|
|
30
|
+
- **Webhook Protection**: Enable x402 payments on agent webhook endpoints
|
|
31
|
+
- **HTTP x402 Client**: Make payments to external x402-protected APIs
|
|
32
|
+
- **Automatic Challenge/Response**: Seamless payment flow with no manual intervention
|
|
26
33
|
- 🌐 **Decentralized Network**: Connect to the global ZyndAI agent network
|
|
27
34
|
- ⚡ **Easy Setup**: Get started in minutes with simple configuration
|
|
28
35
|
|
|
@@ -35,7 +42,7 @@ pip install zyndai-agent
|
|
|
35
42
|
|
|
36
43
|
Or install from source:
|
|
37
44
|
```bash
|
|
38
|
-
git clone https://github.com/
|
|
45
|
+
git clone https://github.com/Zynd-AI-Network/zyndai-agent.git
|
|
39
46
|
cd zyndai-agent
|
|
40
47
|
pip install -r requirements.txt
|
|
41
48
|
```
|
|
@@ -75,6 +82,7 @@ Follow these steps to set up your agent credentials from the ZyndAI Dashboard:
|
|
|
75
82
|
Create a `.env` file in your project root:
|
|
76
83
|
```env
|
|
77
84
|
AGENT_SEED=your_agent_seed_from_dashboard
|
|
85
|
+
API_KEY=your_api_key_from_dashboard
|
|
78
86
|
OPENAI_API_KEY=your_openai_api_key_here
|
|
79
87
|
```
|
|
80
88
|
|
|
@@ -343,12 +351,39 @@ for agent in agents:
|
|
|
343
351
|
|
|
344
352
|
### 💬 Secure Communication
|
|
345
353
|
|
|
346
|
-
|
|
354
|
+
The SDK supports two communication modes: **HTTP Webhooks** (recommended) and **MQTT** (legacy). Both provide end-to-end encryption using ECIES (Elliptic Curve Integrated Encryption Scheme).
|
|
355
|
+
|
|
356
|
+
#### HTTP Webhook Mode (Recommended)
|
|
357
|
+
|
|
358
|
+
Each agent runs an embedded Flask server to receive webhook requests. This mode is simpler, doesn't require external MQTT brokers, and works well for most use cases.
|
|
359
|
+
|
|
360
|
+
##### Basic Webhook Configuration
|
|
361
|
+
|
|
347
362
|
```python
|
|
363
|
+
from zyndai_agent.agent import AgentConfig, ZyndAIAgent
|
|
364
|
+
import os
|
|
365
|
+
|
|
366
|
+
# Configure with webhook mode
|
|
367
|
+
agent_config = AgentConfig(
|
|
368
|
+
webhook_host="0.0.0.0", # Listen on all interfaces
|
|
369
|
+
webhook_port=5000, # Port for webhook server
|
|
370
|
+
webhook_url=None, # Auto-generated or specify public URL
|
|
371
|
+
api_key=os.environ["API_KEY"], # API key for webhook registration
|
|
372
|
+
auto_reconnect=True,
|
|
373
|
+
message_history_limit=100,
|
|
374
|
+
registry_url="https://registry.zynd.ai",
|
|
375
|
+
identity_credential_path="./identity_credential.json",
|
|
376
|
+
secret_seed=os.environ["AGENT_SEED"]
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
# Agent automatically starts webhook server
|
|
380
|
+
zyndai_agent = ZyndAIAgent(agent_config=agent_config)
|
|
381
|
+
print(f"Webhook server running at: {zyndai_agent.webhook_url}")
|
|
382
|
+
|
|
348
383
|
# Connect to a discovered agent
|
|
349
384
|
zyndai_agent.connect_agent(selected_agent)
|
|
350
385
|
|
|
351
|
-
# Send encrypted message
|
|
386
|
+
# Send encrypted message via HTTP POST
|
|
352
387
|
result = zyndai_agent.send_message(
|
|
353
388
|
message_content="Can you help me analyze this dataset?",
|
|
354
389
|
message_type="query"
|
|
@@ -358,6 +393,226 @@ result = zyndai_agent.send_message(
|
|
|
358
393
|
messages = zyndai_agent.read_messages()
|
|
359
394
|
```
|
|
360
395
|
|
|
396
|
+
##### Webhook with x402 Micropayments
|
|
397
|
+
|
|
398
|
+
Enable x402 payment protection on your webhook endpoints to monetize agent services:
|
|
399
|
+
|
|
400
|
+
```python
|
|
401
|
+
from zyndai_agent.agent import AgentConfig, ZyndAIAgent
|
|
402
|
+
import os
|
|
403
|
+
|
|
404
|
+
# Configure with webhook mode and x402 payments
|
|
405
|
+
agent_config = AgentConfig(
|
|
406
|
+
webhook_host="0.0.0.0",
|
|
407
|
+
webhook_port=5001,
|
|
408
|
+
webhook_url=None, # Auto-generated http://localhost:5001/webhook
|
|
409
|
+
auto_reconnect=True,
|
|
410
|
+
message_history_limit=100,
|
|
411
|
+
registry_url="https://registry.zynd.ai",
|
|
412
|
+
identity_credential_path="./identity_credential.json",
|
|
413
|
+
secret_seed=os.environ["AGENT_SEED"],
|
|
414
|
+
agent_id=os.environ["AGENT_ID"],
|
|
415
|
+
price="$0.01", # Price per request
|
|
416
|
+
pay_to_address="0xYourEthereumAddress", # Your payment address
|
|
417
|
+
api_key=os.environ["API_KEY"]
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
# Agent automatically starts webhook server with x402 payment middleware
|
|
421
|
+
zyndai_agent = ZyndAIAgent(agent_config=agent_config)
|
|
422
|
+
print(f"Webhook URL: {zyndai_agent.webhook_url}")
|
|
423
|
+
print("x402 payments enabled - clients must pay to interact")
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
**x402 Configuration:**
|
|
427
|
+
- `price`: Payment amount per request (e.g., "$0.01", "$0.10")
|
|
428
|
+
- `pay_to_address`: Your Ethereum address to receive payments
|
|
429
|
+
- If both `price` and `pay_to_address` are provided, x402 is automatically enabled
|
|
430
|
+
- If either is `None`, x402 is disabled and endpoints are free to access
|
|
431
|
+
|
|
432
|
+
##### Asynchronous vs Synchronous Webhooks
|
|
433
|
+
|
|
434
|
+
The SDK supports two webhook communication modes:
|
|
435
|
+
|
|
436
|
+
**1. Asynchronous Mode (Default)** - Fire and forget:
|
|
437
|
+
```python
|
|
438
|
+
# Messages sent to /webhook endpoint
|
|
439
|
+
# Returns immediately without waiting for agent processing
|
|
440
|
+
result = zyndai_agent.send_message("Process this data")
|
|
441
|
+
|
|
442
|
+
# Handler processes asynchronously
|
|
443
|
+
def message_handler(message: AgentMessage, topic: str):
|
|
444
|
+
# Process message
|
|
445
|
+
response = process_message(message.content)
|
|
446
|
+
|
|
447
|
+
# Optionally send response via separate webhook call
|
|
448
|
+
if zyndai_agent.target_webhook_url:
|
|
449
|
+
zyndai_agent.send_message(response)
|
|
450
|
+
|
|
451
|
+
zyndai_agent.add_message_handler(message_handler)
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
**2. Synchronous Mode** - Request/response pattern:
|
|
455
|
+
```python
|
|
456
|
+
# Messages sent to /webhook/sync endpoint
|
|
457
|
+
# Waits for agent to process and return response (30s timeout)
|
|
458
|
+
|
|
459
|
+
# Handler sets response using set_response()
|
|
460
|
+
def message_handler(message: AgentMessage, topic: str):
|
|
461
|
+
# Process message
|
|
462
|
+
response = agent_executor.invoke({"input": message.content})
|
|
463
|
+
|
|
464
|
+
# Set response for synchronous caller
|
|
465
|
+
zyndai_agent.set_response(message.message_id, response["output"])
|
|
466
|
+
|
|
467
|
+
zyndai_agent.add_message_handler(message_handler)
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
**Synchronous Response Flow:**
|
|
471
|
+
1. Client sends POST to `/webhook/sync`
|
|
472
|
+
2. Agent processes message via handler
|
|
473
|
+
3. Handler calls `set_response(message_id, response_content)`
|
|
474
|
+
4. Client receives immediate HTTP response with result
|
|
475
|
+
5. Timeout after 30 seconds if no response
|
|
476
|
+
|
|
477
|
+
**Use Cases:**
|
|
478
|
+
- **Async**: Long-running tasks, notifications, fire-and-forget operations
|
|
479
|
+
- **Sync**: Real-time queries, immediate responses needed, request-reply pattern
|
|
480
|
+
|
|
481
|
+
##### Complete Webhook Example with LangChain
|
|
482
|
+
|
|
483
|
+
```python
|
|
484
|
+
from zyndai_agent.agent import AgentConfig, ZyndAIAgent
|
|
485
|
+
from zyndai_agent.message import AgentMessage
|
|
486
|
+
from langchain_openai import ChatOpenAI
|
|
487
|
+
from langchain_classic.memory import ChatMessageHistory
|
|
488
|
+
from langchain_classic.agents import AgentExecutor, create_tool_calling_agent
|
|
489
|
+
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
490
|
+
from langchain_community.tools.tavily_search import TavilySearchResults
|
|
491
|
+
import os
|
|
492
|
+
|
|
493
|
+
# Configure agent with webhook and x402
|
|
494
|
+
agent_config = AgentConfig(
|
|
495
|
+
webhook_host="0.0.0.0",
|
|
496
|
+
webhook_port=5001,
|
|
497
|
+
webhook_url=None,
|
|
498
|
+
auto_reconnect=True,
|
|
499
|
+
message_history_limit=100,
|
|
500
|
+
registry_url="https://registry.zynd.ai",
|
|
501
|
+
identity_credential_path="./identity_credential.json",
|
|
502
|
+
secret_seed=os.environ["AGENT_SEED"],
|
|
503
|
+
agent_id=os.environ["AGENT_ID"],
|
|
504
|
+
price="$0.01", # Enable x402 payments
|
|
505
|
+
pay_to_address="0xYourAddress",
|
|
506
|
+
api_key=os.environ["API_KEY"]
|
|
507
|
+
)
|
|
508
|
+
|
|
509
|
+
# Initialize agent
|
|
510
|
+
zynd_agent = ZyndAIAgent(agent_config=agent_config)
|
|
511
|
+
|
|
512
|
+
# Create LangChain agent
|
|
513
|
+
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
|
|
514
|
+
search_tool = TavilySearchResults(max_results=3)
|
|
515
|
+
message_history = ChatMessageHistory()
|
|
516
|
+
|
|
517
|
+
prompt = ChatPromptTemplate.from_messages([
|
|
518
|
+
("system", "You are a helpful AI agent with web search capabilities."),
|
|
519
|
+
MessagesPlaceholder(variable_name="chat_history"),
|
|
520
|
+
("human", "{input}"),
|
|
521
|
+
MessagesPlaceholder(variable_name="agent_scratchpad")
|
|
522
|
+
])
|
|
523
|
+
|
|
524
|
+
agent = create_tool_calling_agent(llm, [search_tool], prompt)
|
|
525
|
+
agent_executor = AgentExecutor(agent=agent, tools=[search_tool], verbose=True)
|
|
526
|
+
zynd_agent.set_agent_executor(agent_executor)
|
|
527
|
+
|
|
528
|
+
# Message handler for both sync and async
|
|
529
|
+
def message_handler(message: AgentMessage, topic: str):
|
|
530
|
+
# Add to history
|
|
531
|
+
message_history.add_user_message(message.content)
|
|
532
|
+
|
|
533
|
+
# Process with LangChain agent
|
|
534
|
+
agent_response = zynd_agent.agent_executor.invoke({
|
|
535
|
+
"input": message.content,
|
|
536
|
+
"chat_history": message_history.messages
|
|
537
|
+
})
|
|
538
|
+
agent_output = agent_response["output"]
|
|
539
|
+
|
|
540
|
+
message_history.add_ai_message(agent_output)
|
|
541
|
+
|
|
542
|
+
# Set response for synchronous mode
|
|
543
|
+
zynd_agent.set_response(message.message_id, agent_output)
|
|
544
|
+
|
|
545
|
+
# Also send via webhook for agent-to-agent communication
|
|
546
|
+
if zynd_agent.target_webhook_url:
|
|
547
|
+
zynd_agent.send_message(agent_output)
|
|
548
|
+
|
|
549
|
+
zynd_agent.add_message_handler(message_handler)
|
|
550
|
+
|
|
551
|
+
print(f"\nWebhook Agent Running!")
|
|
552
|
+
print(f"Webhook URL: {zynd_agent.webhook_url}")
|
|
553
|
+
print(f"x402 Payments: Enabled at {agent_config.price}")
|
|
554
|
+
print("Supports both /webhook (async) and /webhook/sync (sync) endpoints")
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
**Webhook Mode Features:**
|
|
558
|
+
- ✅ No external broker required
|
|
559
|
+
- ✅ Standard HTTP/HTTPS communication
|
|
560
|
+
- ✅ Synchronous and asynchronous message patterns
|
|
561
|
+
- ✅ x402 micropayments integration
|
|
562
|
+
- ✅ Easy to deploy and debug
|
|
563
|
+
- ✅ Works behind firewalls with port forwarding
|
|
564
|
+
- ✅ Auto-retry on port conflicts (tries ports 5000-5010)
|
|
565
|
+
- ✅ Built-in health check endpoint (`/health`)
|
|
566
|
+
- ✅ Automatic payment challenge/response handling
|
|
567
|
+
|
|
568
|
+
#### MQTT Mode (Legacy)
|
|
569
|
+
|
|
570
|
+
Traditional MQTT broker-based communication. Requires a running MQTT broker.
|
|
571
|
+
|
|
572
|
+
```python
|
|
573
|
+
agent_config = AgentConfig(
|
|
574
|
+
mqtt_broker_url="mqtt://registry.zynd.ai:1883", # MQTT broker
|
|
575
|
+
default_outbox_topic=None,
|
|
576
|
+
auto_reconnect=True,
|
|
577
|
+
message_history_limit=100,
|
|
578
|
+
registry_url="https://registry.zynd.ai",
|
|
579
|
+
identity_credential_path="./identity_credential.json",
|
|
580
|
+
secret_seed=os.environ["AGENT_SEED"]
|
|
581
|
+
)
|
|
582
|
+
|
|
583
|
+
zyndai_agent = ZyndAIAgent(agent_config=agent_config)
|
|
584
|
+
|
|
585
|
+
# Connect to a discovered agent
|
|
586
|
+
zyndai_agent.connect_agent(selected_agent)
|
|
587
|
+
|
|
588
|
+
# Send encrypted message via MQTT
|
|
589
|
+
result = zyndai_agent.send_message(
|
|
590
|
+
message_content="Can you help me analyze this dataset?",
|
|
591
|
+
message_type="query"
|
|
592
|
+
)
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
**Migration from MQTT to Webhooks:**
|
|
596
|
+
To migrate existing agents, simply change your configuration from `mqtt_broker_url` to `webhook_host` and `webhook_port`. All other code remains the same!
|
|
597
|
+
|
|
598
|
+
#### Webhook Endpoints Summary
|
|
599
|
+
|
|
600
|
+
When you start a webhook-enabled agent, the following HTTP endpoints become available:
|
|
601
|
+
|
|
602
|
+
| Endpoint | Method | Description | Response Time |
|
|
603
|
+
|----------|--------|-------------|---------------|
|
|
604
|
+
| `/webhook` | POST | Asynchronous message reception | Immediate (fire-and-forget) |
|
|
605
|
+
| `/webhook/sync` | POST | Synchronous message with response | Waits up to 30s for agent response |
|
|
606
|
+
| `/health` | GET | Health check and status | Immediate |
|
|
607
|
+
|
|
608
|
+
**Endpoint Behaviors:**
|
|
609
|
+
- **`/webhook`** (Async): Accepts message, returns 200 immediately, processes in background
|
|
610
|
+
- **`/webhook/sync`** (Sync): Accepts message, waits for handler to call `set_response()`, returns response or timeout
|
|
611
|
+
- **`/health`**: Returns agent status, useful for monitoring and discovery
|
|
612
|
+
|
|
613
|
+
**x402 Protection:**
|
|
614
|
+
When `price` and `pay_to_address` are configured, all webhook endpoints require x402 payment before processing requests.
|
|
615
|
+
|
|
361
616
|
### 🔐 Identity Verification
|
|
362
617
|
|
|
363
618
|
Verify other agents' identities before trusting them:
|
|
@@ -573,13 +828,26 @@ while True:
|
|
|
573
828
|
|
|
574
829
|
| Parameter | Type | Default | Description |
|
|
575
830
|
|-----------|------|---------|-------------|
|
|
576
|
-
| `
|
|
831
|
+
| `webhook_host` | `str` | `"0.0.0.0"` | **Webhook mode**: Host address to bind webhook server |
|
|
832
|
+
| `webhook_port` | `int` | `5000` | **Webhook mode**: Port number for webhook server |
|
|
833
|
+
| `webhook_url` | `str` | `None` | **Webhook mode**: Public URL (auto-generated if None) |
|
|
834
|
+
| `api_key` | `str` | `None` | **Webhook mode**: API key for webhook registration (required for webhook mode) |
|
|
835
|
+
| `price` | `str` | `None` | **x402 Webhook**: Price per request (e.g., "$0.01"). Enables x402 if set with `pay_to_address` |
|
|
836
|
+
| `pay_to_address` | `str` | `None` | **x402 Webhook**: Ethereum address for payments. Enables x402 if set with `price` |
|
|
837
|
+
| `agent_id` | `str` | `None` | **x402 Webhook**: Agent identifier (required when using x402 payments) |
|
|
838
|
+
| `mqtt_broker_url` | `str` | `None` | **MQTT mode**: MQTT broker connection URL |
|
|
839
|
+
| `default_outbox_topic` | `str` | `None` | **MQTT mode**: Default topic for outgoing messages |
|
|
840
|
+
| `auto_reconnect` | `bool` | `True` | Auto-reconnect/restart on disconnect |
|
|
577
841
|
| `message_history_limit` | `int` | `100` | Maximum messages to keep in history |
|
|
578
842
|
| `registry_url` | `str` | `"http://localhost:3002"` | ZyndAI registry service URL |
|
|
579
|
-
| `
|
|
580
|
-
| `identity_credential_path` | `str` | Required | Path to your credential file |
|
|
843
|
+
| `identity_credential_path` | `str` | Required | Path to your DID credential file |
|
|
581
844
|
| `secret_seed` | `str` | Required | Your agent's secret seed |
|
|
582
|
-
|
|
845
|
+
|
|
846
|
+
**Notes**:
|
|
847
|
+
- Configure either `webhook_port` (recommended) OR `mqtt_broker_url`, not both
|
|
848
|
+
- When using webhook mode, `api_key` is required for registering your webhook URL with the registry
|
|
849
|
+
- x402 payments require both `price` and `pay_to_address` to be set. If either is `None`, x402 is disabled
|
|
850
|
+
- When using x402, `agent_id` should also be provided for proper identification
|
|
583
851
|
|
|
584
852
|
### Message Types
|
|
585
853
|
|
|
@@ -753,54 +1021,67 @@ except Exception as e:
|
|
|
753
1021
|
|
|
754
1022
|
## 📊 Architecture Overview
|
|
755
1023
|
```
|
|
756
|
-
|
|
757
|
-
│ ZyndAI Agent SDK
|
|
758
|
-
|
|
759
|
-
│
|
|
760
|
-
│ ┌──────────────────┐ ┌──────────────────┐
|
|
761
|
-
│ │ Identity Manager │ │ Search Manager │
|
|
762
|
-
│ │ │ │ │
|
|
763
|
-
│ │ - Verify DIDs │ │ - Capability │
|
|
764
|
-
│ │ - Load Creds │ │ Matching │
|
|
765
|
-
│ │ - Manage Keys │ │ - ML Scoring │
|
|
766
|
-
│ └──────────────────┘ └──────────────────┘
|
|
767
|
-
│
|
|
768
|
-
│
|
|
769
|
-
│ │ Communication Manager
|
|
770
|
-
│ │
|
|
771
|
-
│ │ -
|
|
772
|
-
│ │ -
|
|
773
|
-
│ │ -
|
|
774
|
-
│ │ -
|
|
775
|
-
│
|
|
776
|
-
│
|
|
777
|
-
│
|
|
778
|
-
│
|
|
779
|
-
│ │
|
|
780
|
-
│ │
|
|
781
|
-
│ │
|
|
782
|
-
│ │ -
|
|
783
|
-
│ │ -
|
|
784
|
-
│
|
|
785
|
-
│
|
|
786
|
-
│
|
|
787
|
-
│
|
|
788
|
-
│ │
|
|
789
|
-
│ │
|
|
790
|
-
│ │
|
|
791
|
-
│ │ -
|
|
792
|
-
│
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
1024
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
1025
|
+
│ ZyndAI Agent SDK │
|
|
1026
|
+
├─────────────────────────────────────────────────────────────┤
|
|
1027
|
+
│ │
|
|
1028
|
+
│ ┌──────────────────┐ ┌──────────────────┐ │
|
|
1029
|
+
│ │ Identity Manager │ │ Search Manager │ │
|
|
1030
|
+
│ │ │ │ │ │
|
|
1031
|
+
│ │ - Verify DIDs │ │ - Capability │ │
|
|
1032
|
+
│ │ - Load Creds │ │ Matching │ │
|
|
1033
|
+
│ │ - Manage Keys │ │ - ML Scoring │ │
|
|
1034
|
+
│ └──────────────────┘ └──────────────────┘ │
|
|
1035
|
+
│ │
|
|
1036
|
+
│ ┌──────────────────────────────────────────────┐ │
|
|
1037
|
+
│ │ Webhook Communication Manager │ │
|
|
1038
|
+
│ │ │ │
|
|
1039
|
+
│ │ - Embedded Flask Server │ │
|
|
1040
|
+
│ │ - Async Endpoint (/webhook) │ │
|
|
1041
|
+
│ │ - Sync Endpoint (/webhook/sync) │ │
|
|
1042
|
+
│ │ - Health Check (/health) │ │
|
|
1043
|
+
│ │ - x402 Payment Middleware (optional) │ │
|
|
1044
|
+
│ │ - Message History Tracking │ │
|
|
1045
|
+
│ └──────────────────────────────────────────────┘ │
|
|
1046
|
+
│ │
|
|
1047
|
+
│ ┌──────────────────────────────────────────┐ │
|
|
1048
|
+
│ │ Communication Manager (MQTT - Legacy) │ │
|
|
1049
|
+
│ │ │ │
|
|
1050
|
+
│ │ - End-to-End Encryption (ECIES) │ │
|
|
1051
|
+
│ │ - Message Routing │ │
|
|
1052
|
+
│ │ - Topic Management │ │
|
|
1053
|
+
│ │ - History Tracking │ │
|
|
1054
|
+
│ └──────────────────────────────────────────┘ │
|
|
1055
|
+
│ │
|
|
1056
|
+
│ ┌──────────────────────────────────────────┐ │
|
|
1057
|
+
│ │ x402 Payment Processor │ │
|
|
1058
|
+
│ │ │ │
|
|
1059
|
+
│ │ - Payment Challenge Handling │ │
|
|
1060
|
+
│ │ - Signature Generation │ │
|
|
1061
|
+
│ │ - Automatic Retry Logic │ │
|
|
1062
|
+
│ │ - Multi-Method Support (GET/POST/etc) │ │
|
|
1063
|
+
│ │ - Webhook Protection (via middleware) │ │
|
|
1064
|
+
│ └──────────────────────────────────────────┘ │
|
|
1065
|
+
│ │
|
|
1066
|
+
│ ┌──────────────────────────────────────────┐ │
|
|
1067
|
+
│ │ LangChain Integration │ │
|
|
1068
|
+
│ │ │ │
|
|
1069
|
+
│ │ - Agent Executor Support │ │
|
|
1070
|
+
│ │ - Custom Tools │ │
|
|
1071
|
+
│ │ - Memory Management │ │
|
|
1072
|
+
│ └──────────────────────────────────────────┘ │
|
|
1073
|
+
└─────────────────────────────────────────────────────────────┘
|
|
1074
|
+
▼ ▼ ▼
|
|
1075
|
+
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
|
|
1076
|
+
│ Registry │ │ MQTT Broker │ │ Other Agent │
|
|
1077
|
+
│ Service │ │ (Legacy) │ │ Webhooks │
|
|
1078
|
+
└──────────────┘ └──────────────┘ └──────────────┘
|
|
1079
|
+
▼
|
|
1080
|
+
┌──────────────┐
|
|
1081
|
+
│ x402 Enabled │
|
|
1082
|
+
│ Services │
|
|
1083
|
+
│ (HTTP APIs) │
|
|
1084
|
+
└──────────────┘
|
|
804
1085
|
```
|
|
805
1086
|
|
|
806
1087
|
## 🤝 Contributing
|
|
@@ -815,7 +1096,7 @@ We welcome contributions! Here's how to get started:
|
|
|
815
1096
|
|
|
816
1097
|
### Development Setup
|
|
817
1098
|
```bash
|
|
818
|
-
git clone https://github.com/
|
|
1099
|
+
git clone https://github.com/Zynd-AI-Network/zyndai-agent.git
|
|
819
1100
|
cd zyndai-agent
|
|
820
1101
|
python -m venv venv
|
|
821
1102
|
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
@@ -850,11 +1131,121 @@ Create agents for real-time market data (x402), technical analysis by agents, se
|
|
|
850
1131
|
### 6. Content Generation with Fact-Checking
|
|
851
1132
|
Orchestrate agents for research, writing, accessing paid fact-checking APIs via x402, and publishing verified content.
|
|
852
1133
|
|
|
1134
|
+
## 🔧 Troubleshooting
|
|
1135
|
+
|
|
1136
|
+
### Webhook Mode Issues
|
|
1137
|
+
|
|
1138
|
+
**Port Already in Use**
|
|
1139
|
+
```
|
|
1140
|
+
The SDK automatically tries ports 5000-5010 if the configured port is busy.
|
|
1141
|
+
Check the console output for the actual port being used.
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
**Agent Behind NAT/Firewall**
|
|
1145
|
+
```python
|
|
1146
|
+
# Specify your public webhook URL manually
|
|
1147
|
+
agent_config = AgentConfig(
|
|
1148
|
+
webhook_host="0.0.0.0",
|
|
1149
|
+
webhook_port=5000,
|
|
1150
|
+
webhook_url="https://my-public-domain.com/webhook", # Your public URL
|
|
1151
|
+
...
|
|
1152
|
+
)
|
|
1153
|
+
```
|
|
1154
|
+
|
|
1155
|
+
**Running Multiple Agents Locally**
|
|
1156
|
+
```python
|
|
1157
|
+
# Agent 1: Port 5000
|
|
1158
|
+
agent1_config = AgentConfig(webhook_port=5000, ...)
|
|
1159
|
+
|
|
1160
|
+
# Agent 2: Port 5001
|
|
1161
|
+
agent2_config = AgentConfig(webhook_port=5001, ...)
|
|
1162
|
+
|
|
1163
|
+
# Agent 3: Port 5002
|
|
1164
|
+
agent3_config = AgentConfig(webhook_port=5002, ...)
|
|
1165
|
+
```
|
|
1166
|
+
|
|
1167
|
+
**Target Agent Offline**
|
|
1168
|
+
```
|
|
1169
|
+
When sending messages, you'll receive clear error messages:
|
|
1170
|
+
- "Error: Could not connect to target agent. Agent may be offline."
|
|
1171
|
+
- "Error: Request timed out. Target agent may be offline."
|
|
1172
|
+
|
|
1173
|
+
The SDK does not automatically retry failed webhooks.
|
|
1174
|
+
```
|
|
1175
|
+
|
|
1176
|
+
**Health Check**
|
|
1177
|
+
```bash
|
|
1178
|
+
# Check if webhook server is running
|
|
1179
|
+
curl http://localhost:5000/health
|
|
1180
|
+
|
|
1181
|
+
# Response:
|
|
1182
|
+
# {"status": "ok", "agent_id": "did:polygonid:...", "timestamp": 1234567890}
|
|
1183
|
+
```
|
|
1184
|
+
|
|
1185
|
+
**Testing Webhook Endpoints**
|
|
1186
|
+
```bash
|
|
1187
|
+
# Test async webhook (returns immediately)
|
|
1188
|
+
curl -X POST http://localhost:5000/webhook \
|
|
1189
|
+
-H "Content-Type: application/json" \
|
|
1190
|
+
-d '{"content": "Hello", "sender_id": "test", "message_type": "query"}'
|
|
1191
|
+
|
|
1192
|
+
# Response: {"status": "received", "message_id": "...", "timestamp": 1234567890}
|
|
1193
|
+
|
|
1194
|
+
# Test sync webhook (waits for agent response)
|
|
1195
|
+
curl -X POST http://localhost:5000/webhook/sync \
|
|
1196
|
+
-H "Content-Type: application/json" \
|
|
1197
|
+
-d '{"content": "Hello", "sender_id": "test", "message_type": "query"}'
|
|
1198
|
+
|
|
1199
|
+
# Response: {"status": "success", "message_id": "...", "response": "...", "timestamp": 1234567890}
|
|
1200
|
+
# Or timeout: {"status": "timeout", "message_id": "...", "error": "...", "timestamp": 1234567890}
|
|
1201
|
+
```
|
|
1202
|
+
|
|
1203
|
+
**x402 Payment Testing**
|
|
1204
|
+
```bash
|
|
1205
|
+
# First request triggers 402 Payment Required
|
|
1206
|
+
curl -X POST http://localhost:5000/webhook \
|
|
1207
|
+
-H "Content-Type: application/json" \
|
|
1208
|
+
-d '{"content": "Hello"}'
|
|
1209
|
+
|
|
1210
|
+
# Response: 402 with payment challenge
|
|
1211
|
+
# SDK automatically handles payment and retries
|
|
1212
|
+
```
|
|
1213
|
+
|
|
1214
|
+
### MQTT Mode Issues
|
|
1215
|
+
|
|
1216
|
+
**Connection Refused**
|
|
1217
|
+
```
|
|
1218
|
+
Ensure your MQTT broker URL is correct and the broker is running.
|
|
1219
|
+
Default: mqtt://registry.zynd.ai:1883
|
|
1220
|
+
```
|
|
1221
|
+
|
|
1222
|
+
**Messages Not Being Received**
|
|
1223
|
+
```
|
|
1224
|
+
Check that agents are subscribed to the correct topics.
|
|
1225
|
+
Verify encryption credentials match between agents.
|
|
1226
|
+
```
|
|
1227
|
+
|
|
1228
|
+
### General Issues
|
|
1229
|
+
|
|
1230
|
+
**Decryption Failures**
|
|
1231
|
+
```
|
|
1232
|
+
Ensure both agents have the correct DID credentials.
|
|
1233
|
+
Verify secret_seed matches the identity_credential_path.
|
|
1234
|
+
Check that credentials haven't been regenerated.
|
|
1235
|
+
```
|
|
1236
|
+
|
|
1237
|
+
**Registry Connection Errors**
|
|
1238
|
+
```
|
|
1239
|
+
Verify registry_url is correct.
|
|
1240
|
+
Check network connectivity to registry.
|
|
1241
|
+
Ensure webhook URL or MQTT broker info was successfully registered.
|
|
1242
|
+
```
|
|
1243
|
+
|
|
853
1244
|
## 🆘 Support & Community
|
|
854
1245
|
|
|
855
|
-
- **GitHub Issues**: [Report bugs or request features](https://github.com/
|
|
1246
|
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/Zynd-AI-Network/zyndai-agent/issues)
|
|
856
1247
|
- **Documentation**: [Full API Documentation](https://docs.zynd.ai)
|
|
857
|
-
- **Email**:
|
|
1248
|
+
- **Email**: zyndainetwork@gmail.com
|
|
858
1249
|
- **Twitter**: [@ZyndAI](https://x.com/ZyndAI)
|
|
859
1250
|
|
|
860
1251
|
## 📄 License
|
|
@@ -875,7 +1266,10 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
875
1266
|
- [x] Core agent communication and discovery
|
|
876
1267
|
- [x] End-to-end encryption
|
|
877
1268
|
- [x] LangChain integration
|
|
878
|
-
- [x] x402 micropayment support
|
|
1269
|
+
- [x] x402 micropayment support for HTTP APIs
|
|
1270
|
+
- [x] HTTP Webhook communication mode (async/sync)
|
|
1271
|
+
- [x] x402 payment protection for webhook endpoints
|
|
1272
|
+
- [ ] WebSocket support for real-time bidirectional communication
|
|
879
1273
|
- [ ] Support for additional LLM providers (Anthropic, Cohere, etc.)
|
|
880
1274
|
- [ ] Web dashboard for agent monitoring and payment tracking
|
|
881
1275
|
- [ ] Advanced orchestration patterns (workflows, state machines)
|
|
@@ -884,6 +1278,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
884
1278
|
- [ ] Enhanced security features (rate limiting, access control)
|
|
885
1279
|
- [ ] Performance optimizations for high-throughput scenarios
|
|
886
1280
|
- [ ] x402 payment analytics and budgeting tools
|
|
1281
|
+
- [ ] Webhook authentication and advanced rate limiting
|
|
887
1282
|
|
|
888
1283
|
---
|
|
889
1284
|
|