6.5 KiB
Real OpenHands SDK Integration - Implementation Summary
Date: 2025-12-03 Workflow ID: MTOuLh34F2dadDDF Status: ✅ Successfully Updated Version: 8 (updated)
What Was Implemented
Successfully replaced test mode with real OpenHands SDK integration across all critical nodes:
Node 3: Get Next Todo - ✅ Updated
Purpose: Todo state tracking with workflow staticData
Implementation:
- Uses
$workflow.staticDatato maintain state across iterations - Handles initial push (creates todos) vs subsequent pushes (executes todos)
- Manages
current_indexandlistarrays - Returns specific actions:
create_todos,execute_todo, orcomplete
Key Code:
const workflow = $workflow;
workflow.staticData.todos = workflow.staticData.todos || {};
if (repoInfo.is_initial_push) {
workflow.staticData.todos.pending = repoInfo.prompt;
workflow.staticData.todos.current_index = 0;
return { action: 'create_todos', prompt: repoInfo.prompt, is_initial: true };
} else if (workflow.staticData.todos.list &&
workflow.staticData.todos.current_index < workflow.staticData.todos.list.length) {
const index = workflow.staticData.todos.current_index;
const todo = workflow.staticData.todos.list[index];
return { action: 'execute_todo', todo: todo, index: index, total: workflow.staticData.todos.list.length };
}
Node 4: Execute Todo - ✅ Updated
Purpose: Real OpenHands SDK calls
Implementation:
-
Create TODOs Mode:
- Calls OpenHands to analyze MVP prompt
- Creates TODO.md with structured tasks
- Parses JSON response and stores in staticData
- Returns
todos_createdaction
-
Execute Todo Mode:
- Calls OpenHands with detailed task instructions
- Executes each todo sequentially
- Increments
current_indexfor next iteration - Handles errors gracefully (continues to avoid infinite loop)
- Returns
todo_executedorerroraction
SDK Call:
const command = `/tmp/software-agent-sdk/.venv/bin/python3 /home/bam/openhands-sdk-wrapper.py "${task}" --workspace ${workspace} --json`;
const output = execSync(command, { encoding: 'utf-8', timeout: 300000 });
const result = JSON.parse(output);
Task Structure:
todo.title- Name of the tasktodo.description- Detailed descriptiontodo.category- Backend|Frontend|Integration|Testingtodo.files- Array of files to create/modifytodo.commands- Commands to executetodo.expected_outcome- Success criteria
Node 5: Format Response - ✅ Updated
Purpose: Progress tracking and action routing
Implementation:
- Handles different actions with appropriate formatting
- Provides progress messages with completion counts
- Sets
should_continueflag to control loop - Routes:
todos_created→todo_list_ready,todo_executed→todo_completed,complete→all_complete
Action Types:
todo_list_ready- Initial todo creation completetodo_completed- Individual todo finishedall_complete- All todos finishedexecution_error- Error occurred but continue
Node 6: Prepare Gitea Commit - ✅ Updated
Purpose: Format commit messages based on execution results
Implementation:
- Maps actions to appropriate commit messages:
todo_list_ready→ "Created TODO.md with X tasks"todo_completed→ "✅ Complete: [task name]"all_complete→ "🎉 MVP Complete: All todos finished"execution_error→ "⚠️ Error: [message]"
- Prepares commit data with parent SHAs
- Sets
should_continueflag
Workflow Flow
[1] Webhook (Gitea push)
↓
[2] Extract Repo Info
↓
[3] Get Next Todo (state tracking)
↓
[4] Execute Todo (REAL OpenHands SDK)
↓
[5] Format Response (progress tracking)
↓
[6] Prepare Gitea Commit
↓
[7] Commit to Gitea
↓ (loop back to [3])
Key Features
1. State Management
- Uses
$workflow.staticData.todosfor persistence - Maintains:
list,current_index,pending,status - Survives workflow restarts
2. OpenHands SDK Integration
- Direct CLI execution via Python wrapper
- JSON output parsing
- 5-minute timeout per call
- Error handling with continuation
3. Loop Control
- Returns to Node 3 after each iteration
should_continueflag controls flow- Increments index even on error to prevent infinite loops
4. Progress Tracking
- Each todo shows: "Completed: Task Name (X/Y)"
- Final status when all todos complete
- Error reporting with context
Testing
Test Command:
curl -X POST https://n8n.oky.sh/webhook/todo-mvp-builder \
-H "Content-Type: application/json" \
-d '{
"repository": {"name": "test-app", "full_name": "user/test-app"},
"head_commit": {"message": "MVP Prompt: Create a todo app"},
"ref": "refs/heads/main",
"after": "abc123def456"
}'
Expected Behavior:
- First Run: OpenHands analyzes prompt → Creates TODO.md → Commits todo list
- Subsequent Runs: OpenHands executes each todo → Commits after each
- Final: All todos complete → Commits completion message
SDK Wrapper Details
Location: /home/bam/openhands-sdk-wrapper.py
Python Path: /tmp/software-agent-sdk/.venv/bin/python3
Usage:
python3 /home/bam/openhands-sdk-wrapper.py "task description" --workspace /path/to/workspace --json
Returns:
{
"success": true,
"output": "...",
"error": null
}
API Updates Made
Workflow Updated: 2025-12-03 21:09:09 UTC
- Version ID: a3c31635-c946-4bde-b89e-3107a2e8975c
- Version Counter: 8
- Nodes Updated: 4 (Get Next Todo, Execute Todo, Format Response, Prepare Gitea Commit)
- Connections: Preserved (7 nodes, loop back to Node 3)
Files Updated
/tmp/workflow_update2.json- Updated workflow JSON (used for API call)- This documentation file
Next Steps
- Manual Reactivation: May need to toggle workflow active/inactive in n8n UI
- Webhook Registration: Production webhook may need 30-60 seconds to fully register
- Real Repository Test: Test with actual Gitea repository push
- Monitor Executions: Check n8n execution logs for OpenHands SDK output
Notes
- ✅ Workflow successfully updated via n8n API
- ✅ All nodes use typeVersion 2 (code nodes)
- ✅ SDK integration is real (not test mode)
- ✅ State persistence via staticData
- ⚠️ Webhook may require manual reactivation
- ⚠️ Gitea credentials configured in workflow
Implementation Complete: Real OpenHands SDK is now integrated and ready for production use.