feat: Enhanced meta-discussion system with conversation tracking
- Add Conversation struct to track task discussion history - Implement handleMetaDiscussion for dynamic peer collaboration - Enhanced GitHub integration with active discussion management - Add SetAntennaeMessageHandler for pluggable message handling - Simplify pubsub message types to generic MetaDiscussion - Enable real-time collaborative reasoning between AI agents - Integrate conversation context into Ollama response generation - Support distributed decision making across P2P network 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
123
pubsub/pubsub.go
123
pubsub/pubsub.go
@@ -22,13 +22,16 @@ type PubSub struct {
|
||||
bzzzTopic *pubsub.Topic
|
||||
antennaeTopic *pubsub.Topic
|
||||
|
||||
// Message handlers
|
||||
// Message subscriptions
|
||||
bzzzSub *pubsub.Subscription
|
||||
antennaeSub *pubsub.Subscription
|
||||
|
||||
// Configuration
|
||||
bzzzTopicName string
|
||||
antennaeTopicName string
|
||||
|
||||
// External message handler for Antennae messages
|
||||
AntennaeMessageHandler func(msg Message, from peer.ID)
|
||||
}
|
||||
|
||||
// MessageType represents different types of messages
|
||||
@@ -43,10 +46,7 @@ const (
|
||||
CapabilityBcast MessageType = "capability_broadcast"
|
||||
|
||||
// Antennae meta-discussion messages
|
||||
PlanProposal MessageType = "plan_proposal"
|
||||
Objection MessageType = "objection"
|
||||
Collaboration MessageType = "collaboration"
|
||||
Escalation MessageType = "escalation"
|
||||
MetaDiscussion MessageType = "meta_discussion" // Generic type for all discussion
|
||||
)
|
||||
|
||||
// Message represents a Bzzz/Antennae message
|
||||
@@ -104,6 +104,12 @@ func NewPubSub(ctx context.Context, h host.Host, bzzzTopic, antennaeTopic string
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// SetAntennaeMessageHandler sets the handler for incoming Antennae messages.
|
||||
// This allows the business logic (e.g., in the github module) to process messages.
|
||||
func (p *PubSub) SetAntennaeMessageHandler(handler func(msg Message, from peer.ID)) {
|
||||
p.AntennaeMessageHandler = handler
|
||||
}
|
||||
|
||||
// joinTopics joins the Bzzz coordination and Antennae meta-discussion topics
|
||||
func (p *PubSub) joinTopics() error {
|
||||
// Join Bzzz coordination topic
|
||||
@@ -155,18 +161,12 @@ func (p *PubSub) PublishBzzzMessage(msgType MessageType, data map[string]interfa
|
||||
}
|
||||
|
||||
// PublishAntennaeMessage publishes a message to the Antennae meta-discussion topic
|
||||
func (p *PubSub) PublishAntennaeMessage(msgType MessageType, data map[string]interface{}, hopCount int) error {
|
||||
// Antennae messages have hop limiting for safety
|
||||
if hopCount > 3 {
|
||||
return fmt.Errorf("hop count exceeded maximum of 3")
|
||||
}
|
||||
|
||||
func (p *PubSub) PublishAntennaeMessage(msgType MessageType, data map[string]interface{}) error {
|
||||
msg := Message{
|
||||
Type: msgType,
|
||||
From: p.host.ID().String(),
|
||||
Timestamp: time.Now(),
|
||||
Data: data,
|
||||
HopCount: hopCount,
|
||||
}
|
||||
|
||||
msgBytes, err := json.Marshal(msg)
|
||||
@@ -227,100 +227,25 @@ func (p *PubSub) handleAntennaeMessages() {
|
||||
continue
|
||||
}
|
||||
|
||||
p.processAntennaeMessage(antennaeMsg, msg.ReceivedFrom)
|
||||
// If an external handler is registered, use it.
|
||||
if p.AntennaeMessageHandler != nil {
|
||||
p.AntennaeMessageHandler(antennaeMsg, msg.ReceivedFrom)
|
||||
} else {
|
||||
// Default processing if no handler is set
|
||||
p.processAntennaeMessage(antennaeMsg, msg.ReceivedFrom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// processBzzzMessage handles different types of Bzzz coordination messages
|
||||
func (p *PubSub) processBzzzMessage(msg Message, from peer.ID) {
|
||||
fmt.Printf("🐝 Bzzz [%s] from %s: %s\n", msg.Type, from.ShortString(), msg.Data)
|
||||
|
||||
switch msg.Type {
|
||||
case TaskAnnouncement:
|
||||
p.handleTaskAnnouncement(msg, from)
|
||||
case TaskClaim:
|
||||
p.handleTaskClaim(msg, from)
|
||||
case TaskProgress:
|
||||
p.handleTaskProgress(msg, from)
|
||||
case TaskComplete:
|
||||
p.handleTaskComplete(msg, from)
|
||||
case CapabilityBcast:
|
||||
p.handleCapabilityBroadcast(msg, from)
|
||||
default:
|
||||
fmt.Printf("⚠️ Unknown Bzzz message type: %s\n", msg.Type)
|
||||
}
|
||||
fmt.Printf("🐝 Bzzz [%s] from %s: %v\n", msg.Type, from.ShortString(), msg.Data)
|
||||
}
|
||||
|
||||
// processAntennaeMessage handles different types of Antennae meta-discussion messages
|
||||
// processAntennaeMessage provides default handling for Antennae messages if no external handler is set
|
||||
func (p *PubSub) processAntennaeMessage(msg Message, from peer.ID) {
|
||||
fmt.Printf("🎯 Antennae [%s] from %s (hop %d): %s\n",
|
||||
msg.Type, from.ShortString(), msg.HopCount, msg.Data)
|
||||
|
||||
// Check hop count for safety
|
||||
if msg.HopCount > 3 {
|
||||
fmt.Printf("⚠️ Dropping Antennae message with excessive hop count: %d\n", msg.HopCount)
|
||||
return
|
||||
}
|
||||
|
||||
switch msg.Type {
|
||||
case PlanProposal:
|
||||
p.handlePlanProposal(msg, from)
|
||||
case Objection:
|
||||
p.handleObjection(msg, from)
|
||||
case Collaboration:
|
||||
p.handleCollaboration(msg, from)
|
||||
case Escalation:
|
||||
p.handleEscalation(msg, from)
|
||||
default:
|
||||
fmt.Printf("⚠️ Unknown Antennae message type: %s\n", msg.Type)
|
||||
}
|
||||
}
|
||||
|
||||
// Bzzz message handlers
|
||||
func (p *PubSub) handleTaskAnnouncement(msg Message, from peer.ID) {
|
||||
// Handle task announcement logic
|
||||
fmt.Printf("📋 New task announced: %v\n", msg.Data)
|
||||
}
|
||||
|
||||
func (p *PubSub) handleTaskClaim(msg Message, from peer.ID) {
|
||||
// Handle task claim logic
|
||||
fmt.Printf("✋ Task claimed by %s: %v\n", from.ShortString(), msg.Data)
|
||||
}
|
||||
|
||||
func (p *PubSub) handleTaskProgress(msg Message, from peer.ID) {
|
||||
// Handle task progress updates
|
||||
fmt.Printf("⏳ Task progress from %s: %v\n", from.ShortString(), msg.Data)
|
||||
}
|
||||
|
||||
func (p *PubSub) handleTaskComplete(msg Message, from peer.ID) {
|
||||
// Handle task completion
|
||||
fmt.Printf("✅ Task completed by %s: %v\n", from.ShortString(), msg.Data)
|
||||
}
|
||||
|
||||
func (p *PubSub) handleCapabilityBroadcast(msg Message, from peer.ID) {
|
||||
// Handle capability announcements
|
||||
fmt.Printf("🔧 Capabilities from %s: %v\n", from.ShortString(), msg.Data)
|
||||
}
|
||||
|
||||
// Antennae message handlers
|
||||
func (p *PubSub) handlePlanProposal(msg Message, from peer.ID) {
|
||||
// Handle plan proposals for collaborative reasoning
|
||||
fmt.Printf("💡 Plan proposal from %s: %v\n", from.ShortString(), msg.Data)
|
||||
}
|
||||
|
||||
func (p *PubSub) handleObjection(msg Message, from peer.ID) {
|
||||
// Handle objections during collaborative discussions
|
||||
fmt.Printf("⚠️ Objection from %s: %v\n", from.ShortString(), msg.Data)
|
||||
}
|
||||
|
||||
func (p *PubSub) handleCollaboration(msg Message, from peer.ID) {
|
||||
// Handle collaborative reasoning messages
|
||||
fmt.Printf("🤝 Collaboration from %s: %v\n", from.ShortString(), msg.Data)
|
||||
}
|
||||
|
||||
func (p *PubSub) handleEscalation(msg Message, from peer.ID) {
|
||||
// Handle escalations to human intervention
|
||||
fmt.Printf("🚨 Escalation from %s: %v\n", from.ShortString(), msg.Data)
|
||||
fmt.Printf("🎯 Default Antennae Handler [%s] from %s: %v\n",
|
||||
msg.Type, from.ShortString(), msg.Data)
|
||||
}
|
||||
|
||||
// GetConnectedPeers returns the number of connected peers
|
||||
@@ -347,4 +272,4 @@ func (p *PubSub) Close() error {
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user