-
Notifications
You must be signed in to change notification settings - Fork 28
fix(subagents): session-correlated sub-agent log observability #1428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
38a679e
feat: improve sub-agent observability instrumentation
f2d801c
fix(subagents): log progress events, drop non-functional OTel spans
Aaronontheweb dcb01df
Merge branch 'dev' into feat/subagent-observability
Aaronontheweb 029004a
Merge branch 'dev' into feat/subagent-observability
Aaronontheweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
src/Netclaw.Actors.Tests/SubAgents/SubAgentObservabilityTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="SubAgentObservabilityTests.cs" company="Petabridge, LLC"> | ||
| // Copyright (C) 2026 - 2026 Petabridge, LLC <https://petabridge.com> | ||
| // </copyright> | ||
| // ----------------------------------------------------------------------- | ||
| using Akka.Actor; | ||
| using Akka.Hosting; | ||
| using Akka.Hosting.TestKit; | ||
| using Microsoft.Extensions.AI; | ||
| using Netclaw.Actors.SubAgents; | ||
| using Netclaw.Actors.Tests.Memory; | ||
| using Netclaw.Configuration; | ||
| using Netclaw.Tools; | ||
| using Xunit; | ||
|
|
||
| namespace Netclaw.Actors.Tests.SubAgents; | ||
|
|
||
| /// <summary> | ||
| /// Observability coverage for <see cref="SubAgentActor"/>: progress phases and | ||
| /// lifecycle events must surface in the logs (and therefore Seq) even on the | ||
| /// non-streaming spawn path, where the actor has no activity sink to write to. | ||
| /// Before the observability work these phases only reached a parent-owned channel | ||
| /// (or, with no sink, nothing at all). Regression coverage for issues #1429/#1431. | ||
| /// </summary> | ||
| public sealed class SubAgentObservabilityTests : TestKit | ||
| { | ||
| public SubAgentObservabilityTests(ITestOutputHelper output) : base(output: output) { } | ||
|
|
||
| protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider) | ||
| { | ||
| // INFO so the EventFilter assertions on the sub-agent's progress and | ||
| // lifecycle logs are deterministic. | ||
| builder.AddHocon("akka.loglevel = INFO", HoconAddMode.Prepend); | ||
| } | ||
|
|
||
| private static SubAgentDefinition CreateDefinition(IReadOnlyList<INetclawTool>? tools = null) | ||
| => new() | ||
| { | ||
| Name = new AgentName("test-agent"), | ||
| SystemPrompt = "You are a test agent.", | ||
| Tools = tools ?? [], | ||
| EmitStructuredFindings = false | ||
| }; | ||
|
|
||
| private static RunSubAgent NewRun(string task, string? scopeId = null) | ||
| => new() | ||
| { | ||
| Task = task, | ||
| Timeout = TimeSpan.FromSeconds(5), | ||
| Audience = TrustAudience.Personal, | ||
| SessionScopeId = scopeId | ||
| }; | ||
|
|
||
| [Fact] | ||
| public async Task Progress_phase_is_logged_on_the_non_streaming_path() | ||
| { | ||
| // No ActivitySink is supplied (the non-streaming spawn_agent path). Before | ||
| // the fix EmitActivity was a no-op here, so a long run emitted almost nothing | ||
| // between start and completion. Now the phase is logged, so it is visible and | ||
| // diagnosable in Seq. The scope id mirrors a real spawn so the SessionId/ | ||
| // SubSessionId enrichment branch is exercised too. | ||
| var agent = Sys.ActorOf(SubAgentActor.CreateProps(CreateDefinition(), new FakeChatClient())); | ||
|
|
||
| await EventFilter.Info(contains: "calling the model").ExpectAsync(1, async () => | ||
| { | ||
| await agent.Ask<SubAgentResult>( | ||
| NewRun("Say hello", "console/C123/subagent/test-agent/run-abc"), | ||
| TimeSpan.FromSeconds(5), | ||
| TestContext.Current.CancellationToken); | ||
| }, cancellationToken: TestContext.Current.CancellationToken); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Completion_emits_summary_with_cumulative_stats() | ||
| { | ||
| var agent = Sys.ActorOf(SubAgentActor.CreateProps(CreateDefinition(), new FakeChatClient())); | ||
|
|
||
| // The summary line carries the cumulative tool/iteration/duration stats used | ||
| // for sub-agent run analysis. | ||
| await EventFilter.Info(contains: "summary:").ExpectAsync(1, async () => | ||
| { | ||
| await agent.Ask<SubAgentResult>( | ||
| NewRun("Say hello"), TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken); | ||
| }, cancellationToken: TestContext.Current.CancellationToken); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Tool_dispatch_logs_a_tool_start_event_with_call_id() | ||
| { | ||
| var fakeTool = new FakeNetclawTool("greet", "Hello from tool!"); | ||
| var fakeClient = new FakeChatClient | ||
| { | ||
| ToolCallsOnFirstCall = | ||
| [ | ||
| new FunctionCallContent("call-1", "greet", | ||
| new Dictionary<string, object?> { ["name"] = "World" }) | ||
| ] | ||
| }; | ||
| var agent = Sys.ActorOf(SubAgentActor.CreateProps(CreateDefinition([fakeTool]), fakeClient)); | ||
|
|
||
| // A tool start event (distinct from the existing tool-result log) lets an | ||
| // operator see when a slow tool began, not just when it finished. | ||
| await EventFilter.Info(contains: "tool start callId=call-1 name=greet").ExpectAsync(1, async () => | ||
| { | ||
| await agent.Ask<SubAgentResult>( | ||
| NewRun("Greet the user"), TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken); | ||
| }, cancellationToken: TestContext.Current.CancellationToken); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM