diff --git a/internal/ai/runtime/internal/impl/callbacks/runlog_callback.go b/internal/ai/runtime/internal/impl/callbacks/runlog_callback.go index 9aeb47e..ee01ac3 100644 --- a/internal/ai/runtime/internal/impl/callbacks/runlog_callback.go +++ b/internal/ai/runtime/internal/impl/callbacks/runlog_callback.go @@ -18,9 +18,6 @@ func NewRuntimeTraceCollector() *RuntimeTraceCollector { } func (c *RuntimeTraceCollector) Marshal() string { - if c == nil { - return "" - } c.mu.Lock() defer c.mu.Unlock() buf, err := json.Marshal(c.Data) @@ -31,9 +28,6 @@ func (c *RuntimeTraceCollector) Marshal() string { } func (c *RuntimeTraceCollector) SetTooling(staticToolCodes []string, dynamicToolCodes []string, toolSearchEnabled bool) { - if c == nil { - return - } c.mu.Lock() defer c.mu.Unlock() c.Data.Input.StaticToolCodes = append([]string(nil), staticToolCodes...) @@ -42,9 +36,6 @@ func (c *RuntimeTraceCollector) SetTooling(staticToolCodes []string, dynamicTool } func (c *RuntimeTraceCollector) SetInstructionSummary(summary InstructionTraceSummary) { - if c == nil { - return - } c.mu.Lock() defer c.mu.Unlock() c.Data.Instruction.SectionTitles = append([]string(nil), summary.SectionTitles...) @@ -54,9 +45,6 @@ func (c *RuntimeTraceCollector) SetInstructionSummary(summary InstructionTraceSu } func (c *RuntimeTraceCollector) SetSkillMiddleware(enabled bool, toolName string) { - if c == nil { - return - } c.mu.Lock() defer c.mu.Unlock() c.Data.Skill.MiddlewareEnabled = enabled @@ -71,7 +59,7 @@ type SkillMetadata struct { } func (c *RuntimeTraceCollector) SetVisibleSkills(skills map[string]SkillMetadata) { - if c == nil || len(skills) == 0 { + if len(skills) == 0 { return } c.mu.Lock() @@ -87,9 +75,6 @@ func (c *RuntimeTraceCollector) SetVisibleSkills(skills map[string]SkillMetadata } func (c *RuntimeTraceCollector) ActivateSkill(skill SkillMetadata, routeReason string, routeTrace string) { - if c == nil { - return - } c.mu.Lock() defer c.mu.Unlock() c.Data.Skill.Code = skill.Code @@ -101,18 +86,12 @@ func (c *RuntimeTraceCollector) ActivateSkill(skill SkillMetadata, routeReason s } func (c *RuntimeTraceCollector) SetFilteredToolCodes(toolCodes []string) { - if c == nil { - return - } c.mu.Lock() defer c.mu.Unlock() c.Data.Skill.FilteredToolCodes = append([]string(nil), toolCodes...) } func (c *RuntimeTraceCollector) SetRetrieverSummary(summary RetrieverTraceSummary) { - if c == nil { - return - } c.mu.Lock() defer c.mu.Unlock() c.Data.Retriever.TopK = summary.TopK @@ -128,9 +107,6 @@ func (c *RuntimeTraceCollector) SetRetrieverSummary(summary RetrieverTraceSummar } func (c *RuntimeTraceCollector) AddToolItem(item ToolTraceItem) { - if c == nil { - return - } c.mu.Lock() defer c.mu.Unlock() c.Data.Tools.Count++ @@ -138,9 +114,6 @@ func (c *RuntimeTraceCollector) AddToolItem(item ToolTraceItem) { } func (c *RuntimeTraceCollector) AddToolSearchItem(item ToolSearchTraceItem) { - if c == nil { - return - } c.mu.Lock() defer c.mu.Unlock() c.Data.ToolSearch.Count++ @@ -148,9 +121,6 @@ func (c *RuntimeTraceCollector) AddToolSearchItem(item ToolSearchTraceItem) { } func (c *RuntimeTraceCollector) AddGraphToolItem(item GraphToolTraceItem) { - if c == nil { - return - } c.mu.Lock() defer c.mu.Unlock() c.Data.GraphTools.Count++ diff --git a/internal/ai/runtime/internal/impl/factory/agent_factory.go b/internal/ai/runtime/internal/impl/factory/agent_factory.go index dc89c38..132b428 100644 --- a/internal/ai/runtime/internal/impl/factory/agent_factory.go +++ b/internal/ai/runtime/internal/impl/factory/agent_factory.go @@ -55,7 +55,7 @@ func NewAgentFactory() *AgentFactory { chatModelFactory: NewChatModelFactory(), toolFactory: NewToolFactory(), instructionService: instruction.NewService(nil, nil, nil), - handlerService: NewAgentHandlerService(nil), + handlerService: NewAgentHandlerService(NewSkillMiddlewareService()), } } @@ -73,21 +73,19 @@ func (f *AgentFactory) BuildCustomerServiceAgent(ctx context.Context, input Buil allTools = append(allTools, input.StaticTools...) instructionResult := f.instructionService.Build(input.AIAgent, nil, input.InstructionToolDefinitions, input.StaticToolCodes) handlers := make([]adk.ChatModelAgentMiddleware, 0, 3) - if f.handlerService != nil { - builtHandlers, err := f.handlerService.Build(ctx, BuildAgentHandlersInput{ - AIAgent: input.AIAgent, - InstructionToolDefinitions: input.InstructionToolDefinitions, - DynamicToolDefinitions: input.DynamicMCPToolDefinitions, - DynamicTools: dynamicTools, - StaticToolMetadata: input.StaticToolMetadata, - Collector: input.Collector, - InstructionSummary: buildInstructionTraceSummary(instructionResult.Summary), - }) - if err != nil { - return nil, err - } - handlers = append(handlers, builtHandlers...) + builtHandlers, err := f.handlerService.Build(ctx, BuildAgentHandlersInput{ + AIAgent: input.AIAgent, + InstructionToolDefinitions: input.InstructionToolDefinitions, + DynamicToolDefinitions: input.DynamicMCPToolDefinitions, + DynamicTools: dynamicTools, + StaticToolMetadata: input.StaticToolMetadata, + Collector: input.Collector, + InstructionSummary: buildInstructionTraceSummary(instructionResult.Summary), + }) + if err != nil { + return nil, err } + handlers = append(handlers, builtHandlers...) inner, err := adk.NewChatModelAgent(ctx, &adk.ChatModelAgentConfig{ Name: strings.TrimSpace(input.AIAgent.Name), Description: strings.TrimSpace(input.AIAgent.Description), diff --git a/internal/ai/runtime/internal/impl/factory/agent_handler_service.go b/internal/ai/runtime/internal/impl/factory/agent_handler_service.go index 5783b33..8138342 100644 --- a/internal/ai/runtime/internal/impl/factory/agent_handler_service.go +++ b/internal/ai/runtime/internal/impl/factory/agent_handler_service.go @@ -31,7 +31,7 @@ type BuildAgentHandlersInput struct { func NewAgentHandlerService(skillMiddleware *SkillMiddlewareService) *AgentHandlerService { if skillMiddleware == nil { - skillMiddleware = NewSkillMiddlewareService() + panic("skill middleware is required") } return &AgentHandlerService{skillMiddleware: skillMiddleware} } diff --git a/internal/ai/runtime/internal/impl/factory/agent_handler_service_test.go b/internal/ai/runtime/internal/impl/factory/agent_handler_service_test.go index e607634..ea4e9d9 100644 --- a/internal/ai/runtime/internal/impl/factory/agent_handler_service_test.go +++ b/internal/ai/runtime/internal/impl/factory/agent_handler_service_test.go @@ -9,7 +9,7 @@ import ( func TestAgentHandlerServiceBuildWithCollectorOnly(t *testing.T) { collector := einocallbacks.NewRuntimeTraceCollector() - service := NewAgentHandlerService(nil) + service := NewAgentHandlerService(NewSkillMiddlewareService()) handlers, err := service.Build(context.Background(), BuildAgentHandlersInput{ Collector: collector, @@ -33,7 +33,7 @@ func TestAgentHandlerServiceBuildWithCollectorOnly(t *testing.T) { } func TestAgentHandlerServiceBuildWithEmptyInput(t *testing.T) { - service := NewAgentHandlerService(nil) + service := NewAgentHandlerService(NewSkillMiddlewareService()) handlers, err := service.Build(context.Background(), BuildAgentHandlersInput{}) if err != nil { diff --git a/internal/ai/runtime/reply_interrupt_service.go b/internal/ai/runtime/reply_interrupt_service.go index 99073be..51618b4 100644 --- a/internal/ai/runtime/reply_interrupt_service.go +++ b/internal/ai/runtime/reply_interrupt_service.go @@ -2,6 +2,7 @@ package runtime import ( "context" + "fmt" "strings" applicationruntime "cs-agent/internal/ai/application/runtime" @@ -16,8 +17,8 @@ func newReplyInterruptService() *replyInterruptService { } func (s *replyInterruptService) ResumePendingInterrupt(ctx context.Context, owner *aiReplyService, replyCtx aiReplyContext) error { - if replyCtx.PendingInterrupt == nil || owner == nil { - return nil + if replyCtx.PendingInterrupt == nil { + return fmt.Errorf("pending interrupt is required") } summary, err := owner.executor.ResumePendingInterrupt(ctx, runtimeReplyResumeInput{ Conversation: replyCtx.Conversation, @@ -83,9 +84,6 @@ func (s *replyInterruptService) ResumePendingInterrupt(ctx context.Context, owne } func (s *replyInterruptService) HandleInterruptedSummary(owner *aiReplyService, replyCtx aiReplyContext, summary *applicationruntime.Summary) error { - if owner == nil { - return nil - } pending := buildConversationInterrupt(replyCtx.Conversation, replyCtx.Message, replyCtx.AIAgent, summary) if err := svc.ConversationInterruptService.CreateOrUpdatePending(pending); err != nil { return err @@ -110,8 +108,8 @@ func (s *replyInterruptService) HandleInterruptedSummary(owner *aiReplyService, } func (s *replyInterruptService) HandleInterruptedResume(owner *aiReplyService, replyCtx aiReplyContext, summary *applicationruntime.Summary) error { - if replyCtx.PendingInterrupt == nil || owner == nil { - return nil + if replyCtx.PendingInterrupt == nil { + return fmt.Errorf("pending interrupt is required") } replyText := resolveInterruptPrompt(summary) replyMessage, err := owner.commit.CommitAIReply(replyCommitInput{ diff --git a/internal/ai/runtime/runtime_reply_executor.go b/internal/ai/runtime/runtime_reply_executor.go index 9143812..e876324 100644 --- a/internal/ai/runtime/runtime_reply_executor.go +++ b/internal/ai/runtime/runtime_reply_executor.go @@ -55,7 +55,7 @@ func (e *runtimeReplyExecutor) Run(ctx context.Context, input runtimeReplyRunInp func (e *runtimeReplyExecutor) ResumePendingInterrupt(ctx context.Context, input runtimeReplyResumeInput) (*applicationruntime.Summary, error) { if input.PendingInterrupt == nil { - return nil, nil + return nil, fmt.Errorf("pending interrupt is required") } aiConfig := svc.AIConfigService.Get(input.AIAgent.AIConfigID) if aiConfig == nil {