Add AI agent communication example using GossipSub#45
Open
Harshit-Mishra2212 wants to merge 1 commit into
Open
Add AI agent communication example using GossipSub#45Harshit-Mishra2212 wants to merge 1 commit into
Harshit-Mishra2212 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Looking through the examples folder, there is no example showing how AI agents can use py-libp2p to communicate with each other. All existing examples cover the networking primitives (chat, echo, ping) but none ofthem connect this to an actual AI agent use case. Given issues like #20 this felt like a useful gap to fill.
The example implements a dispatcher-worker pattern over GossipSub. The dispatcher broadcasts tasks on the
agent/tasks/v1topic. Worker agents subscribe to that topic, process the task, and publish their response back onagent/responses/v1. Using two separate topics keeps the message flow clean - the dispatcher only sees responses, workers only see tasks. Multiple workers can connect to the same dispatcher simultaneously and each one responds independently. No central server is involved at any point.The task processing is intentionally kept simple to keep the focus on the p2p communication layer. In a real deployment this is where we would plug in an LLM or run local inference. The architecture stays the same regardless of what runs inside process_task.
Changes
examples/ai_agent/agent.pyHow to verify
pip install libp2p
Terminal 1
python examples/ai_agent/agent.py
Terminal 2 (paste address printed by Terminal 1)
python examples/ai_agent/agent.py -d (address) --worker
Type a task in Terminal 1. The worker in Terminal 2 receives it, processes it, and the response appears back in Terminal 1.