Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions ai/component/agent/agent.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
type: agent
spec:
agent_type: "react"
model: "dashscope/qwen3.7-max"
model: "dashscope/qwen3.5-plus"
prompt_base_path: "./prompts"
max_iterations: 3 # Reduced from 10 to 3 for faster response
stage_channel_buffer_size: 5
mcp_host_name: "mcp_host"
prompt_file: "agentReasonAct.txt"
max_iterations: 3 # bounded reason-act loop; the last iteration forces an answer (effective tool rounds = max_iterations - 1)
channel_buffer_size: 5

# Model sampling + per model-call timeout (seconds).
temperature: 0.7
top_p: 0.9
max_tokens: 3000
timeout: 90

# Per-tool timeout overrides (seconds), keyed by tool name. Tools without an
# override use a built-in 30s default. A failed/timed-out tool no longer aborts
# the interaction; its error is passed to the observe stage to degrade.
# the interaction; its error is recorded as the tool's output so the model can
# still answer from whatever else returned.
# tool_timeouts:
# get_service_detail: 15
# mcp_log: 60

stages:
- name: "reasonAct"
flow_type: "reasonAct"
prompt_file: "agentReasonAct.txt"
temperature: 0.7
top_p: 0.9
max_tokens: 3000
timeout: 90
enable_tools: true

- name: "observe"
flow_type: "observe"
prompt_file: "agentObserve.txt"
temperature: 0.7
top_p: 0.9
max_tokens: 2000
timeout: 30 # Reduced from 60 to 30 for faster timeout fallback
enable_tools: false
157 changes: 0 additions & 157 deletions ai/component/agent/fallback/handler.go

This file was deleted.

62 changes: 13 additions & 49 deletions ai/component/agent/react/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,15 @@ import (
// the agent's YAML-sourced configuration and, on Init, resolves dependencies
// (tools) and constructs the underlying ReActAgent.
type AgentComponent struct {
instanceName string
Agent *ReActAgent
agentType string
model string
promptBasePath string
maxIterations int
stageChannelBufferSize int
mcpHostName string
toolTimeouts map[string]int
stages []StageInfo
instanceName string
Agent *ReActAgent
spec AgentSpec
}

// NewAgentComponent builds an unstarted AgentComponent from resolved
// configuration values. The ReActAgent itself is created later, in Init.
func NewAgentComponent(
agentType string,
model string,
promptBasePath string,
maxIterations int,
stageChannelBufferSize int,
mcpHostName string,
toolTimeouts map[string]int,
stages []StageInfo,
) (runtime.Component, error) {
return &AgentComponent{
agentType: agentType,
model: model,
promptBasePath: promptBasePath,
maxIterations: maxIterations,
stageChannelBufferSize: stageChannelBufferSize,
mcpHostName: mcpHostName,
toolTimeouts: toolTimeouts,
stages: stages,
}, nil
// NewAgentComponent builds an unstarted AgentComponent from a decoded spec. The
// ReActAgent itself is created later, in Init.
func NewAgentComponent(spec AgentSpec) (runtime.Component, error) {
return &AgentComponent{spec: spec}, nil
}

// Name returns the component's instance name, or "agent" if none was set.
Expand All @@ -79,17 +54,7 @@ func (a *AgentComponent) SetName(name string) {

// Validate checks the component's configuration without side effects.
func (a *AgentComponent) Validate() error {
cfg := AgentSpec{
AgentType: a.agentType,
Model: a.model,
PromptBasePath: a.promptBasePath,
MaxIterations: a.maxIterations,
StageChannelBufferSize: a.stageChannelBufferSize,
MCPHostName: a.mcpHostName,
ToolTimeouts: a.toolTimeouts,
Stages: a.stages,
}
return cfg.Validate()
return a.spec.Validate()
}

// Init resolves the tools dependency from the runtime and constructs the
Expand All @@ -104,19 +69,18 @@ func (a *AgentComponent) Init(rt *runtime.Runtime) error {
return fmt.Errorf("invalid tools component type")
}
toolRefs := tools.GetToolRefs()
toolTimeouts := newToolTimeoutResolver(defaultToolTimeoutSeconds, a.toolTimeouts)
reactAgent, err := NewReActAgent(rt.GetGenkitRegistry(), a.promptBasePath, a.model, a.maxIterations, a.stageChannelBufferSize, a.stages, toolTimeouts, toolRefs)
toolTimeouts := newToolTimeoutResolver(defaultToolTimeoutSeconds, a.spec.ToolTimeouts)
reactAgent, err := NewReActAgent(rt.GetGenkitRegistry(), &a.spec, toolTimeouts, toolRefs)
if err != nil {
return fmt.Errorf("failed to create ReAct agent: %w", err)
}

a.Agent = reactAgent

rt.GetLogger().Info("Agent component initialized",
"agent_type", a.agentType,
"model", a.model,
"max_iterations", a.maxIterations,
"stages", len(a.stages))
"agent_type", a.spec.AgentType,
"model", a.spec.Model,
"max_iterations", a.spec.MaxIterations)

return nil
}
Expand Down
Loading