Skip to content

fix(harness)!: make built-in web tools opt-in - #4103

Closed
xseruer wants to merge 5 commits into
agentscope-ai:mainfrom
xseruer:fix/harness-web-tools-opt-in
Closed

xseruer wants to merge 5 commits into
agentscope-ai:mainfrom
xseruer:fix/harness-web-tools-opt-in

Conversation

@xseruer

@xseruer xseruer commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT (current main).

Summary

  • Do not register Harness's built-in web_search and web_fetch unless the application explicitly calls enableWebTools().
  • Propagate that choice to automatically constructed general-purpose and declared subagents, so opting in continues to work for delegated tasks.
  • Preserve disableWebTools(), explicitly registered application tools, and model-provider-native search; document the new default and migration in English and Chinese.

Why disabled by default is the better default

1. A registered capability should not advertise functionality that is unavailable

The built-in web_search is backed by Tavily and requires a separately configured TAVILY_API_KEY. Today, Harness registers it regardless of whether those credentials exist. Without a key, every invocation returns a configuration error rather than search results. An optional third-party integration is not a usable default capability just because the framework contains its implementation.

2. Unused schemas and failed calls waste tokens and increase latency

The search schema is included in model input even in applications that cannot or do not intend to use Tavily. That consumes input/context budget without contributing a usable capability. If selected, generating the tool name and arguments, processing the configuration error, and potentially attempting recovery add further tokens, latency, and irrelevant context. The unnecessary capability also appears in delegated tasks unless the choice is applied consistently to subagents.

Disabling it at registration time removes the unused schema, rather than leaving a tool available and hoping the model never calls it. This PR makes no numerical token-saving claim: the benefit is the removal of unnecessary schemas and avoidable failed turns, not a benchmark result.

3. Framework search should not compete with an application's selected native search

A model provider may already offer a native web_search capability. Automatically introducing a separate Tavily-backed tool with the same name can create naming or tool-selection ambiguity and steer the model away from the intended search backend. The framework should let the application deliberately choose its search provider instead of silently adding an alternative.

This change does not disable provider-native search or change provider adapters. It only changes automatic registration of Harness's own web tools.

4. Third-party credentials, billing, and data handling should be an explicit choice

An open-source framework can support external APIs without enabling them by default. Tavily has its own credentials, billing, and data-handling terms. Whether an agent should send search queries to that service belongs to application configuration, particularly for deployments with internal or sensitive workloads.

Registration alone does not send queries or incur Tavily charges, and the current missing-key check prevents an outbound search when no key is configured. The immediate missing-key problem is wasted model tokens and failed calls; explicit opt-in additionally makes the external-service dependency and query-routing choice intentional when credentials are present.

5. Explicit opt-in is predictable and easy to migrate

enableWebTools() expresses application intent independently of ambient environment variables. Merely adding TAVILY_API_KEY, or supplying webHttpClient(...) for transport configuration, must not silently change the agent's exposed capabilities. Applications that want the existing tools can retain them with one builder call; applications using another search backend no longer need a defensive opt-out.

Behavior and migration

HarnessAgent agent = HarnessAgent.builder()
    .model(model)
    .workspace(workspace)
    .enableWebTools()
    .build();
  • Default: neither built-in web tool is registered, on the main agent or automatically constructed subagents.
  • Opt-in: both tools are registered and the choice is inherited by general-purpose and declared subagents.
  • Credentials: Tavily-backed web_search still requires TAVILY_API_KEY when called. Setting the key alone does not enable it.
  • Transport: webHttpClient(...) only customizes HTTP transport; call enableWebTools() separately.
  • Opt-out: disableWebTools() remains supported, including after an explicit opt-in.
  • Scope: web_fetch itself does not require Tavily credentials; it follows the existing shared web-tools switch. Applications needing only one web tool can register it explicitly in their toolkit.
  • Unaffected: explicitly registered application tools and provider-native search.

This intentionally changes a public default, so the commit is marked as breaking and the migration is documented. No new dependencies, credential auto-detection, provider-specific heuristics, or search implementation changes are introduced.

