Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package service

import (
"testing"

"github.com/Tencent/WeKnora/internal/config"
"github.com/Tencent/WeKnora/internal/types"
"github.com/stretchr/testify/require"
)

// The engine already knows how to run a round's tool calls concurrently
// (AgentEngine.executeToolCallsParallel, gated on AgentConfig.ParallelToolCalls),
// but nothing ever set that flag: buildAgentConfig copies CustomAgentConfig into
// the runtime AgentConfig field by field and this one was absent, so the gate
// read the zero value and the parallel branch was unreachable for every custom
// agent. Failure was silent — tools just kept running one at a time.
func TestAgentConfigCarriesTheParallelToolCallsPreference(t *testing.T) {
for _, tc := range []struct {
name string
want bool
}{
{name: "opted in", want: true},
{name: "opted out", want: false},
} {
t.Run(tc.name, func(t *testing.T) {
svc := &sessionService{
cfg: &config.Config{},
webSearchProviderRepo: &sharedAgentWebSearchRepo{},
}
req := &types.QARequest{
Session: &types.Session{ID: "session-1", TenantID: 1},
CustomAgent: &types.CustomAgent{
TenantID: 1,
Config: types.CustomAgentConfig{
MaxIterations: 5,
ParallelToolCalls: tc.want,
},
},
}

agentConfig, err := svc.buildAgentConfig(t.Context(), req, &types.Tenant{ID: 1}, 1)
require.NoError(t, err)
require.Equal(t, tc.want, agentConfig.ParallelToolCalls)
})
}
}

// Agents saved before this option existed must keep running their tools
// sequentially: tools are not required to be side-effect free, so silently
// turning on concurrency for them would be a behavior change, not a fix.
func TestAgentConfigDefaultsParallelToolCallsOff(t *testing.T) {
svc := &sessionService{
cfg: &config.Config{},
webSearchProviderRepo: &sharedAgentWebSearchRepo{},
}
req := &types.QARequest{
Session: &types.Session{ID: "session-1", TenantID: 1},
CustomAgent: &types.CustomAgent{
TenantID: 1,
Config: types.CustomAgentConfig{MaxIterations: 5},
},
}

agentConfig, err := svc.buildAgentConfig(t.Context(), req, &types.Tenant{ID: 1}, 1)
require.NoError(t, err)
require.False(t, agentConfig.ParallelToolCalls)
}
1 change: 1 addition & 0 deletions internal/application/service/session_agent_qa.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func (s *sessionService) buildAgentConfig(
customAgent := req.CustomAgent
agentConfig := &types.AgentConfig{
MaxIterations: customAgent.Config.MaxIterations,
ParallelToolCalls: customAgent.Config.ParallelToolCalls,
Temperature: customAgent.Config.Temperature,
WebSearchEnabled: customAgent.Config.WebSearchEnabled && req.WebSearchEnabled,
WebSearchMaxResults: customAgent.Config.WebSearchMaxResults,
Expand Down
4 changes: 4 additions & 0 deletions internal/types/custom_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ type CustomAgentConfig struct {
// ===== Agent Mode Settings =====
// Maximum iterations for ReAct loop (only for agent type)
MaxIterations int `yaml:"max_iterations" json:"max_iterations"`
// Whether independent tool calls in one round run concurrently (default: false).
// Opt-in because tools are not required to be side-effect free; agents that
// depend on tools observing each other's writes must leave this off.
ParallelToolCalls bool `yaml:"parallel_tool_calls" json:"parallel_tool_calls,omitempty"`
// Timeout for a single LLM call in seconds (0 = use global default)
LLMCallTimeout int `yaml:"llm_call_timeout" json:"llm_call_timeout,omitempty"`
// Allowed tools (only for agent type)
Expand Down