feat: refactor request types and service integration for improved runtime handling
This commit is contained in:
@@ -1,9 +1,58 @@
|
|||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import runtimeapp "cs-agent/internal/ai/runtime/app"
|
import (
|
||||||
|
"cs-agent/internal/ai/runtime/registry"
|
||||||
|
"cs-agent/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
// TODO 为什么要定义类型别名?
|
type Request struct {
|
||||||
type Request = runtimeapp.Request
|
Conversation *models.Conversation
|
||||||
type ResumeRequest = runtimeapp.ResumeRequest
|
UserMessage *models.Message
|
||||||
type InterruptContextSummary = runtimeapp.InterruptContextSummary
|
AIAgent *models.AIAgent
|
||||||
type Summary = runtimeapp.Summary
|
AIConfig *models.AIConfig
|
||||||
|
ManualSkillCode string
|
||||||
|
SelectedSkill *models.SkillDefinition
|
||||||
|
SkillRouteReason string
|
||||||
|
SkillRouteTrace string
|
||||||
|
CheckPointID string
|
||||||
|
ToolSet *registry.ToolSet
|
||||||
|
}
|
||||||
|
|
||||||
|
type ResumeRequest struct {
|
||||||
|
Conversation *models.Conversation
|
||||||
|
AIAgent *models.AIAgent
|
||||||
|
AIConfig *models.AIConfig
|
||||||
|
CheckPointID string
|
||||||
|
ResumeData map[string]any
|
||||||
|
ToolSet *registry.ToolSet
|
||||||
|
}
|
||||||
|
|
||||||
|
type InterruptContextSummary struct {
|
||||||
|
Type string `json:"type,omitempty"`
|
||||||
|
ID string `json:"id"`
|
||||||
|
InfoPreview string `json:"infoPreview,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Summary struct {
|
||||||
|
RunID string
|
||||||
|
Status string
|
||||||
|
ReplyText string
|
||||||
|
PlannedSkillCode string
|
||||||
|
PlannedSkillName string
|
||||||
|
PlanReason string
|
||||||
|
SkillRouteTrace string
|
||||||
|
SkillAllowedToolCodes []string
|
||||||
|
ModelName string
|
||||||
|
PromptTokens int
|
||||||
|
CompletionTokens int
|
||||||
|
HistoryMessageCount int
|
||||||
|
RetrieverCount int
|
||||||
|
ToolCallCount int
|
||||||
|
ToolCodes []string
|
||||||
|
InvokedToolCodes []string
|
||||||
|
CheckPointID string
|
||||||
|
Interrupted bool
|
||||||
|
Interrupts []InterruptContextSummary
|
||||||
|
TraceData string
|
||||||
|
ErrorMessage string
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,74 +3,29 @@ package app
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"cs-agent/internal/ai/runtime/internal/executor"
|
applicationruntime "cs-agent/internal/ai/application/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
runtime *executor.Service
|
app *applicationruntime.Service
|
||||||
catalog *toolCatalog
|
|
||||||
prepare *prepareService
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService() *Service {
|
func NewService() *Service {
|
||||||
catalog := newToolCatalog()
|
|
||||||
return &Service{
|
return &Service{
|
||||||
runtime: executor.NewService(),
|
app: applicationruntime.NewService(),
|
||||||
catalog: catalog,
|
|
||||||
prepare: newPrepareService(catalog),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) Run(ctx context.Context, req Request) (*Summary, error) {
|
func (s *Service) Run(ctx context.Context, req Request) (*Summary, error) {
|
||||||
selectedSkill, skillReason, skillTrace, skillErr := s.prepare.selectSkill(ctx, req)
|
if s == nil || s.app == nil {
|
||||||
req.SelectedSkill = selectedSkill
|
return nil, nil
|
||||||
req.SkillRouteReason = skillReason
|
|
||||||
req.SkillRouteTrace = skillTrace
|
|
||||||
if req.SelectedSkill != nil {
|
|
||||||
req.SelectedSkill = cloneSkillDefinition(req.SelectedSkill)
|
|
||||||
}
|
}
|
||||||
if err := s.prepare.prepareToolsForRun(&req); err != nil {
|
return s.app.Run(ctx, req)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
summary, err := s.runtime.ExecuteRun(ctx, executor.RunInput{
|
|
||||||
Conversation: req.Conversation,
|
|
||||||
UserMessage: req.UserMessage,
|
|
||||||
AIAgent: req.AIAgent,
|
|
||||||
AIConfig: req.AIConfig,
|
|
||||||
SelectedSkill: req.SelectedSkill,
|
|
||||||
SkillRouteReason: req.SkillRouteReason,
|
|
||||||
SkillRouteTrace: req.SkillRouteTrace,
|
|
||||||
CheckPointID: req.CheckPointID,
|
|
||||||
ToolSet: req.ToolSet,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ret := toSummary(summary)
|
|
||||||
if ret != nil && skillErr != nil && ret.PlanReason == "" {
|
|
||||||
ret.PlanReason = "skill_failed_fallback_runtime"
|
|
||||||
}
|
|
||||||
return ret, err
|
|
||||||
}
|
|
||||||
ret := toSummary(summary)
|
|
||||||
if ret != nil && skillErr != nil && ret.PlanReason == "" {
|
|
||||||
ret.PlanReason = "skill_failed_fallback_runtime"
|
|
||||||
}
|
|
||||||
return ret, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) Resume(ctx context.Context, req ResumeRequest) (*Summary, error) {
|
func (s *Service) Resume(ctx context.Context, req ResumeRequest) (*Summary, error) {
|
||||||
if err := s.prepare.prepareToolsForResume(&req); err != nil {
|
if s == nil || s.app == nil {
|
||||||
return nil, err
|
return nil, nil
|
||||||
}
|
}
|
||||||
summary, err := s.runtime.ExecuteResume(ctx, executor.ResumeInput{
|
return s.app.Resume(ctx, req)
|
||||||
Conversation: req.Conversation,
|
|
||||||
AIAgent: req.AIAgent,
|
|
||||||
AIConfig: req.AIConfig,
|
|
||||||
CheckPointID: req.CheckPointID,
|
|
||||||
ResumeData: req.ResumeData,
|
|
||||||
ToolSet: req.ToolSet,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return toSummary(summary), err
|
|
||||||
}
|
|
||||||
return toSummary(summary), nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,58 +1,8 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import applicationruntime "cs-agent/internal/ai/application/runtime"
|
||||||
"cs-agent/internal/ai/runtime/registry"
|
|
||||||
"cs-agent/internal/models"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Request struct {
|
type Request = applicationruntime.Request
|
||||||
Conversation *models.Conversation
|
type ResumeRequest = applicationruntime.ResumeRequest
|
||||||
UserMessage *models.Message
|
type InterruptContextSummary = applicationruntime.InterruptContextSummary
|
||||||
AIAgent *models.AIAgent
|
type Summary = applicationruntime.Summary
|
||||||
AIConfig *models.AIConfig
|
|
||||||
ManualSkillCode string
|
|
||||||
SelectedSkill *models.SkillDefinition
|
|
||||||
SkillRouteReason string
|
|
||||||
SkillRouteTrace string
|
|
||||||
CheckPointID string
|
|
||||||
ToolSet *registry.ToolSet
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResumeRequest struct {
|
|
||||||
Conversation *models.Conversation
|
|
||||||
AIAgent *models.AIAgent
|
|
||||||
AIConfig *models.AIConfig
|
|
||||||
CheckPointID string
|
|
||||||
ResumeData map[string]any
|
|
||||||
ToolSet *registry.ToolSet
|
|
||||||
}
|
|
||||||
|
|
||||||
type InterruptContextSummary struct {
|
|
||||||
Type string `json:"type,omitempty"`
|
|
||||||
ID string `json:"id"`
|
|
||||||
InfoPreview string `json:"infoPreview,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Summary struct {
|
|
||||||
RunID string
|
|
||||||
Status string
|
|
||||||
ReplyText string
|
|
||||||
PlannedSkillCode string
|
|
||||||
PlannedSkillName string
|
|
||||||
PlanReason string
|
|
||||||
SkillRouteTrace string
|
|
||||||
SkillAllowedToolCodes []string
|
|
||||||
ModelName string
|
|
||||||
PromptTokens int
|
|
||||||
CompletionTokens int
|
|
||||||
HistoryMessageCount int
|
|
||||||
RetrieverCount int
|
|
||||||
ToolCallCount int
|
|
||||||
ToolCodes []string
|
|
||||||
InvokedToolCodes []string
|
|
||||||
CheckPointID string
|
|
||||||
Interrupted bool
|
|
||||||
Interrupts []InterruptContextSummary
|
|
||||||
TraceData string
|
|
||||||
ErrorMessage string
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user