Refactor AI Agent and AI Config handling across multiple files
- Updated function signatures to accept AI Agent and AI Config as non-pointer types for better clarity and safety. - Modified instances where AI Agent and AI Config were dereferenced to improve code readability. - Removed unnecessary nil checks for AI Agent and AI Config, simplifying the logic. - Adjusted related tests and services to align with the new function signatures. - Cleaned up code in runtime, skills, and executor packages to ensure consistency in handling AI configurations.
This commit is contained in:
@@ -18,7 +18,7 @@ type prepareService struct {
|
||||
}
|
||||
|
||||
func (s *prepareService) selectSkill(ctx context.Context, req Request) (*models.SkillDefinition, string, string, error) {
|
||||
if req.AIAgent == nil || req.AIConfig == nil || req.UserMessage == nil || req.Conversation == nil {
|
||||
if req.UserMessage == nil || req.Conversation == nil {
|
||||
return nil, "", "", nil
|
||||
}
|
||||
result, err := skills.Select(ctx, skills.RuntimeContext{
|
||||
|
||||
@@ -72,10 +72,7 @@ func (c *toolCatalog) parseSkillAllowedToolCodes(skill *models.SkillDefinition)
|
||||
return toolx.NormalizeToolCodes(items)
|
||||
}
|
||||
|
||||
func (c *toolCatalog) parseAgentAllowedToolCodes(aiAgent *models.AIAgent) []string {
|
||||
if aiAgent == nil {
|
||||
return nil
|
||||
}
|
||||
func (c *toolCatalog) parseAgentAllowedToolCodes(aiAgent models.AIAgent) []string {
|
||||
ret := make([]string, 0)
|
||||
if raw := strings.TrimSpace(aiAgent.AllowedMCPTools); raw != "" {
|
||||
items, err := toolx.ParseAgentMCPToolsJSON(raw)
|
||||
@@ -94,6 +91,6 @@ func (c *toolCatalog) parseAgentAllowedToolCodes(aiAgent *models.AIAgent) []stri
|
||||
return toolx.NormalizeToolCodes(ret)
|
||||
}
|
||||
|
||||
func (c *toolCatalog) resolveAllowedToolCodes(aiAgent *models.AIAgent, skill *models.SkillDefinition) []string {
|
||||
func (c *toolCatalog) resolveAllowedToolCodes(aiAgent models.AIAgent, skill *models.SkillDefinition) []string {
|
||||
return toolx.IntersectToolCodes(c.parseAgentAllowedToolCodes(aiAgent), c.parseSkillAllowedToolCodes(skill))
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestNormalizeAllowedToolCodes(t *testing.T) {
|
||||
|
||||
func TestToolCatalogResolveAllowedToolCodes(t *testing.T) {
|
||||
catalog := newToolCatalog()
|
||||
agent := &models.AIAgent{
|
||||
agent := models.AIAgent{
|
||||
AllowedMCPTools: `[{"toolCode":"graph/create_ticket_with_confirmation"},{"toolCode":"graph/handoff_to_human"}]`,
|
||||
}
|
||||
skill := &models.SkillDefinition{
|
||||
@@ -45,7 +45,7 @@ func TestToolCatalogResolveAllowedToolCodes(t *testing.T) {
|
||||
|
||||
func TestToolCatalogResolveAllowedToolCodesFallsBackWhenSkillEmpty(t *testing.T) {
|
||||
catalog := newToolCatalog()
|
||||
agent := &models.AIAgent{
|
||||
agent := models.AIAgent{
|
||||
AllowedMCPTools: `[{"toolCode":"graph/create_ticket_with_confirmation"},{"toolCode":"graph/handoff_to_human"}]`,
|
||||
}
|
||||
ret := catalog.resolveAllowedToolCodes(agent, nil)
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
type Request struct {
|
||||
Conversation *models.Conversation
|
||||
UserMessage *models.Message
|
||||
AIAgent *models.AIAgent
|
||||
AIConfig *models.AIConfig
|
||||
AIAgent models.AIAgent
|
||||
AIConfig models.AIConfig
|
||||
ManualSkillCode string
|
||||
SelectedSkill *models.SkillDefinition
|
||||
SkillRouteReason string
|
||||
@@ -20,8 +20,8 @@ type Request struct {
|
||||
|
||||
type ResumeRequest struct {
|
||||
Conversation *models.Conversation
|
||||
AIAgent *models.AIAgent
|
||||
AIConfig *models.AIConfig
|
||||
AIAgent models.AIAgent
|
||||
AIConfig models.AIConfig
|
||||
CheckPointID string
|
||||
ResumeData map[string]string
|
||||
ToolSet *registry.ToolSet
|
||||
|
||||
Reference in New Issue
Block a user