Skip to content

Commit b0bf425

Browse files
committed
migrations
1 parent 9f5a204 commit b0bf425

28 files changed

+2231
-168
lines changed

AGENTS.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,24 @@ Update guidelines:
3232
- for Agent Lightning migration tasks, ALWAYS mirror functionality, tests, and docs from `external/microsoft-agent-lightning`; treat the submodule as the canonical specification and never modify it directly
3333
- for Agent Lightning migration tasks, NEVER ship mocks, stubs, or placeholder implementations—port real behaviour before closing a task
3434
- for Agent Lightning runtime work, build on Microsoft Agent Framework components and `Microsoft.Extensions.AI`; prefer first-party packages under permissive (MIT) licenses
35+
- for Agent Lightning migration tasks, pursue the migration plan end-to-end without pausing to ask for clarification mid-task; deliver completed work unless the user explicitly redirects
36+
- for Agent Lightning migration tasks, when the user says "продовжити" or "continue", step through the requested workflow without further confirmation prompts
37+
- for Agent Lightning migration tasks, proactively capture improvement ideas directly in the working file (e.g., TODO comments) and implement them within the same task
38+
- for Agent Lightning migration tasks, default to progressing the migration even without an explicit "продовжити"/"continue"; halt only when the user gives new instructions
39+
- for Agent Lightning migration tasks, record any future follow-up items as `TODO:` comments in the relevant files so they are not lost
40+
- for Agent Lightning test coverage, include negative/error scenarios alongside positive cases to validate failure paths
3541
- maintain .NET central package management and keep the solution on .NET 9 / C# 13 with preview features enabled until GA guidance changes
3642
- always run `dotnet format --verify-no-changes` before `dotnet test` and make sure the full suite is green
3743
- reuse the ManagedCode Communication workflows for CI, CodeQL, and release automation; keep publish pipelines ready to push NuGet packages
3844
- avoid template artifacts (e.g., `Class1.cs`, `UnitTest1.cs`); name files and types according to their Agent Lightning domain responsibilities
3945
- keep documentation, code comments, and commit messaging in English
46+
- for .NET tests, feel free to use Shouldly assertions when they improve readability
4047

4148
## Solution Layout
4249

4350
- `external/microsoft-agent-lightning` – vendored Python sources used for parity checks and fixtures.
4451
- `src/ManagedCode.AgentLightning.Core` – shared domain models (`Rollout`, `Attempt`, hooks, etc.).
4552
- `src/ManagedCode.AgentLightning.AgentRuntime` – runtime orchestration built atop `Microsoft.Extensions.AI`.
46-
- `src/ManagedCode.AgentLightning.Cli` – CLI harness hosting the C# runtime (ships as an executable, not a package).
4753
- `tests/ManagedCode.AgentLightning.Tests` – xUnit suite validating runtime behaviour and parity scenarios.
4854
- `.github/workflows` – CI/CodeQL/release pipelines mirrored from ManagedCode Communication.
4955
- `MIGRATION_PLAN.md` – evergreen tracker for module-by-module parity progress.
@@ -54,7 +60,6 @@ Update guidelines:
5460
- .NET solution scaffolding in place with central package management and packaging metadata.
5561
- Core rollout and attempt models ported to C# with concurrency-safe metadata.
5662
- Initial `LightningAgent` runtime implemented using `IChatClient`, plus `LocalChatClient` for offline smoke testing.
57-
- CLI harness invokes the runtime and exposes an interactive loop.
5863
- CI, CodeQL, and release workflows added; `dotnet format` and `dotnet test` succeed locally.
5964
- `MIGRATION_PLAN.md` documents coverage and remaining workstreams.
6065

