42077c1aab
- Removed the selectSkill method from prepareService and adjusted related logic in the Run method of Service. - Updated tool catalog to parse agent allowed tool codes directly. - Simplified Request and RunInput structures by removing unnecessary fields. - Enhanced the RuntimeTraceCollector to manage skill activation and visibility. - Introduced a new databaseSkillBackend to manage skill definitions and their metadata. - Added tests for skill backend functionalities to ensure correct behavior. - Updated various factory methods to accommodate changes in skill handling. - Improved documentation and descriptions for better clarity.
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package runtime
|
|
|
|
import (
|
|
"context"
|
|
|
|
"cs-agent/internal/ai/runtime/executor"
|
|
"cs-agent/internal/pkg/utils"
|
|
)
|
|
|
|
type Service struct {
|
|
runtime *executor.Service
|
|
catalog *toolCatalog
|
|
prepare *prepareService
|
|
}
|
|
|
|
func NewService() *Service {
|
|
catalog := newToolCatalog()
|
|
return &Service{
|
|
runtime: executor.NewService(),
|
|
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
|
|
}
|
|
req.UserMessage.Content = utils.BuildRuntimeMessageText(req.UserMessage.MessageType, req.UserMessage.Content)
|
|
if err := s.prepare.prepareToolsForRun(&req); err != nil {
|
|
return nil, err
|
|
}
|
|
summary, err := s.runtime.ExecuteRun(ctx, executor.RunInput{
|
|
Conversation: req.Conversation,
|
|
UserMessage: req.UserMessage,
|
|
AIAgent: req.AIAgent,
|
|
AIConfig: req.AIConfig,
|
|
CheckPointID: req.CheckPointID,
|
|
ToolSet: req.ToolSet,
|
|
})
|
|
if err != nil {
|
|
return toSummary(summary), err
|
|
}
|
|
return toSummary(summary), 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, executor.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
|
|
}
|