refactor: Agent驱动重构,整章写入替代场景拼接

This commit is contained in:
voocel
2026-03-15 14:14:46 +08:00
parent 25e219e934
commit 568ef0b1d1
27 changed files with 942 additions and 568 deletions

View File

@@ -18,6 +18,7 @@ func BuildCoordinator(
) (*agentcore.Agent, *tools.AskUserTool) {
// 共享工具
contextTool := tools.NewContextTool(store, refs, cfg.Style)
readChapter := tools.NewReadChapterTool(store)
askUser := tools.NewAskUserTool()
// Architect SubAgent 工具
@@ -26,19 +27,20 @@ func BuildCoordinator(
tools.NewSaveFoundationTool(store),
}
// Writer SubAgent 工具V1: +polish_chapter +check_consistency
// Writer SubAgent 工具:读写 + 规划 + 一致性检查 + 提交
writerTools := []agentcore.Tool{
contextTool,
readChapter,
tools.NewPlanChapterTool(store),
tools.NewWriteSceneTool(store),
tools.NewPolishChapterTool(store),
tools.NewDraftChapterTool(store),
tools.NewCheckConsistencyTool(store),
tools.NewCommitChapterTool(store),
}
// Editor SubAgent 工具
// Editor SubAgent 工具:读原文 + 审阅 + 摘要
editorTools := []agentcore.Tool{
contextTool,
readChapter,
tools.NewSaveReviewTool(store),
tools.NewSaveArcSummaryTool(store),
tools.NewSaveVolumeSummaryTool(store),
@@ -79,16 +81,16 @@ func BuildCoordinator(
writer := agentcore.SubAgentConfig{
Name: "writer",
Description: "场景写作者:逐场景完成一章的创作,包含打磨和一致性检查",
Description: "创作者:自主完成一章的构思、写作、自审和提交",
Model: model,
SystemPrompt: writerPrompt,
Tools: writerTools,
MaxTurns: 25,
MaxTurns: 20,
}
editor := agentcore.SubAgentConfig{
Name: "editor",
Description: "全局审阅者:发现跨章结构问题,输出审阅结果",
Description: "审阅者:阅读原文,从结构和审美两个层面发现问题",
Model: model,
SystemPrompt: prompts.Editor,
Tools: editorTools,

View File

@@ -283,12 +283,11 @@ func determineRecovery(progress *domain.Progress, runMeta *domain.RunMeta) recov
if progress.InProgressChapter > 0 {
ch := progress.InProgressChapter
scenes := len(progress.CompletedScenes)
return recoveryResult{
PromptText: withGuidance(fmt.Sprintf(
"第 %d 章正在进行中,已完成 %d 个场景。请调用 writer 从场景 %d 继续写作。总共需要写 %d 章。",
ch, scenes, scenes+1, progress.TotalChapters)),
Label: fmt.Sprintf("场景级恢复:第 %d 章已完成 %d 个场景", ch, scenes),
"第 %d 章正在进行中,已有部分草稿。请调用 writer 继续完成该章(可用 read_chapter 读取已有草稿)。总共需要写 %d 章。",
ch, progress.TotalChapters)),
Label: fmt.Sprintf("恢复:第 %d 章进行中", ch),
}
}
@@ -348,17 +347,29 @@ func handleSubAgentDone(coordinator *agentcore.Agent, store *state.Store, emit e
log.Printf("[host] 清除 commit 信号失败: %v", err)
}
log.Printf("[host] 章节提交信号:第 %d 章,%d 字%d 个场景",
result.Chapter, result.WordCount, result.SceneCount)
log.Printf("[host] 章节提交信号:第 %d 章,%d 字",
result.Chapter, result.WordCount)
if emit != nil {
emit(UIEvent{
Time: time.Now(),
Category: "SYSTEM",
Summary: fmt.Sprintf("第 %d 章已提交:%d 字%d 个场景", result.Chapter, result.WordCount, result.SceneCount),
Summary: fmt.Sprintf("第 %d 章已提交:%d 字", result.Chapter, result.WordCount),
Level: "success",
})
}
// outline_feedback 处理Writer 反馈大纲偏离
if result.Feedback != nil && result.Feedback.Deviation != "" {
log.Printf("[host] outline_feedback: %s", result.Feedback.Deviation)
if emit != nil {
emit(UIEvent{Time: time.Now(), Category: "SYSTEM",
Summary: "Writer 反馈大纲偏离: " + truncateLog(result.Feedback.Deviation, 60), Level: "info"})
}
coordinator.FollowUp(agentcore.UserMsg(fmt.Sprintf(
"[系统] Writer 在第 %d 章写作中发现大纲偏离。偏离:%s。建议%s。请评估是否需要调整后续大纲。",
result.Chapter, result.Feedback.Deviation, result.Feedback.Suggestion)))
}
// 确定性判断 0正在重写/打磨流程中
progress, _ := store.LoadProgress()
if progress != nil && (progress.Flow == domain.FlowRewriting || progress.Flow == domain.FlowPolishing) {

View File

@@ -37,7 +37,6 @@ type UISnapshot struct {
CompletedCount int
TotalWordCount int
InProgressChapter int
CompletedScenes int
PendingRewrites []int
RewriteReason string
PendingSteer string
@@ -272,7 +271,6 @@ func (rt *Runtime) Snapshot() UISnapshot {
snap.CompletedCount = len(progress.CompletedChapters)
snap.TotalWordCount = progress.TotalWordCount
snap.InProgressChapter = progress.InProgressChapter
snap.CompletedScenes = len(progress.CompletedScenes)
snap.PendingRewrites = progress.PendingRewrites
snap.RewriteReason = progress.RewriteReason
}