@@ -65,4 +70,4 @@ Update guidelines:
6570
3. Import Python fixtures into the C# test suite to exercise parity scenarios end-to-end.
6671
4. Implement adapters for real AI providers (OpenAI, Azure OpenAI, etc.) using Microsoft Agent Framework primitives.
6772
5. Design persistence abstractions mirroring the Python `store` package.
68-
6. Document configuration expectations and CLI commands for the new runtime.
73+
6. Document configuration expectations and hosting guidance for the new runtime.

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<Deterministic>true</Deterministic>
99
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1010
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
11-
<Version>0.1.0</Version>
11+
<Version>0.0.1</Version>
1212
<Authors>ManagedCode</Authors>
1313
<Company>ManagedCode</Company>
1414
<PackageLicenseExpression>MIT</PackageLicenseExpression>

Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<ItemGroup>
3-
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
3+
<PackageVersion Include="Shouldly" Version="4.2.1" />
44
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.10.1" />
55
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
66
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
@@ -13,5 +13,6 @@
1313
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
1414
<PackageVersion Include="xunit" Version="2.9.2" />
1515
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
16+
<PackageVersion Include="OpenTelemetry" Version="1.9.0" />
1617
</ItemGroup>
1718
</Project>

MIGRATION_PLAN.md

Lines changed: 100 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,108 @@
1-
# ManagedCode Agent Lightning C# Migration Plan
2-
3-
This document tracks the conversion of the original Python implementation to a .NET 9 / C# 13 codebase published under the ManagedCode namespace.
4-
The Python reference lives in the `external/microsoft-agent-lightning` submodule and remains the
5-
single source of truth for product behaviour until full parity is achieved.
6-
7-
## Repository Layout
8-
9-
- `external/microsoft-agent-lightning` &mdash; upstream Python sources used for reference and fixtures.
10-
- `src/ManagedCode.AgentLightning.Core` &mdash; shared domain models and primitives.
11-
- `src/ManagedCode.AgentLightning.AgentRuntime` &mdash; runtime orchestration for agents backed by `Microsoft.Extensions.AI`.
12-
- `src/ManagedCode.AgentLightning.Cli` &mdash; self-hosted CLI harness that exercises the C# runtime.
13-
- `tests/ManagedCode.AgentLightning.Tests` &mdash; xUnit test suite validating the C# port.
14-
15-
## Python Module Inventory
16-
17-
| Python Module | Summary | Migration Target | Status | Notes |
18-
|-------------------------------------------------------------------|--------------------------------------------------------------|-------------------------------------------------|----------------|-------|
19-
| `agentlightning/types/core.py`, `types/tracer.py` | Core data models, spans, rollouts | `ManagedCode.AgentLightning.Core/Models` | **In progress** | Triplet, Rollout, Attempt ported; tracer shapes pending. |
20-
| `agentlightning/litagent/` | Agent lifecycle, rollout orchestration | `ManagedCode.AgentLightning.AgentRuntime` | **In progress** | `LightningAgent` implemented with `IChatClient`; advanced features pending. |
21-
| `agentlightning/runner/` | Runner coordination, hooks, parallel execution | `ManagedCode.AgentLightning.AgentRuntime` | Not started | Need scheduling and multi-attempt coordination. |
22-
| `agentlightning/tracer/` | OpenTelemetry integrations | `ManagedCode.AgentLightning.Core` / `ManagedCode.AgentLightning.AgentRuntime` | Not started | Requires .NET OTEL pipeline. |
23-
| `agentlightning/store/` | Persistence layer | TBD | Not started | Identify .NET storage abstraction. |
24-
| `agentlightning/reward/` | Reward calculation utilities | TBD | Not started | Requires parity with RL tooling. |
25-
| `agentlightning/adapter/`, `execution/`, `algorithm/`, `trainer/` | Training pipelines, adapters, algorithms | TBD | Not started | Dependent on runner and tracer ports. |
26-
| `agentlightning/cli/` | Python CLI entry points | `ManagedCode.AgentLightning.Cli` | **In progress** | New CLI harness available; parity with Python commands pending. |
27-
| `agentlightning/server.py`, `client.py` | Legacy HTTP server/client | Separate ASP.NET/API project (future) | Not started | Decide on long-term hosting story. |
28-
| `agentlightning/logging.py` | Logging helpers | `.NET logging abstractions` | **In progress** | Logging routed through `Microsoft.Extensions.Logging`. |
29-
| `tests/` | Integration and parity tests | `tests/ManagedCode.AgentLightning.Tests` | Not started | Need fixtures mirroring upstream scenarios. |
1+
2+
# ManagedCode Agent Lightning Migration Plan
3+
4+
This plan tracks parity work between `external/microsoft-agent-lightning` (Python) and the C# port.
5+
6+
## Status Legend
7+
8+
- ✅ Complete in C#
9+
- 🚧 Planned / not yet ported
10+
- ❓ Needs investigation / decide if we port
11+
12+
## Core Building Blocks
13+
14+
| Component | Python Source | Status | Notes |
15+
| --- | --- | --- | --- |
16+
| Domain models | `agentlightning/types/core.py` || `ManagedCode.AgentLightning.Core/Models` – rollout/attempt/triplet + hooks |
17+
| Tracing models | `agentlightning/types/tracer.py` || `ManagedCode.AgentLightning.Core/Tracing` – span DTOs & helpers with OpenTelemetry tests |
18+
| Resources | `agentlightning/types/resources.py` || `ManagedCode.AgentLightning.Core/Resources` – LLM/proxy/prompt resources mirrored |
19+
| LitAgent base | `agentlightning/litagent/litagent.py` || `LitAgentBase<T>` with hook lifecycle, `LightningAgent` derives from it |
20+
| Adapter infrastructure | `agentlightning/adapter/base.py` || `Adapters/Adapter`, `TraceAdapter`, `TraceToMessagesAdapter` implemented with tests |
21+
| Runner infrastructure | `agentlightning/runner/base.py` || `LitAgentRunner` processes rollouts via LightningAgent and stores spans |
22+
| Store interface | `agentlightning/store/base.py` || `ILightningStore` contract + `InMemoryLightningStore` covering queue/attempt/span lifecycle |
23+
| Trainer orchestration | `agentlightning/trainer/trainer.py` || `Trainer` orchestrates batches via store + runner (tested) |
24+
25+
## Span & Resource Adapters
26+
27+
| Adapter | Python Source | Status | Notes |
28+
| --- | --- | --- | --- |
29+
| Trace → messages | `adapter/messages.py` | 🚧 | Convert spans to chat history for `IChatClient` |
30+
| Trace → triplets | `adapter/triplet.py` | 🚧 | Build reward-aware triplets from spans |
31+
| OTEL trace adapter | `adapter/base.py` | 🚧 | Hook Activity -> SpanModel bridging |
32+
33+
## Execution & Store Layers
34+
35+
| Component | Python Source | Status | Notes |
36+
| --- | --- | --- | --- |
37+
| LightningStore (async) | `store/base.py` | 🚧 | Async contract mirroring enqueue/start/query APIs |
38+
| In-memory store | `store/memory.py` | 🚧 | Production-grade concurrency port |
39+
| Client/server bridge | `store/client_server.py` || Decide ASP.NET hosting approach |
40+
| Runner execution strategies | `execution/*` | 🚧 | Channel/task-based equivalents |
41+
42+
## Algorithms & Training Pipelines
43+
44+
| Component | Python Source | Status | Notes |
45+
| --- | --- | --- | --- |
46+
| Algorithm base class | `algorithm/base.py` | 🚧 | Define async lifecycle (`SetupAsync`, `TrainAsync`, `TeardownAsync`) with dataset plumbing |
47+
| Fast baseline algorithms | `algorithm/fast.py` || Decide whether to port representative baseline for smoke tests |
48+
| APO (Automatic Prompt Optimization) | `algorithm/apo/apo.py` | 🚧 | Requires prompt diffing, versioned templates, and evaluation harness |
49+
| VERL distributed trainer | `algorithm/verl/*` || Needs multi-process orchestration design in .NET (potential future phase) |
50+
| Trainer legacy compat | `trainer/legacy.py` | 🚧 | Implement legacy hooks while aligning with new runner/store abstractions |
51+
| Trainer orchestration | `trainer/trainer.py` | 🚧 | Port training loop, scheduler, and algorithm/run coordination |
52+
| Registry/config utilities | `trainer/registry.py`, `trainer/init_utils.py` | 🚧 | Recreate component registration and config binding over `Options` |
53+
54+
## Reward & Instrumentation
55+
56+
| Component | Python Source | Status | Notes |
57+
| --- | --- | --- | --- |
58+
| Reward emitters | `emitter/reward.py`, `reward.py` | 🚧 | Implement reward span helpers with OTEL integration |
59+
| Message/object emitters | `emitter/message.py`, `emitter/object.py`, `emitter/utils.py` | 🚧 | Required for parity in trace adapters |
60+
| Instrumentation (AgentOps, LiteLLM, vLLM) | `instrumentation/*` || Determine .NET bindings and optionality |
61+
| Logging utilities | `logging.py` || Replaced with `Microsoft.Extensions.Logging` configuration helpers |
62+
| LLM proxy instrumentation | `llm_proxy.py` || Evaluate hosting (ASP.NET Core) and span exporter support |
63+
64+
## Fixtures, Docs & Tooling
65+
66+
| Area | Status | Notes |
67+
| --- | --- | --- |
68+
| Python fixture import | 🚧 | Need harness to reuse JSON/SQLite fixtures from submodule |
69+
| Integration test parity | 🚧 | Blocked until adapters, store, runner port complete |
70+
| Docs & README updates | 🚧 | Document hosting, configuration, and migration progress |
71+
| Packaging & CI || .NET solution, format/test gates, and workflows in place |
72+
73+
## External Interfaces
74+
75+
| Component | Python Source | Status | Notes |
76+
| --- | --- | --- | --- |
77+
| LLM proxy service | `llm_proxy.py` || Evaluate ASP.NET Core standalone proxy |
78+
| Logging helpers | `logging.py` || Using `Microsoft.Extensions.Logging` |
79+
| Legacy server/client | `server.py`, `client.py` || Decide on support for legacy flows |
80+
81+
## Test Parity
82+
83+
| Area | Status | Notes |
84+
| --- | --- | --- |
85+
| Core models & resources || Unit tests in `ManagedCode.AgentLightning.Tests` |
86+
| Span conversions || `Tracing/SpanModelTests` |
87+
| Resource helper coverage || `Resources/ResourceModelTests` |
88+
| Adapter tests | 🚧 | Need to mirror upstream fixtures |
89+
| Runner/store/trainer integration | 🚧 | Blocked until components ported |
3090

