diff options
Diffstat (limited to 'src/Agent.Mcp/QueuedTaskWorker.cs')
| -rw-r--r-- | src/Agent.Mcp/QueuedTaskWorker.cs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Agent.Mcp/QueuedTaskWorker.cs b/src/Agent.Mcp/QueuedTaskWorker.cs new file mode 100644 index 0000000..23404e3 --- /dev/null +++ b/src/Agent.Mcp/QueuedTaskWorker.cs @@ -0,0 +1,18 @@ +using Agent.Core.Tasks; +using Microsoft.Extensions.Hosting; +using Agent.Core.Runtime; + +namespace Agent.Mcp; + +public sealed class QueuedTaskWorker(TaskRegistry registry, AgentRuntime runtime) : BackgroundService +{ + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + await foreach (Guid taskId in registry.ReadQueuedAsync(stoppingToken).ConfigureAwait(false)) + { + if (!registry.Transition(taskId, AgentTaskState.Planning, "planning")) continue; + registry.Transition(taskId, AgentTaskState.Running, "ollama chat"); + await runtime.ExecuteAsync(taskId, stoppingToken).ConfigureAwait(false); + } + } +} |