Test plan

  • Java 17 targeted regression run: mvn -B -T1C -pl agentscope-harness -am test -Dtest=HarnessAgentTest,HarnessAgentSubagentStreamTest,WebToolsTest -Dsurefire.failIfNoSpecifiedTests=false — 106 tests passed, no failures/errors/skips.
  • Cover default absence, explicit opt-in, explicit disable after opt-in, and custom HTTP client not implicitly enabling web tools.
  • Cover default and opt-in inheritance for both general-purpose and declared subagents; retain custom-client and fromAgent collision regression coverage with explicit opt-in.
  • Java 17 mvn -B -T1C -pl agentscope-harness -am spotless:apply.
  • Documentation npm test — 13 tests passed.
  • Documentation npm run validate — navigation, syntax, links, anchors, assets, and Mintlify build passed.
  • Documentation npm run broken-links — no broken links.
  • git diff --check.
  • Full repository Java 17 mvn -B -T1C clean verify — BUILD SUCCESS; Surefire module summaries report 9,289 tests: 9,052 passed, 237 skipped, zero failures/errors.

Checklist

  • Code has been formatted with mvn spotless:apply.
  • All executed repository tests passed; the 237 skipped tests are explicitly reported above.
  • Javadoc comments follow project conventions and describe explicit enablement.
  • Related English and Chinese documentation has been updated.
  • Code is ready for review.

Avoid spending tokens on unconfigured Tavily search and competing with provider-native search unless applications explicitly opt in.

BREAKING CHANGE: Built-in web_search and web_fetch now require enableWebTools(); credentials or a custom HTTP client alone do not enable them.
@mintlify

mintlify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit d2adf00.

Approve preview

@juruoO-o

Copy link
Copy Markdown
Collaborator

当前 HarnessAgent 默认提供 web_search 和 web_fetch,应用已经可以通过 .disableWebTools() 主动关闭。把默认值改为关闭后,依赖这两个工具的应用即使代码和配置都没变,升级后也会失去原有能力。尤其是 web_fetch 无需 Tavily 凭据,也会一起被关闭。

xzxiaoshan added a commit that referenced this pull request Nov 20, 2026
…#4274)

## Background