3191
## Completed Work
3292

33-
- Converted repository scaffold to .NET 9 / C# 13 solution with central package management.
34-
- Implemented core rollout models (`Triplet`, `Attempt`, `Rollout`, hooks) in `ManagedCode.AgentLightning.Core`.
35-
- Ported fundamental agent execution pipeline powered by `Microsoft.Extensions.AI.IChatClient`.
36-
- Added `LocalChatClient` for offline validation and connected CLI harness.
37-
- Established CI, CodeQL, and release workflows mirroring ManagedCode patterns.
38-
- Added initial integration test covering `LightningAgent` execution against the local client.
93+
- .NET 9 solution scaffolding with central package management
94+
- Core rollout/attempt models and runtime scaffolding (`LightningAgent` + `LocalChatClient`)
95+
- CI/CodeQL/release workflows (ManagedCode templates)
96+
- Span/resource models with OpenTelemetry conversions and unit coverage
3997

4098
## Near-Term Priorities
4199

42-
1. Port tracer data structures (`Span`, OTEL conversions) and integrate with .NET OpenTelemetry.
43-
2. Bring over runner orchestration primitives (parallel workers, retry policies, resource slots).
44-
3. Reproduce Python parity tests by sourcing fixtures from the submodule.
45-
4. Introduce configurable connectors for real AI providers using `Microsoft.Extensions.AI` builders.
46-
5. Document configuration and extension points in `README.md`.
47-
48-
## Tracking Progress
100+
1. Port trace adapters (messages, triplets) to convert spans into actionable payloads.
101+
2. Implement store abstractions (interface + in-memory implementation) to unblock runner tests.
102+
3. Port runner orchestration and cover end-to-end execution (agent + store + adapters).
103+
4. Reproduce key Python fixtures/tests for adapters and store logic.
104+
5. Plan hosting story for LLM proxy / legacy endpoints (document decisions).
49105

50-
Update this file whenever:
106+
## Tracking Guidance
51107

52-
- A Python module gains a parity implementation or has design decisions documented.
53-
- Tests are ported or new coverage approaches are introduced.
54-
- Workflow or packaging behaviours change.
55-
- Deprecated guidance is removed or superseded.
108+
Update this document whenever a component moves between statuses or when new design decisions affect parity.

ManagedCode.AgentLightning.sln

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedCode.AgentLightning.
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedCode.AgentLightning.AgentRuntime", "src\ManagedCode.AgentLightning.AgentRuntime\ManagedCode.AgentLightning.AgentRuntime.csproj", "{59FE07C9-6A6C-4A6E-89DB-726A29E7B9B6}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedCode.AgentLightning.Cli", "src\ManagedCode.AgentLightning.Cli\ManagedCode.AgentLightning.Cli.csproj", "{26BEADEA-4780-466D-9488-4F1920FBFF90}"
13-
EndProject
1412
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagedCode.AgentLightning.Tests", "tests\ManagedCode.AgentLightning.Tests\ManagedCode.AgentLightning.Tests.csproj", "{4B831725-AF23-4E64-A5E2-74BB02F46FB4}"
1513
EndProject
1614
Global
@@ -47,18 +45,6 @@ Global
4745
{59FE07C9-6A6C-4A6E-89DB-726A29E7B9B6}.Release|x64.Build.0 = Release|Any CPU
4846
{59FE07C9-6A6C-4A6E-89DB-726A29E7B9B6}.Release|x86.ActiveCfg = Release|Any CPU
4947
{59FE07C9-6A6C-4A6E-89DB-726A29E7B9B6}.Release|x86.Build.0 = Release|Any CPU
50-
{26BEADEA-4780-466D-9488-4F1920FBFF90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51-
{26BEADEA-4780-466D-9488-4F1920FBFF90}.Debug|Any CPU.Build.0 = Debug|Any CPU
52-
{26BEADEA-4780-466D-9488-4F1920FBFF90}.Debug|x64.ActiveCfg = Debug|Any CPU
53-
{26BEADEA-4780-466D-9488-4F1920FBFF90}.Debug|x64.Build.0 = Debug|Any CPU
54-
{26BEADEA-4780-466D-9488-4F1920FBFF90}.Debug|x86.ActiveCfg = Debug|Any CPU
55-
{26BEADEA-4780-466D-9488-4F1920FBFF90}.Debug|x86.Build.0 = Debug|Any CPU
56-
{26BEADEA-4780-466D-9488-4F1920FBFF90}.Release|Any CPU.ActiveCfg = Release|Any CPU
57-
{26BEADEA-4780-466D-9488-4F1920FBFF90}.Release|Any CPU.Build.0 = Release|Any CPU
58-
{26BEADEA-4780-466D-9488-4F1920FBFF90}.Release|x64.ActiveCfg = Release|Any CPU
59-
{26BEADEA-4780-466D-9488-4F1920FBFF90}.Release|x64.Build.0 = Release|Any CPU
60-
{26BEADEA-4780-466D-9488-4F1920FBFF90}.Release|x86.ActiveCfg = Release|Any CPU
61-
{26BEADEA-4780-466D-9488-4F1920FBFF90}.Release|x86.Build.0 = Release|Any CPU
6248
{4B831725-AF23-4E64-A5E2-74BB02F46FB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6349
{4B831725-AF23-4E64-A5E2-74BB02F46FB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
6450
{4B831725-AF23-4E64-A5E2-74BB02F46FB4}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -78,7 +64,6 @@ Global
7864
GlobalSection(NestedProjects) = preSolution
7965
{5B342791-2739-4DEF-8662-3FAC7145772A} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
8066
{59FE07C9-6A6C-4A6E-89DB-726A29E7B9B6} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
81-
{26BEADEA-4780-466D-9488-4F1920FBFF90} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
8267
{4B831725-AF23-4E64-A5E2-74BB02F46FB4} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
8368
EndGlobalSection
8469
EndGlobal

0 commit comments

Comments
 (0)