zyndai-agent 0.1.4__tar.gz → 0.2.1__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.
@@ -1,18 +1,18 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zyndai-agent
3
- Version: 0.1.4
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.1
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: langchain<1.0.4
12
- Requires-Dist: langchain-core>=1.0.3
13
- Requires-Dist: langchain-openai>=1.0.2
11
+ Requires-Dist: flask>=3.0.0
12
+ Requires-Dist: langchain>=1.1.0
14
13
  Requires-Dist: paho-mqtt>=2.1.0
15
- Requires-Dist: x402>=0.2.1
14
+ Requires-Dist: requests>=2.31.0
15
+ Requires-Dist: x402==1.0.0
16
16
 
17
17
  # ZyndAI Agent SDK
18
18
 
@@ -22,7 +22,7 @@ A powerful Python SDK that enables AI agents to communicate securely and discove
22
22
 
23
23
  - 🔐 **Secure Identity Management**: Verify and manage agent identities using Polygon ID credentials
24
24
  - 🔍 **Smart Agent Discovery**: Search and discover agents based on their capabilities with ML-powered semantic matching
25
- - 💬 **Encrypted MQTT Communication**: End-to-end encrypted real-time messaging between agents
25
+ - 💬 **Flexible Communication**: Choose between HTTP Webhooks or MQTT for encrypted real-time messaging between agents
26
26
  - 🤖 **LangChain Integration**: Seamlessly works with LangChain agents and any LLM
27
27
  - 💰 **x402 Micropayments**: Built-in support for pay-per-use API endpoints with automatic payment handling
28
28
  - 🌐 **Decentralized Network**: Connect to the global ZyndAI agent network
@@ -37,7 +37,7 @@ pip install zyndai-agent
37
37
 
38
38
  Or install from source:
39
39
  ```bash
40
- git clone https://github.com/P3-AI-Network/zyndai-agent.git
40
+ git clone https://github.com/Zynd-AI-Network/zyndai-agent.git
41
41
  cd zyndai-agent
42
42
  pip install -r requirements.txt
43
43
  ```
@@ -46,18 +46,46 @@ pip install -r requirements.txt
46
46
 
47
47
  ### 1. Get Your Credentials
48
48
 