Swept the last 125 PRs (#4272→#4075) for single-OS CI failures under
`mvn -B -T1C clean verify` (one build OS red, the other green on the
same commit = flake suspect). Cross-PR repeats and main's own red run on
2026-11-19 (ubuntu, run 44516464414) pinpoints four still-broken test
classes; all fixes are test-side only (no `src/main` changes).

## Fixes and evidence

| Test class | Victims | Signature | Fix |
|---|---|---|---|
| `RocketMqExecutionTest` | #4182, #4192, #4103 + main run 44516464414
(2026-11-19, ubuntu) | `turn reaches SUCCEEDED did not become true
within 10s` while the turn kept progressing (modelCalls complete, acks
climbing, lastFailure=none) — deadline breakthrough under starvation,
not a lost turn | shared `waitUntil` deadline 10s→30s (repo tier
#3726/#3774) |
| `AgentScopeAdapterTest` | #4204 (same-commit re-run green = confirmed
flake), #4191, #4246 | `Timed out observing Turn` at 6.7–8.5s elapsed;
resume/recovery one step from terminal | `turn.await(5s)`→30s at all 3
sibling sites via `TURN_DEADLINE`, outer `get` budgets +5s margin |
| `WorkerRuntimeTest` | #4219, #4224, #4255 (windows) | (a) `Worker
lease lost` after 2.4s — 1s claim leases expired between claim and
release; (b) `renewed.await(5s)` missed at 6.5s while the recovery lane
was healthy; (c) `Interrupted sleep interrupted` —
`WorkerRuntime.process()` interrupts the calling thread on lease-renewal
failure and manual `tick()` runs it on the test thread | (a) claim
leases 1s→30s (staleness under test still comes from `release(ZERO)` +
re-claim); (b) latches 5s→30s; (c) raw `Thread.sleep`→interrupt-proof
`pause()` at 5 sites, mirroring the #4176 fix for the same signature in
`ProcessRecoveryTest` |
| `ChatSessionsTest.await` (shared with `ChatControllerTest`) | #4233,
#4182 (stuck-RUNNING at 40.8s/46.4s), #4268, #4163 (poll threw `Durable
database transaction failed`) | two surfaces of one cause: every
snapshot poll opens a writing sqlite transaction contending with the
runtime's own writes, and windows runners starve turns past 30s (same
file already measured 56.6s starvation and uses 120s elsewhere, #3726) |
deadline 30s→120s (aligned tier) + tolerate transient `UNAVAILABLE`
store exceptions while polling; persistent failure rethrows at the
deadline, FAILED-turn fast-fail unchanged |
| `CommandExecutorTest.missingExitCodeIsUnknown` | local -T2C full-repo
stress (2026-11-19; pristine-main baseline of the same class green) |
the 2s network budget fired on scheduler starvation before the instant
fake response was processed, misclassifying the failure as a deadline
miss instead of a missing exit code (2.97s elapsed) | budget 2s→30s for
this non-deadline-semantics test; the two deadline-semantics tests keep
their tight budgets |

## Constraint compliance

- Happy path zero cost: every change only extends failure-path deadlines
or hardens helpers; no new sleeps, no weakened assertions.
- Minimal widening anchored to measured data (each comment cites victims
+ measured values); 30s follows the repo's established deflake tier,
120s follows this file's own previously measured starvation tier.
- Structural hardening preferred: `pause()` helper, transient-lock
retry, lease decoupling from the tested invariant.
- No `src/main` changes.

## Observed but deliberately not fixed here

-
`ProcessRecoveryTest.replacementCollectsOriginalResultWithoutRepeatingEffect`
(#4214: `expected: 2 but was: 3`): recovery-semantics race (model re-run
without effect re-run after abrupt halt) — a product question for the
durable recovery work, not a deadline flake.
-
`JevEvidenceProcessorTest.filterFailureIsWithheldButRankFailureFollowsScoredEvidence`
(#4265: delivered `[]` on a 25×-slowed runner): root cause not
established; single occurrence.
- Already fixed upstream, victims predate the fix:
`AgentScopeAgentExecutorInputRequiredTest` (#4157/#4187/#4152 all
predate #4176's `BaseReActAgentRunner` change), `InboxMiddlewareTest`
(#4093 predates #3738), `HarnessAgentSubagentStreamEventsTest` (#4183
predates #2917).
- `SkillBoxTest$UploadContainment` quartet (#4201/#4202/#4212/#4229):
test does not exist on main (fork stack only); deterministic cross-drive
path bug, not load flakiness.
- #4184/#4185: both-OS compile breaks from dependency major bumps
(dependabot), out of scope.

Also applied during review: sibling sites with the identical measured
mechanism were widened in the same pass — the remaining 1s fixture claim
leases in `WorkerRuntimeTest` (fenced begin/update/release sequences,
same #4219 signature), the start/PAUSED 5s budgets in the same
`AgentScopeAdapterTest` method as the victims, and the 5s/4s observe
budgets in
`completeLocalBackendRunsNativeAgentWhileManagedObserverIsBlocked`.

## Test plan

- [x] Full local `mvn -B -T2C clean verify` green (stricter than CI's
-T1C). Locally excluded, each verified to fail identically on pristine
main on this machine (Windows/git-bash) while passing on CI:
`JsonFileAgentStateStoreTest` (symlink permissions), the
`agentscope-extensions-durable-sandbox` trio plus
`ToolInSandboxExampleTest`/`SandboxRoundTripTest` (sandbox shell heredoc
incompatible with local git-bash python3), and the
`AgentScopeAdapterTest`/`ProcessRecoveryTest`/`HarnessExternalToolProcessRecoveryTest`
trio (durable-adapter classes whose Windows runs are skipped on CI; the
same named tests fail on pristine main locally).
- [ ] CI green on both OS.

@juruoO-o juruoO-o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢补充 Tavily 配置和子 Agent 工具继承的说明。让应用更方便地控制暴露给模型的工具,这个方向有价值。

项目的兼容性原则是,已有应用在代码和配置不变的情况下升级,应保留原有行为。当前改动会让默认构建的 HarnessAgent 同时失去 web_search 和 web_fetch;已有应用即使配置了 webHttpClient,也需要额外调用 enableWebTools() 才能恢复。这里的兼容性影响是工具注册行为发生了变化,已有代码仍然能够编译,因此用户可能要到运行时才会发现。

请保留这两个工具现有的默认注册行为,以及 disableWebTools() 的现有用法。如果希望给应用更细粒度的控制,可以通过显式配置提供,并让未使用新配置的应用继续按原方式运行。建议保留一个使用升级前 builder 写法的回归测试,核对两个工具仍然可见。

另外,docs/v2 对应已发布的 v2.0.4,该版本没有 enableWebTools()。如果调整后仍新增配置,请将说明放在中英文 docs/dev 中,保持稳定版示例可直接使用。

@xseruer

xseruer commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

感谢评审,也认同这个原则:默认注册行为是已有应用依赖的行为,不应在代码和配置不变的情况下因升级而改变。

我们不再推进默认关闭的改动,关闭这个 PR。我们自己需要关闭这两个工具的场景会继续使用 disableWebTools()。

如果以后在大版本中有调整默认值的机会,欢迎届时再考虑显式 opt-in;在那之前不再占用评审时间。

@xseruer xseruer closed this Nov 26, 2026
@xseruer
xseruer deleted the fix/harness-web-tools-opt-in branch November 26, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 重要紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants