Skip to content

feat: agent tool variants, server tools, multi tool-result helper#1

Open
rimdoo wants to merge 1 commit into
mainfrom
feat/managed-agents-tool-variants
Open

feat: agent tool variants, server tools, multi tool-result helper#1
rimdoo wants to merge 1 commit into
mainfrom
feat/managed-agents-tool-variants

Conversation

@rimdoo

@rimdoo rimdoo commented May 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • AgentTool.Other constructor now public. The documented escape hatch ("pass any Java SDK AgentCreateParams.Tool") was previously unreachable from outside the module because of an internal constructor. raw property stays internal.
  • Typed variants for the common Managed-Agents tool cases:
    • AgentTool.Toolset20260401Subset(enabled: Set<DefaultTool>) — subset of agent_toolset_20260401 via default_config.enabled = false + per-tool addConfig. DefaultTool enum: BASH, READ, GLOB, GREP, WEB_SEARCH, WEB_FETCH.
    • AgentTool.McpToolset(serverName, enabled?) — reference a registered MCP server, optional tool-name whitelist.
    • AgentTool.CustomTool(name, description, rawInputSchema) — client-side tools; rawInputSchema keeps the Java SDK type so nested JSON Schema is fully expressible.
  • Surrounding additions used by the same flows:
    • McpUrlServer(name, url) + createAgent(mcpServers = ...) register remote MCP servers at agent creation. Auth lives separately in a vault credential targeting the same mcpServerUrl.
    • createSession(vaultIds = ...) attaches vault credentials so the agent can authenticate to MCP servers.
    • SessionStreamEvent.AgentCustomToolUse(id, name, inputJson) — previously absorbed by SessionStreamEvent.Other.
  • Message.toolResults(vararg | List) — bundles multiple tool_result blocks into one user message (required when the assistant emits >1 tool_use per turn).
  • ServerTool sealed (WebSearch / WebFetch) + serverTools parameter on createMessage / streamMessage. Mixes freely with client-side tools = listOf(Tool(...)).

Scoping notes

  • Messages-API MCP (mcp_servers body + anthropic-beta: mcp-client-2025-04-04 header) is not wrapped here. The upstream surface is still moving, so callers use the raw Java SDK directly for that case.
  • Audited every class X internal constructor(internal val raw: ...) in sdk/src/main/kotlin/com/rimdoo/anthropic/. The only one that should accept external raw injection is AgentTool.Other; the rest (ContentBlock.Other, SessionStreamEvent.Other, MessageStreamEvent.MessageStart/...) are response-side wraps the SDK constructs itself, so internal constructor is correct on those.

Test plan

  • ./gradlew :sdk:test — 134 unit tests pass (39 mappers, 7 DSL, 7 exceptions, 81 client-API smoke).
  • New MappersTest entries: every AgentTool variant builds, Toolset20260401Subset / McpToolset reject empty enabled sets, McpUrlServer + ServerTool.WebSearch + ServerTool.WebFetch build with every option combination, AgentTool.Other(rawUnion) constructs from outside-style code.
  • New ClientApiSmokeTest entries: createAgent with every AgentTool variant + mcpServers, createSession with vaultIds, createMessage / streamMessage with serverTools (alone and mixed with tools).

🤖 Generated with Claude Code

Open `AgentTool.Other` constructor to public — the documented escape hatch for
unmodeled tool variants was unreachable from outside the module ([cite: prior
`internal constructor`]). New typed variants for the common cases:

- `AgentTool.Toolset20260401Subset(enabled: Set<DefaultTool>)` — subset of the
  bundled toolset via `default_config.enabled = false` + per-tool `addConfig`.
- `AgentTool.McpToolset(serverName, enabled?)` — reference a registered MCP
  server, optionally whitelisting tool names.
- `AgentTool.CustomTool(name, description, rawInputSchema)` — client-side
  tools; raw schema type retained so nested JSON Schema stays expressible.

Adjacent:
- `McpUrlServer(name, url)` + `createAgent(mcpServers = ...)` register remote
  MCP servers at agent creation.
- `createSession(vaultIds = ...)` attaches vault credentials for MCP auth.
- `SessionStreamEvent.AgentCustomToolUse(id, name, inputJson)` — previously
  absorbed by `SessionStreamEvent.Other`.
- `Message.toolResults(...)` bundles multiple `tool_result` blocks into one
  user message (required when the assistant emits >1 `tool_use` per turn).
- `ServerTool` sealed (`WebSearch` / `WebFetch`) + `serverTools` parameter on
  `createMessage` / `streamMessage`. Mixes freely with client-side `tools`.

134 unit tests (37 + 7 + 7 + 81 + 2 new MappersTest, +5 new ClientApiSmokeTest).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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