Files
ai-agent/internal/ai/application/runtime/service.go
T
mlogclub 164121836d Refactor runtime executor integration and introduce eino package
- Replaced the existing runtime executor with a new eino package for better modularity.
- Updated Service struct to use the new RuntimeExecutor from eino.
- Adjusted Run and Resume methods to accommodate changes in input types and execution logic.
- Introduced new types in the eino package to align with the previous executor's functionality.
- Refactored tooling preparation logic to streamline tool definitions and improve clarity.
- Added new context builders and event consumers to enhance runtime event handling.
- Removed legacy executor code and ensured all references are updated to the new eino package.
2026-04-14 09:33:49 +08:00

83 lines
2.2 KiB
Go

package runtime
import (
"context"
runtimeeino "cs-agent/internal/ai/infra/eino"
)
type Service struct {
runtime *runtimeeino.RuntimeExecutor
catalog *toolCatalog
prepare *prepareService
}
func NewService() *Service {
catalog := newToolCatalog()
return &Service{
runtime: runtimeeino.NewRuntimeExecutor(),
catalog: catalog,
prepare: newPrepareService(catalog),
}
}
func (s *Service) Run(ctx context.Context, req Request) (*Summary, error) {
if s == nil || s.runtime == nil || s.prepare == nil {
return nil, nil
}
selectedSkill, skillReason, skillTrace, skillErr := s.prepare.selectSkill(ctx, req)
req.SelectedSkill = selectedSkill
req.SkillRouteReason = skillReason
req.SkillRouteTrace = skillTrace
if req.SelectedSkill != nil {
req.SelectedSkill = cloneSkillDefinition(req.SelectedSkill)
}
if err := s.prepare.prepareToolsForRun(&req); err != nil {
return nil, err
}
summary, err := s.runtime.ExecuteRun(ctx, runtimeeino.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) {
if s == nil || s.runtime == nil || s.prepare == nil {
return nil, nil
}
if err := s.prepare.prepareToolsForResume(&req); err != nil {
return nil, err
}
summary, err := s.runtime.ExecuteResume(ctx, runtimeeino.ResumeInput{
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
}