Skip to content

Commit 3cf2300

Browse files
committed
Enhance LitAgentRunner and related classes for improved execution and parallelism support
1 parent 93ee0a7 commit 3cf2300

File tree

7 files changed

+512
-52
lines changed

7 files changed

+512
-52
lines changed

MIGRATION_PLAN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This plan tracks parity work between `external/microsoft-agent-lightning` (Pytho
3737
| LightningStore (async) | `store/base.py` || `ILightningStore` exposes start/enqueue/start-attempt, span sequencing, and wait semantics |
3838
| In-memory store | `store/memory.py` || Expanded store handles attempts, spans, resources, and polling waits with thread-safe state |
3939
| Client/server bridge | `store/client_server.py` || Decide ASP.NET hosting approach |
40-
| Runner execution strategies | `execution/*` | 🚧 | C# runner tracks worker ids, retries via store requeue; parallel orchestration still pending |
40+
| Runner execution strategies | `execution/*` | 🚧 | C# runner supports single-step execution, retry-aware polling, and resource hydration; parallel orchestration still pending |
4141

4242
## Algorithms & Training Pipelines
4343

src/ManagedCode.AgentLightning.AgentRuntime/LightningAgent.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using System.Collections.Generic;
12
using System.Collections.ObjectModel;
3+
using System.Linq;
24
using ManagedCode.AgentLightning.Core.Models;
5+
using ManagedCode.AgentLightning.Core.Resources;
36
using Microsoft.Extensions.AI;
47
using Microsoft.Extensions.Logging;
58

@@ -41,7 +44,20 @@ public LightningAgent(
4144
_timeProvider = timeProvider ?? TimeProvider.System;
4245
}
4346

44-
protected override async Task<LightningExecutionResult> RolloutAsync(object taskInput, CancellationToken cancellationToken)
47+
public Task<LightningExecutionResult> ExecuteAsync(
48+
object taskInput,
49+
NamedResources? resources,
50+
string? resourcesId,
51+
RolloutMode? mode = null,
52+
CancellationToken cancellationToken = default) =>
53+
base.ExecuteAsync(taskInput, resources, mode, resourcesId, cancellationToken);
54+
55+
protected override async Task<LightningExecutionResult> RolloutAsync(
56+
object taskInput,
57+
NamedResources? resources,
58+
RolloutMode? mode,
59+
string? resourcesId,
60+
CancellationToken cancellationToken)
4561
{
4662
ThrowIfDisposed();
4763

@@ -52,15 +68,34 @@ protected override async Task<LightningExecutionResult> RolloutAsync(object task
5268
taskInput,
5369
startTimestamp,
5470
config: _options.RolloutConfig,
55-
mode: null,
56-
resourcesId: null);
71+
mode: mode,
72+
resourcesId: resourcesId);
5773

5874
var attempt = new Attempt(
5975
rolloutId,
6076
$"{rolloutId}:attempt:1",
6177
sequenceId: 1,
6278
startTimestamp);
6379

80+
if (!string.IsNullOrEmpty(resourcesId))
81+
{
82+
var id = resourcesId!;
83+
rollout.AddMetadata("resources.id", id);
84+
attempt.AddMetadata("resources.id", id);
85+
}
86+
87+
if (resources is { Count: > 0 })
88+
{
89+
var resourceNames = resources.Keys.ToArray();
90+
rollout.AddMetadata("resources.names", resourceNames);
91+
attempt.AddMetadata("resources.names", resourceNames);
92+
}
93+
94+
if (mode is { } rolloutMode)
95+
{
96+
rollout.AddMetadata("mode", rolloutMode.ToString());
97+
}
98+
6499
var context = new LightningContext(this, this, rollout);
65100
await InvokeHooksAsync(h => h.OnTraceStartAsync(context, cancellationToken), cancellationToken).ConfigureAwait(false);
66101

src/ManagedCode.AgentLightning.AgentRuntime/LitAgentBase.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using ManagedCode.AgentLightning.AgentRuntime.Runner;
2+
using ManagedCode.AgentLightning.Core.Models;
3+
using ManagedCode.AgentLightning.Core.Resources;
24

35
namespace ManagedCode.AgentLightning.AgentRuntime;
46

@@ -26,10 +28,25 @@ internal void AttachRunner(LitAgentRunner runner)
2628

2729
public virtual bool IsAsync => true;
2830

29-
public async Task<LightningExecutionResult> ExecuteAsync(TTask task, CancellationToken cancellationToken = default)
31+
public Task<LightningExecutionResult> ExecuteAsync(TTask task, CancellationToken cancellationToken = default) =>
32+
ExecuteAsync(task, resources: null, mode: null, resourcesId: null, cancellationToken);
33+
34+
public Task<LightningExecutionResult> ExecuteAsync(
35+
TTask task,
36+
NamedResources? resources,
37+
RolloutMode? mode,
38+
CancellationToken cancellationToken = default) =>
39+
ExecuteAsync(task, resources, mode, resourcesId: null, cancellationToken);
40+
41+
public async Task<LightningExecutionResult> ExecuteAsync(
42+
TTask task,
43+
NamedResources? resources,
44+
RolloutMode? mode,
45+
string? resourcesId,
46+
CancellationToken cancellationToken = default)
3047
{
3148
await OnRolloutStartAsync(task, cancellationToken).ConfigureAwait(false);
32-
var result = await RolloutAsync(task, cancellationToken).ConfigureAwait(false);
49+
var result = await RolloutAsync(task, resources, mode, resourcesId, cancellationToken).ConfigureAwait(false);
3350
await OnRolloutEndAsync(task, result, cancellationToken).ConfigureAwait(false);
3451
return result;
3552
}
@@ -39,5 +56,10 @@ public async Task<LightningExecutionResult> ExecuteAsync(TTask task, Cancellatio
3956
protected virtual Task OnRolloutEndAsync(TTask task, LightningExecutionResult result, CancellationToken cancellationToken) =>
4057
Task.CompletedTask;
4158

42-
protected abstract Task<LightningExecutionResult> RolloutAsync(TTask task, CancellationToken cancellationToken);
59+
protected abstract Task<LightningExecutionResult> RolloutAsync(
60+
TTask task,
61+
NamedResources? resources,
62+
RolloutMode? mode,
63+
string? resourcesId,
64+
CancellationToken cancellationToken);
4365
}

0 commit comments

Comments
 (0)