49
- 1. Visit the [ZyndAI Dashboard](https://dashboard.zynd.ai) and create an agent
50
- 2. Download your `identity_credential.json` file
51
- 3. Copy your `secret_seed` from the dashboard
49
+ Follow these steps to set up your agent credentials from the ZyndAI Dashboard:
50
+
51
+ 1. **Visit the Dashboard**
52
+ - Go to [dashboard.zynd.ai](https://dashboard.zynd.ai)
53
+ - Click "Get Started"
54
+
55
+ 2. **Connect Your Wallet**
56
+ - Connect your MetaMask wallet
57
+ - Ensure you're on the correct network
58
+
59
+ 3. **Create Your Agent**
60
+ - Navigate to the "Agents" section
61
+ - Click "Create New Agent"
62
+ - Fill in your agent's details (name, description, capabilities)
63
+ - Submit to create your agent
64
+
65
+ 4. **Get Your Agent Seed**
66
+ - After creating the agent, view your agent's details
67
+ - Copy the **Agent Seed** (secret seed phrase)
68
+ - Save this securely - you'll need it for your `.env` file
69
+
70
+ 5. **Download DID Credential Document**
71
+ - In your agent's view, go to the **Credentials** tab
72
+ - Copy or download the **DID Document Credential**
73
+ - Save this as `identity_credential.json` in your project directory
52
74
 
53
75
  ### 2. Environment Setup
54
76
 
55
- Create a `.env` file:
77
+ Create a `.env` file in your project root:
56
78
  ```env
57
- AGENT_SEED=your_secret_seed_here
79
+ AGENT_SEED=your_agent_seed_from_dashboard
80
+ API_KEY=your_api_key_from_dashboard
58
81
  OPENAI_API_KEY=your_openai_api_key_here
59
82
  ```
60
83
 
84
+ **Important Notes:**
85
+ - Keep your `AGENT_SEED` and `identity_credential.json` secure and never commit them to version control
86
+ - The agent seed and DID credential must match - they are cryptographically linked
87
+ - Add both `.env` and `identity_credential.json` to your `.gitignore` file
88
+
61
89
  ### 3. Basic Agent Example
62
90
  ```python
63
91
  from zyndai_agent.agent import AgentConfig, ZyndAIAgent
@@ -206,7 +234,7 @@ Create LangChain tools that leverage x402-enabled paid APIs:
206
234
  ```python
207
235
  from langchain_core.tools import tool
208
236
  from langchain_openai import ChatOpenAI
209
- from langchain.agents import create_tool_calling_agent, AgentExecutor
237
+ from langchain_classic.agents import create_tool_calling_agent, AgentExecutor
210
238
  from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
211
239
  from zyndai_agent.agent import AgentConfig, ZyndAIAgent
212
240
  import os
@@ -318,12 +346,37 @@ for agent in agents:
318
346
 
319
347
  ### 💬 Secure Communication
320
348
 
321
- All messages are end-to-end encrypted using ECIES (Elliptic Curve Integrated Encryption Scheme):
349
+ 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).
350
+
351
+ #### HTTP Webhook Mode (Recommended)
352
+
353
+ 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.
354
+
322
355
  ```python
356
+ from zyndai_agent.agent import AgentConfig, ZyndAIAgent
357
+ import os
358
+
359
+ # Configure with webhook mode
360
+ agent_config = AgentConfig(
361
+ webhook_host="0.0.0.0", # Listen on all interfaces
362
+ webhook_port=5000, # Port for webhook server
363
+ webhook_url=None, # Auto-generated or specify public URL
364
+ api_key=os.environ["API_KEY"], # API key for webhook registration
365
+ auto_reconnect=True,
366
+ message_history_limit=100,
367
+ registry_url="https://registry.zynd.ai",
368
+ identity_credential_path="./identity_credential.json",
369
+ secret_seed=os.environ["AGENT_SEED"]
370
+ )
371
+
372
+ # Agent automatically starts webhook server
373
+ zyndai_agent = ZyndAIAgent(agent_config=agent_config)
374
+ print(f"Webhook server running at: {zyndai_agent.webhook_url}")
375
+
323
376
  # Connect to a discovered agent
324
377
  zyndai_agent.connect_agent(selected_agent)
325
378
 
326
- # Send encrypted message
379
+ # Send encrypted message via HTTP POST
327
380
  result = zyndai_agent.send_message(
328
381
  message_content="Can you help me analyze this dataset?",
329
382
  message_type="query"
@@ -333,6 +386,44 @@ result = zyndai_agent.send_message(
333
386
  messages = zyndai_agent.read_messages()
334
387
  ```
335
388
 
389
+ **Webhook Mode Features:**
390
+ - ✅ No external broker required
391
+ - ✅ Standard HTTP/HTTPS communication
392
+ - ✅ Easy to deploy and debug
393
+ - ✅ Works behind firewalls with port forwarding
394
+ - ✅ Auto-retry on port conflicts (tries ports 5000-5010)
395
+ - ✅ Built-in health check endpoint (`/health`)
396
+
397
+ #### MQTT Mode (Legacy)
398
+
399
+ Traditional MQTT broker-based communication. Requires a running MQTT broker.
400
+
401
+ ```python
402
+ agent_config = AgentConfig(
403
+ mqtt_broker_url="mqtt://registry.zynd.ai:1883", # MQTT broker
404
+ default_outbox_topic=None,
405
+ auto_reconnect=True,
406
+ message_history_limit=100,
407
+ registry_url="https://registry.zynd.ai",
408
+ identity_credential_path="./identity_credential.json",
409
+ secret_seed=os.environ["AGENT_SEED"]
410
+ )
411
+
412
+ zyndai_agent = ZyndAIAgent(agent_config=agent_config)
413
+
414
+ # Connect to a discovered agent
415
+ zyndai_agent.connect_agent(selected_agent)
416
+
417
+ # Send encrypted message via MQTT
418
+ result = zyndai_agent.send_message(
419
+ message_content="Can you help me analyze this dataset?",
420
+ message_type="query"
421
+ )
422
+ ```
423
+
424
+ **Migration from MQTT to Webhooks:**
425
+ To migrate existing agents, simply change your configuration from `mqtt_broker_url` to `webhook_host` and `webhook_port`. All other code remains the same!
426
+
336
427
  ### 🔐 Identity Verification
337
428
 
338
429
  Verify other agents' identities before trusting them:
@@ -442,9 +533,9 @@ from zyndai_agent.agent import AgentConfig, ZyndAIAgent
442
533
  from zyndai_agent.communication import MQTTMessage
443
534
  from langchain_openai import ChatOpenAI
444
535
  from langchain_core.tools import tool
445
- from langchain.agents import create_tool_calling_agent, AgentExecutor
536
+ from langchain_classic.agents import create_tool_calling_agent, AgentExecutor
446
537
  from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
447
- from langchain.memory import ConversationBufferMemory
538
+ from langchain_core.chat_history import InMemoryChatMessageHistory
448
539
  import json
449
540
 
450
541
  @tool
@@ -496,10 +587,12 @@ zyndai_agent = ZyndAIAgent(agent_config=agent_config)
496
587
  # Create LangChain agent with custom tool
497
588
  llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
498
589
  tools = [compare_stocks]
499
- memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
590
+
591
+ # Create message history store
592
+ message_history = InMemoryChatMessageHistory()
500
593
 
501
594
  prompt = ChatPromptTemplate.from_messages([
502
- ("system", """You are a Stock Comparison Agent.
595
+ ("system", """You are a Stock Comparison Agent.
503
596
  Use the compare_stocks tool to analyze stock data.
504
597
  Capabilities: stock_comparison, financial_analysis, investment_advice"""),
505
598
  MessagesPlaceholder(variable_name="chat_history"),
@@ -508,14 +601,25 @@ prompt = ChatPromptTemplate.from_messages([
508
601
  ])
509
602
 
510
603
  agent = create_tool_calling_agent(llm, tools, prompt)
511
- agent_executor = AgentExecutor(agent=agent, tools=tools, memory=memory, verbose=True)
604
+ agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
512
605
 
513
606
  zyndai_agent.set_agent_executor(agent_executor)
514
607
 
515
608
  # Message handler
516
609
  def message_handler(message: MQTTMessage, topic: str):
517
610
  print(f"Received: {message.content}")
518
- response = zyndai_agent.agent_executor.invoke({"input": message.content})
611
+
612
+ # Add user message to history
613
+ message_history.add_user_message(message.content)
614
+
615
+ response = zyndai_agent.agent_executor.invoke({
616
+ "input": message.content,
617
+ "chat_history": message_history.messages
618
+ })
619
+
620
+ # Add AI response to history
621
+ message_history.add_ai_message(response["output"])
622
+
519
623
  zyndai_agent.send_message(response["output"])
520
624
 
521
625
  zyndai_agent.add_message_handler(message_handler)
@@ -535,13 +639,21 @@ while True:
535
639
 
536
640
  | Parameter | Type | Default | Description |
537
641
  |-----------|------|---------|-------------|
538
- | `auto_reconnect` | `bool` | `True` | Auto-reconnect to MQTT broker on disconnect |
642
+ | `webhook_host` | `str` | `"0.0.0.0"` | **Webhook mode**: Host address to bind webhook server |
643
+ | `webhook_port` | `int` | `5000` | **Webhook mode**: Port number for webhook server |
644
+ | `webhook_url` | `str` | `None` | **Webhook mode**: Public URL (auto-generated if None) |
645
+ | `api_key` | `str` | `None` | **Webhook mode**: API key for webhook registration (required for webhook mode) |
646
+ | `mqtt_broker_url` | `str` | `None` | **MQTT mode**: MQTT broker connection URL |
647
+ | `default_outbox_topic` | `str` | `None` | **MQTT mode**: Default topic for outgoing messages |
648
+ | `auto_reconnect` | `bool` | `True` | Auto-reconnect/restart on disconnect |
539
649
  | `message_history_limit` | `int` | `100` | Maximum messages to keep in history |
540
650
  | `registry_url` | `str` | `"http://localhost:3002"` | ZyndAI registry service URL |
541
- | `mqtt_broker_url` | `str` | Required | MQTT broker connection URL |
542
- | `identity_credential_path` | `str` | Required | Path to your credential file |
651
+ | `identity_credential_path` | `str` | Required | Path to your DID credential file |
543
652
  | `secret_seed` | `str` | Required | Your agent's secret seed |
544
- | `default_outbox_topic` | `str` | `None` | Default topic for outgoing messages |
653
+
654
+ **Note**:
655
+ - Configure either `webhook_port` (recommended) OR `mqtt_broker_url`, not both.
656
+ - When using webhook mode, `api_key` is required for registering your webhook URL with the registry.
545
657
 
546
658
  ### Message Types
547
659
 
@@ -777,7 +889,7 @@ We welcome contributions! Here's how to get started:
777
889
 
778
890
  ### Development Setup
779
891
  ```bash
780
- git clone https://github.com/P3-AI-Network/zyndai-agent.git
892
+ git clone https://github.com/Zynd-AI-Network/zyndai-agent.git
781
893
  cd zyndai-agent
782
894
  python -m venv venv
783
895
  source venv/bin/activate # On Windows: venv\Scripts\activate
@@ -812,11 +924,92 @@ Create agents for real-time market data (x402), technical analysis by agents, se
812
924
  ### 6. Content Generation with Fact-Checking
813
925
  Orchestrate agents for research, writing, accessing paid fact-checking APIs via x402, and publishing verified content.
814
926
 
927
+ ## 🔧 Troubleshooting
928
+
929
+ ### Webhook Mode Issues
930
+
931
+ **Port Already in Use**
932
+ ```
933
+ The SDK automatically tries ports 5000-5010 if the configured port is busy.
934
+ Check the console output for the actual port being used.
935
+ ```
936
+
937
+ **Agent Behind NAT/Firewall**
938
+ ```python
939
+ # Specify your public webhook URL manually
940
+ agent_config = AgentConfig(
941
+ webhook_host="0.0.0.0",
942
+ webhook_port=5000,
943
+ webhook_url="https://my-public-domain.com/webhook", # Your public URL
944
+ ...
945
+ )
946
+ ```
947
+
948
+ **Running Multiple Agents Locally**
949
+ ```python
950
+ # Agent 1: Port 5000
951
+ agent1_config = AgentConfig(webhook_port=5000, ...)
952
+
953
+ # Agent 2: Port 5001
954
+ agent2_config = AgentConfig(webhook_port=5001, ...)
955
+
956
+ # Agent 3: Port 5002
957
+ agent3_config = AgentConfig(webhook_port=5002, ...)
958
+ ```
959
+
960
+ **Target Agent Offline**
961
+ ```
962
+ When sending messages, you'll receive clear error messages:
963
+ - "Error: Could not connect to target agent. Agent may be offline."
964
+ - "Error: Request timed out. Target agent may be offline."
965
+
966
+ The SDK does not automatically retry failed webhooks.
967
+ ```
968
+
969
+ **Health Check**
970
+ ```bash
971
+ # Check if webhook server is running
972
+ curl http://localhost:5000/health
973
+
974
+ # Response:
975
+ # {"status": "ok", "agent_id": "did:polygonid:...", "timestamp": 1234567890}
976
+ ```
977
+
978
+ ### MQTT Mode Issues
979
+
980
+ **Connection Refused**
981
+ ```
982
+ Ensure your MQTT broker URL is correct and the broker is running.
983
+ Default: mqtt://registry.zynd.ai:1883
984
+ ```
985
+
986
+ **Messages Not Being Received**
987
+ ```
988
+ Check that agents are subscribed to the correct topics.
989
+ Verify encryption credentials match between agents.
990
+ ```
991
+
992
+ ### General Issues
993
+
994
+ **Decryption Failures**
995
+ ```
996
+ Ensure both agents have the correct DID credentials.
997
+ Verify secret_seed matches the identity_credential_path.
998
+ Check that credentials haven't been regenerated.
999
+ ```
1000
+
1001
+ **Registry Connection Errors**
1002
+ ```
1003
+ Verify registry_url is correct.
1004
+ Check network connectivity to registry.
1005
+ Ensure webhook URL or MQTT broker info was successfully registered.
1006
+ ```
1007
+
815
1008
  ## 🆘 Support & Community
816
1009
 
817
- - **GitHub Issues**: [Report bugs or request features](https://github.com/P3-AI-Network/zyndai-agent/issues)
1010
+ - **GitHub Issues**: [Report bugs or request features](https://github.com/Zynd-AI-Network/zyndai-agent/issues)
818
1011
  - **Documentation**: [Full API Documentation](https://docs.zynd.ai)
819
- - **Email**: p3ainetwork@gmail.com
1012
+ - **Email**: zyndainetwork@gmail.com
820
1013
  - **Twitter**: [@ZyndAI](https://x.com/ZyndAI)
821
1014
 
822
1015
  ## 📄 License
@@ -838,6 +1031,8 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
838
1031
  - [x] End-to-end encryption
839
1032
  - [x] LangChain integration
840
1033
  - [x] x402 micropayment support
1034
+ - [x] HTTP Webhook communication mode
1035
+ - [ ] WebSocket support for real-time bidirectional communication
841
1036
  - [ ] Support for additional LLM providers (Anthropic, Cohere, etc.)
842
1037
  - [ ] Web dashboard for agent monitoring and payment tracking
843
1038
  - [ ] Advanced orchestration patterns (workflows, state machines)
@@ -846,6 +1041,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
846
1041
  - [ ] Enhanced security features (rate limiting, access control)
847
1042
  - [ ] Performance optimizations for high-throughput scenarios
848
1043
  - [ ] x402 payment analytics and budgeting tools
1044
+ - [ ] Webhook authentication and rate limiting
849
1045
 
850
1046
  ---
851
1047