集成 ToolExecutor 到 Room

- 在 Room 结构体中添加 ToolExecutor 字段
- 在 Load 函数中初始化 ToolExecutor
This commit is contained in:
scorpio 2026-03-10 09:37:42 +08:00
parent 9a4ff4713a
commit cbbb7d399d
2 changed files with 38 additions and 32 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/sdaduanbilei/agent-team/internal/agent"
"github.com/sdaduanbilei/agent-team/internal/llm"
"github.com/sdaduanbilei/agent-team/internal/prompt"
"github.com/sdaduanbilei/agent-team/internal/room/tools"
"github.com/sdaduanbilei/agent-team/internal/skill"
"github.com/sdaduanbilei/agent-team/internal/store"
)
@ -33,6 +34,8 @@ func Load(roomDir string, agentsDir string, skillsDir string, opts ...LoadOption
r := &Room{Config: cfg, Dir: roomDir, members: make(map[string]*agent.Agent), Mode: "plan", Status: StatusPending}
r.ToolExecutor = tools.NewExecutor(filepath.Join(roomDir, "workspace"))
projectRoot := filepath.Dir(agentsDir)
if data, err := os.ReadFile(filepath.Join(projectRoot, "SYSTEM.md")); err == nil {
r.systemRules = string(data)
@ -591,7 +594,7 @@ func (r *Room) masterCallerDecidedIteration(ctx context.Context, masterMsgs *[]l
"Results": resultsStr.String(),
"BoardContext": board.ToContext(),
"WorkspaceContext": r.buildWorkspaceContext(),
"WorkflowStep": r.buildWorkflowStep(),
"WorkflowStep": r.buildWorkflowStep(),
})
feedbackLLMMsg := llm.NewMsg("user", feedbackMsg)

View File

@ -10,6 +10,7 @@ import (
"github.com/sdaduanbilei/agent-team/internal/agent"
"github.com/sdaduanbilei/agent-team/internal/llm"
"github.com/sdaduanbilei/agent-team/internal/prompt"
"github.com/sdaduanbilei/agent-team/internal/room/tools"
"github.com/sdaduanbilei/agent-team/internal/skill"
"github.com/sdaduanbilei/agent-team/internal/store"
"github.com/sdaduanbilei/agent-team/internal/user"
@ -39,15 +40,15 @@ type Config struct {
}
type Room struct {
Config Config
Dir string
master *agent.Agent
members map[string]*agent.Agent
skillMeta []skill.Meta
User *user.User
Status Status
ActiveAgent string // for working status display
Broadcast func(Event) // set by api layer
Config Config
Dir string
master *agent.Agent
members map[string]*agent.Agent
skillMeta []skill.Meta
User *user.User
Status Status
ActiveAgent string // for working status display
Broadcast func(Event) // set by api layer
// master 的会话历史,保持多轮对话上下文
masterHistory []llm.Message
@ -71,6 +72,8 @@ type Room struct {
Store *store.Store
currentGroupID int64 // 当前用户消息的 group_id
ToolExecutor *tools.Executor
cancelFunc func()
cancelMu sync.Mutex
}
@ -90,31 +93,31 @@ const (
EvtScheduleRun EventType = "schedule_run"
EvtTokenUsage EventType = "token_usage"
EvtFileRead EventType = "file_read"
EvtFileWorking EventType = "file_working" // file-llm 开始生成文件
EvtFileDone EventType = "file_done" // file-llm 文件生成完成
EvtFileWorking EventType = "file_working" // file-llm 开始生成文件
EvtFileDone EventType = "file_done" // file-llm 文件生成完成
)
type Event struct {
Type EventType `json:"type"`
RoomID string `json:"room_id"`
Agent string `json:"agent,omitempty"`
Role string `json:"role,omitempty"` // master | member | challenge
Content string `json:"content,omitempty"`
Streaming bool `json:"streaming,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
Task string `json:"task,omitempty"`
Feedback string `json:"feedback,omitempty"`
Status Status `json:"status,omitempty"`
ActiveAgent string `json:"active_agent,omitempty"`
Action string `json:"action,omitempty"`
Filename string `json:"filename,omitempty"`
Mode string `json:"mode,omitempty"`
Title string `json:"title,omitempty"`
PromptTokens int `json:"prompt_tokens,omitempty"`
CompletionTokens int `json:"completion_tokens,omitempty"`
TotalTokens int `json:"total_tokens,omitempty"`
NoStore bool `json:"-"` // 跳过 emit 中的自动 DB 存储(调用方已显式存储)
Type EventType `json:"type"`
RoomID string `json:"room_id"`
Agent string `json:"agent,omitempty"`
Role string `json:"role,omitempty"` // master | member | challenge
Content string `json:"content,omitempty"`
Streaming bool `json:"streaming,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
Task string `json:"task,omitempty"`
Feedback string `json:"feedback,omitempty"`
Status Status `json:"status,omitempty"`
ActiveAgent string `json:"active_agent,omitempty"`
Action string `json:"action,omitempty"`
Filename string `json:"filename,omitempty"`
Mode string `json:"mode,omitempty"`
Title string `json:"title,omitempty"`
PromptTokens int `json:"prompt_tokens,omitempty"`
CompletionTokens int `json:"completion_tokens,omitempty"`
TotalTokens int `json:"total_tokens,omitempty"`
NoStore bool `json:"-"` // 跳过 emit 中的自动 DB 存储(调用方已显式存储)
}
// ProjectFile 项目模板中的单个文件