Add BotSharp.Plugin.Dify for hybrid workflow orchestration #15
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.
Implements a hybrid architecture where BotSharp handles authentication, routing, and control while delegating complex content generation to Dify workflows via REST API integration.
Implementation
Plugin Core
DifyPlugin- IBotSharpPlugin implementation with DI registrationCallDifyWorkflowFn- IFunctionCallback for sync/async workflow executionDifyWorkflowService- HTTP client for Dify API (POST /v1/workflows/{id}/run)Async Task Management
DifyTaskPollingService- BackgroundService that polls workflow status at configurable intervalsDifyTaskStorageService- Thread-safe in-memory task tracking (replaceable with persistent storage)Models
DifyWorkflowRequest/Response- API DTOs matching Dify's schemaDifyWorkflowTask- Internal task state with polling attempt trackingDifyWorkflowArgs- Function arguments from LLM callsUsage
{ "function": "dify-workflow-execute", "arguments": { "workflow_id": "data-analyzer", "inputs": "{\"sales_data\": {...}, \"format\": \"summary\"}", "async": true, "conversation_id": "conv-123" } }Sync mode: Blocks until completion, suitable for <30s tasks
Async mode: Returns task_id immediately, polls in background, supports session resumption
Configuration
{ "Dify": { "BaseUrl": "https://api.dify.ai", "ApiKey": "your-key", "PollingIntervalSeconds": 10, "MaxPollingAttempts": 180, "TimeoutSeconds": 300 } }Testing
10 unit tests covering task storage, model initialization, and state transitions. In-memory storage is production-ready pattern for replacement with Redis/SQL.
Architecture Decision
Polling-based status checking chosen due to Dify's lack of webhook support. Designed for webhook replacement when available. Background service prevents thread blocking during long-running workflows (minutes to hours).
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.