Files
ainovel-clients/app/agents.go
voocel 27bd85ef90 init
2026-03-07 21:25:55 +08:00

85 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package app
import (
"github.com/voocel/agentcore"
"github.com/voocel/ainovel-cli/state"
"github.com/voocel/ainovel-cli/tools"
)
// BuildCoordinator 组装 Coordinator Agent 及其 SubAgent。
func BuildCoordinator(
cfg Config,
store *state.Store,
model agentcore.ChatModel,
refs tools.References,
prompts Prompts,
styles map[string]string,
) *agentcore.Agent {
// 共享工具
contextTool := tools.NewContextTool(store, refs, cfg.Style)
// Architect SubAgent 工具
architectTools := []agentcore.Tool{
contextTool,
tools.NewSaveFoundationTool(store),
}
// Writer SubAgent 工具V1: +polish_chapter +check_consistency
writerTools := []agentcore.Tool{
contextTool,
tools.NewPlanChapterTool(store),
tools.NewWriteSceneTool(store),
tools.NewPolishChapterTool(store),
tools.NewCheckConsistencyTool(store),
tools.NewCommitChapterTool(store),
}
// Editor SubAgent 工具V1
editorTools := []agentcore.Tool{
contextTool,
tools.NewSaveReviewTool(store),
}
architect := agentcore.SubAgentConfig{
Name: "architect",
Description: "世界构建师:生成小说前提、大纲和角色档案",
Model: model,
SystemPrompt: prompts.Architect,
Tools: architectTools,
MaxTurns: 10,
}
// 动态拼接风格指令到 Writer prompt
writerPrompt := prompts.Writer
if style, ok := styles[cfg.Style]; ok {
writerPrompt += "\n\n" + style
}
writer := agentcore.SubAgentConfig{
Name: "writer",
Description: "场景写作者:逐场景完成一章的创作,包含打磨和一致性检查",
Model: model,
SystemPrompt: writerPrompt,
Tools: writerTools,
MaxTurns: 25,
}
editor := agentcore.SubAgentConfig{
Name: "editor",
Description: "全局审阅者:发现跨章结构问题,输出审阅结果",
Model: model,
SystemPrompt: prompts.Editor,
Tools: editorTools,
MaxTurns: 10,
}
subagentTool := agentcore.NewSubAgentTool(architect, writer, editor)
return agentcore.NewAgent(
agentcore.WithModel(model),
agentcore.WithSystemPrompt(prompts.Coordinator),
agentcore.WithTools(subagentTool, contextTool),
agentcore.WithMaxTurns(60),
)
}