Skip to content

feat(agent): let custom agents opt into parallel tool execution - #2716

Open
hjxccc wants to merge 1 commit into
Tencent:mainfrom
hjxccc:pr/custom-agent-parallel-tool-calls
Open

feat(agent): let custom agents opt into parallel tool execution#2716
hjxccc wants to merge 1 commit into
Tencent:mainfrom
hjxccc:pr/custom-agent-parallel-tool-calls

Conversation

@hjxccc

@hjxccc hjxccc commented Aug 15, 2026

Copy link
Copy Markdown

Description

AgentEngine.executeToolCalls already branches to executeToolCallsParallel when AgentConfig.ParallelToolCalls is set (internal/agent/act.go:230), and that branch is fully implemented — errgroup, results collected in original order, siblings not cancelled on individual failure.

But nothing ever sets the flag. buildAgentConfig copies CustomAgentConfig into the runtime AgentConfig field by field, and this field was missing from the bridge, so the gate always read the zero value:

$ grep -rn "ParallelToolCalls:\|\.ParallelToolCalls =" --include=*.go internal/ | grep -v _test | grep -v chat/
internal/agent/think.go:176:  ParallelToolCalls: &parallelToolCalls,

That single hit is chat.Options.ParallelToolCalls (a *bool on the outbound LLM request) — a different struct. types.AgentConfig.ParallelToolCalls has no assignment anywhere, which makes executeToolCallsParallel unreachable for every custom agent.

This PR adds ParallelToolCalls to CustomAgentConfig and maps it in buildAgentConfig, so the existing engine capability becomes reachable.

Defaults to false. Tools are not required to be side-effect free, and agents that depend on tools observing each other's writes must keep running them sequentially. Turning concurrency on for already-saved agents would be a behaviour change rather than a fix, so opting in is explicit.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📚 Documentation update
  • 🎨 Refactor
  • ⚡ Performance improvement
  • 🧪 Test
  • 🔧 Configuration / Build / CI

Related Issue

None — found while reading the agent execution path.

Testing

Go 1.26.0, CGO_ENABLED=1:

  • gofmt -l internal/types/custom_agent.go internal/application/service/session_agent_qa.go internal/application/service/agent_parallel_tool_calls_config_test.go — no output
  • go vet ./internal/types/ ./internal/application/service/ — clean
  • go test ./internal/application/service/ -run ParallelToolCalls -count=1 -v — 3 cases pass

New coverage mirrors the existing agent_memory_config_test.go, which guards the same class of defect (a field silently absent from buildAgentConfig's field-by-field copy):

  • TestAgentConfigCarriesTheParallelToolCallsPreference — opted in / opted out both propagate.
  • TestAgentConfigDefaultsParallelToolCallsOff — an agent that never set the field stays sequential.

The focused packages were validated. Full-repository make test was not run; the change is two field additions plus their unit tests.

Checklist

  • git diff --check origin/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages pass
  • Diff-scoped lint passes where applicable (go vet for the changed packages)
  • Full-repository checks were run, or any unrelated/environment-dependent failures are documented above
  • Self-reviewed the code
  • Added/updated tests covering the change
  • Updated related documentation (not applicable; the field is self-documenting in the config struct and defaults to existing behavior)
  • Breaking changes are clearly called out (none — default preserves sequential execution)

Screenshots / Recordings

Not applicable; backend-only change. No frontend toggle is included — the field is settable through the existing agent config API. Happy to add a UI control in the agent editor if maintainers would like it in the same PR.

AgentEngine.executeToolCalls already branches to executeToolCallsParallel
when AgentConfig.ParallelToolCalls is set, and that branch is fully
implemented (errgroup, ordered result collection, best-effort siblings).
But nothing ever set the flag: buildAgentConfig copies CustomAgentConfig
into the runtime AgentConfig field by field, and this field was missing
from both structs' bridge. The gate therefore always read the zero value,
making executeToolCallsParallel unreachable for every custom agent.

Add ParallelToolCalls to CustomAgentConfig and map it in buildAgentConfig.

Defaults to false: tools are not required to be side-effect free, so
agents saved before this option existed must keep running their tools
sequentially. Enabling concurrency for them silently would be a behavior
change rather than a fix.
@hjxccc

hjxccc commented Aug 18, 2026

Copy link
Copy Markdown
Author

友好 ping 一下 🙏 CI 全绿、无冲突。

一句话:executeToolCallsParallel(act.go)整套已经实现好了,但 types.AgentConfig.ParallelToolCalls 在全仓没有任何赋值点,buildAgentConfig 漏了这个字段,所以这条并行分支对所有自定义智能体都是不可达代码。本 PR 只是把 CustomAgentConfigAgentConfig 的桥接补齐。

默认 false,存量智能体行为不变——工具不保证无副作用,所以必须显式 opt-in。

sakitam-fdd added a commit to sakitam-fdd/WeKnora that referenced this pull request Aug 21, 2026
Port Tencent#2716 onto the current fork staging branch using GitHub's three-way merge.
sakitam-fdd added a commit to sakitam-fdd/WeKnora that referenced this pull request Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant