diff --git a/backend/ai-core/internal/model/sub_session.go b/backend/ai-core/internal/model/sub_session.go index 60d513f..4222611 100644 --- a/backend/ai-core/internal/model/sub_session.go +++ b/backend/ai-core/internal/model/sub_session.go @@ -49,7 +49,9 @@ type SubSessionResult struct { Confidence float64 `json:"confidence"` // 置信度 0-1 Progress float64 `json:"progress"` // 执行进度 0.0 ~ 1.0 Error string `json:"error,omitempty"` - Metadata map[string]any `json:"metadata"` // 类型特定的元数据 + Metadata map[string]any `json:"metadata"` // 类型特定的元数据 + CreatedAt time.Time `json:"created_at"` // 任务创建时间 + FinishedAt time.Time `json:"finished_at"` // 任务结束时间 } // ToolCallRecord 工具调用记录 diff --git a/backend/ai-core/internal/subsession/manager.go b/backend/ai-core/internal/subsession/manager.go index 0f5de25..1c11eba 100644 --- a/backend/ai-core/internal/subsession/manager.go +++ b/backend/ai-core/internal/subsession/manager.go @@ -6,6 +6,7 @@ import ( "fmt" "git.yeij.top/AskaEth/Cyrene/pkg/logger" "sync" + "time" "git.yeij.top/AskaEth/Cyrene/ai-core/internal/bus" "git.yeij.top/AskaEth/Cyrene/ai-core/internal/llm" @@ -109,7 +110,8 @@ func (m *Manager) Dispatch( } }() - result := model.SubSessionResult{Type: p.Type()} + createdAt := time.Now() + result := model.SubSessionResult{Type: p.Type(), CreatedAt: createdAt} m.getBus().Publish(bus.BusEvent{ Type: bus.EventSubSessionStarted, Payload: bus.SubSessionPayload{SubType: p.Type(), Status: "started"}, @@ -125,7 +127,8 @@ func (m *Manager) Dispatch( if err != nil { result.Error = fmt.Sprintf("创建上下文失败: %v", err) logger.Printf("[subsession] %s 创建上下文失败: %v", p.Type(), err) - resultCh <- result + result.FinishedAt = time.Now() + resultCh <- result return } @@ -134,6 +137,7 @@ func (m *Manager) Dispatch( // 执行子会话 subResult, execErr := p.Execute(subCtx, llmMessages) if execErr != nil { + result.FinishedAt = time.Now() result.Error = fmt.Sprintf("执行失败: %v", execErr) logger.Printf("[subsession] %s 执行失败: %v", p.Type(), execErr) resultCh <- result @@ -143,12 +147,14 @@ func (m *Manager) Dispatch( // 检查超时 select { case <-subCtx.Done(): + result.FinishedAt = time.Now() result.Error = "子会话超时" logger.Printf("[subsession] %s 超时 (limit=%v)", p.Type(), p.Timeout()) default: if subResult != nil { result = *subResult result.Type = p.Type() + result.CreatedAt = createdAt logger.Printf("[subsession] %s 完成: 摘要=%s", p.Type(), truncate(result.Summary, 50)) } }