Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions BlogWriter.Tests/BloggerAgentRoutingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ public async Task ResearchButNoDraft_RoutesToAuthor()
Assert.Equal("author", decision.NextStep);
}

[Fact]
public async Task RefinementResetsState_AndRoutesToResearcher()
{
var state = new ResearchState
{
MainTask = "topic",
ResearchFindings = ["some findings"],
CurrentSubTask = "Add a caching section.",
Draft = "a draft",
ReviewNotes = ResearchState.ApprovedMarker,
};

state.StartFollowUp("Add a caching section.");
BloggerDecision decision = await CreateAgent().InvokeAsync(state);

Assert.Equal("researcher", decision.NextStep);
Assert.Empty(state.Draft);
Assert.Empty(state.ResearchFindings);
}

[Fact]
public async Task DraftWithNoReview_RoutesToReviewer()
{
Expand Down
6 changes: 3 additions & 3 deletions BlogWriter.Tests/ResearchStateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void RevisionLimitReached_RequiresUnapprovedReviewAtCap(
}

[Fact]
public void StartFollowUp_PreservesDraftAndResearchButResetsReviewCycle()
public void StartFollowUp_ResetsResearchAndDraftSoRefinedSearchTriggersFreshResearch()
{
var state = new ResearchState
{
Expand All @@ -81,8 +81,8 @@ public void StartFollowUp_PreservesDraftAndResearchButResetsReviewCycle()
state.StartFollowUp("Add a caching section.");

Assert.Equal("Add a caching section.", state.CurrentSubTask);
Assert.Equal("draft", state.Draft);
Assert.Equal(["finding"], state.ResearchFindings);
Assert.Empty(state.Draft);
Assert.Empty(state.ResearchFindings);
Assert.Empty(state.ReviewNotes);
Assert.Equal(0, state.RevisionNumber);
Assert.Empty(state.NextStep);
Expand Down
12 changes: 11 additions & 1 deletion ResearchState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public string BuildResearchQuery()
return string.Join("\n\n", parts);
}

/// <summary>Prepares an approved or revision-capped draft for a user-requested follow-up.</summary>
/// <summary>
/// Prepares a user-requested follow-up as a fresh research cycle. Any prior
/// draft or completed research is discarded so the blogger re-enters the
/// researcher stage and the refined query becomes the new source of truth.
Comment on lines +81 to +83
/// </summary>
public void StartFollowUp(string followUp)
{
ArgumentException.ThrowIfNullOrWhiteSpace(followUp);
Expand All @@ -91,6 +95,12 @@ public void StartFollowUp(string followUp)

SearchRefinements.Add(trimmed);
CurrentSubTask = trimmed;

// A refinement is a fresh research pass, not a continuation of the old
// one. Clear stale completion state so the blogger routes back to the
// researcher with the refined query instead of reusing the prior draft.
Draft = "";
ResearchFindings.Clear();
Comment on lines +102 to +103
ReviewNotes = "";
RevisionNumber = 0;
NextStep = "";
Expand Down
1 change: 1 addition & 0 deletions ResearcherAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public async Task<ResearchState> ResearchNodeAsync(ResearchState state, Cancella
? state.CurrentSubTask
: state.MainTask;

Console.WriteLine($"Researching topic: {query}");
_logger.LogInformation("Researching: {SubTask}", researchLabel);

string findings;
Expand Down