feat: Integrate Ollama reasoning for initial task planning
This commit introduces the new 'reasoning' module, which allows the bzzz-agent to connect to a local Ollama instance. It also modifies the 'github' integration module to use this new capability. When a task is claimed, the agent now generates a step-by-step execution plan using an Ollama model and publishes this plan to the Antennae meta-discussion channel for peer review before proceeding. This completes Phase 1 of the Ollama integration plan.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/deepblackcloud/bzzz/pubsub"
|
||||
"github.com/deepblackcloud/bzzz/reasoning" // Import the new reasoning module
|
||||
)
|
||||
|
||||
// Integration handles the integration between GitHub tasks and Bzzz P2P coordination
|
||||
@@ -150,33 +151,74 @@ func (i *Integration) announceTaskClaim(task *Task) error {
|
||||
return i.pubsub.PublishBzzzMessage(pubsub.TaskClaim, data)
|
||||
}
|
||||
|
||||
// executeTask simulates task execution
|
||||
// executeTask is where the agent performs the work for a claimed task.
|
||||
// It now includes a reasoning step to form a plan before execution.
|
||||
func (i *Integration) executeTask(task *Task) {
|
||||
fmt.Printf("🚀 Starting execution of task #%d: %s\n", task.Number, task.Title)
|
||||
|
||||
// Announce task progress
|
||||
|
||||
// Announce that the task has started
|
||||
progressData := map[string]interface{}{
|
||||
"task_id": task.Number,
|
||||
"agent_id": i.config.AgentID,
|
||||
"status": "started",
|
||||
"timestamp": time.Now().Unix(),
|
||||
}
|
||||
|
||||
if err := i.pubsub.PublishBzzzMessage(pubsub.TaskProgress, progressData); err != nil {
|
||||
fmt.Printf("⚠️ Failed to announce task progress: %v\n", err)
|
||||
fmt.Printf("⚠️ Failed to announce task start: %v\n", err)
|
||||
}
|
||||
|
||||
// === REASONING STEP ===
|
||||
// Use Ollama to generate a plan based on the task's title and body.
|
||||
fmt.Printf("🧠 Reasoning about task #%d to form a plan...\n", task.Number)
|
||||
|
||||
// Simulate work (in a real implementation, this would be actual task execution)
|
||||
workDuration := time.Duration(30+task.Priority*10) * time.Second
|
||||
fmt.Printf("⏳ Working on task for %v...\n", workDuration)
|
||||
time.Sleep(workDuration)
|
||||
// Construct the prompt for the reasoning model
|
||||
prompt := fmt.Sprintf("You are an expert AI developer. Based on the following GitHub issue, create a concise, step-by-step plan to resolve it. Issue Title: %s. Issue Body: %s.", task.Title, task.Body)
|
||||
|
||||
// Complete the task
|
||||
// Select a model (this could be made more dynamic later)
|
||||
model := "phi3"
|
||||
|
||||
// Generate the plan using the reasoning module
|
||||
plan, err := reasoning.GenerateResponse(i.ctx, model, prompt)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Failed to generate execution plan for task #%d: %v\n", task.Number, err)
|
||||
// Announce failure and return
|
||||
// (Error handling logic would be more robust in a real implementation)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("📝 Generated Plan for task #%d:\n%s\n", task.Number, plan)
|
||||
|
||||
// === META-DISCUSSION STEP ===
|
||||
// Announce the plan on the Antennae channel for peer review.
|
||||
metaMsg := map[string]interface{}{
|
||||
"issue_id": task.Number,
|
||||
"node_id": i.config.AgentID,
|
||||
"message": "Here is my proposed plan of action. Please review and provide feedback within the next 60 seconds.",
|
||||
"plan": plan,
|
||||
"msg_id": fmt.Sprintf("plan-%d-%d", task.Number, time.Now().UnixNano()),
|
||||
"parent_id": nil,
|
||||
"hop_count": 1,
|
||||
"timestamp": time.Now().Unix(),
|
||||
}
|
||||
|
||||
if err := i.pubsub.PublishAntennaeMessage(pubsub.MetaDiscussion, metaMsg); err != nil {
|
||||
fmt.Printf("⚠️ Failed to publish plan to meta-discussion channel: %v\n", err)
|
||||
}
|
||||
|
||||
// Wait for a short "objection period"
|
||||
fmt.Println("⏳ Waiting 60 seconds for peer feedback on the plan...")
|
||||
time.Sleep(60 * time.Second)
|
||||
// In a full implementation, this would listen for responses on the meta-discussion topic.
|
||||
|
||||
// For now, we assume the plan is good and proceed.
|
||||
fmt.Printf("✅ Plan for task #%d approved. Proceeding with execution.\n", task.Number)
|
||||
|
||||
// Complete the task on GitHub
|
||||
results := map[string]interface{}{
|
||||
"status": "completed",
|
||||
"execution_time": workDuration.String(),
|
||||
"execution_plan": plan,
|
||||
"agent_id": i.config.AgentID,
|
||||
"deliverables": []string{"Implementation completed", "Tests passed", "Documentation updated"},
|
||||
"deliverables": []string{"Plan generated and approved", "Execution logic would run here"},
|
||||
}
|
||||
|
||||
if err := i.client.CompleteTask(task.Number, i.config.AgentID, results); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user