Repository navigation
Add the agent tools-as-code builder - #9
Conversation
Port the hand-written tools-as-code builder (elevenlabs-js docs/agents-as-code/tool-spec.md) to Java as com.elevenlabs.api.agenttools: webhook, client and system tools, the Schema helper, Header and AuthConnection, Tool.fromJson/fromResponse loaders, build() returning the generated ToolRequestModel and toJsonString() byte-identical to the JS SDK. It reuses the workflow builder's CanonicalJson and Destination. It follows the rules the .NET, PHP, Ruby and Rust ports share where they deviate from JS on purpose (removing the last assignment, client param or query param omits the field; an empty URL is missing_url; loaded containers are objects only when untyped; a nullable literal's null constant survives loading; loaded query, allowed_values and required_constraints keep unmodeled fields), plus the latest review fixes: constants the generated model would change are reported instead of sent altered, path params are always required, and malformed loaded fields are kept and reported as invalid_model. The 21 shared fixtures are vendored and run in ToolFixtureTest, which also checks that build()'s model loads back to the same bytes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PR SummaryMedium Risk Overview The package adds an immutable Reviewed by Cursor Bugbot for commit 26972d8. Bugbot is set up for automated code reviews on this repo. Configure here. |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| } | ||
| ToolValidation.checkSchema(prop.getValue(), path, true, issues); | ||
| } | ||
| } |
There was a problem hiding this comment.
Query schema skips container checks
Low Severity
Webhook query validation walks each query param but never runs checkSchema on the query object itself. Client params, body, and response all do, so loaded query requireAnyOf()/requireAllOf() names that do not exist are not reported as unknown_required_property.
Reviewed by Cursor Bugbot for commit 4c8788b. Configure here.
There was a problem hiding this comment.
Leaving this as is. The API's query params schema has no required_constraints (the generated QueryParamsJsonSchemaInput has only properties and required), and query params can only be added through queryParam(), so requireAnyOf()/requireAllOf() can't target them. A loaded required_constraints there is kept as an unmodeled field, as the spec says, and no other SDK checks it.
…ent-tools-builder
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ent-tools-builder
A transfer_to_number tool may hold per-provider transfer_rules instead of transfers; the API takes exactly one of the two. A pulled rules-only tool was rejected as no_transfers. Now no_transfers fires only when neither list has entries, loaded rules are kept as loaded, and a tool with both is a new conflicting_transfers error. Vendors shared fixtures 22 and 23 from elevenlabs-js. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cf63c7e. Configure here.
| boolean hasRules = hasEntries(params.get("transfer_rules")); | ||
| if (!hasTransfers && !hasRules) { | ||
| issues.add(ToolIssue.error("no_transfers", "transfer", systemToolType + " needs at least one transfer()")); | ||
| } else if (hasTransfers && hasRules) { |
There was a problem hiding this comment.
Rules check covers agent transfers
Low Severity
validate() treats a non-empty transfer_rules list as a valid substitute for transfers on every transfer tool, including transfer_to_agent. That field exists only on transfer_to_number; a loaded agent-transfer tool with rules and no destinations now passes instead of reporting no_transfers, and one that also has transfers is rejected as conflicting_transfers even though transfer_rules is just an unmodeled extra field there.
Reviewed by Cursor Bugbot for commit cf63c7e. Configure here.
Co-Authored-By: Claude Opus 5.5 <[email protected]>


Summary
Adds
com.elevenlabs.api.agenttools, a hand-written builder for agent tools in code: webhook, client and system tools, plus theSchemahelper they share.build()returns the generatedToolRequestModelthatagents().tools().create()andupdate()take, andtoJsonString()writes the same bytes as the JS SDK and the CLI'stool_configs/*.json. It reuses the workflow builder'sCanonicalJsonandDestination.Stacked on #7 (the workflows builder): it targets
pma/agent-workflowsand must merge after #7.Details
Contract. Follows
docs/agents-as-code/tool-spec.mdin elevenlabs-js. The 21 golden fixtures are vendored intosrc/test/resources/agenttools/fixturesand run byToolFixtureTest. Expected output is compared byte for byte, and for every output fixture the test also checks that thebuild()model loads back to the same bytes.API.
Tool.webhook(name, description)/Tool.client(...)/SystemTool.endCall(),.skipTurn(),.transferToNumber()and the rest.Tool.fromJson(String | JsonNode)loads a bare config or a{tool_config}wrapper, andTool.fromResponse(ToolResponseModel)loads a get response. ThenasWebhook()/asClient()/asSystem()(asOptional),build(),buildConfig()andtoJson()/toJsonString().SystemTool.buildBuiltInConfig()returns theSystemToolConfigInputforprompt.built_in_tools. Java won't letbuildConfig()change its return type in a subclass, so the system tool gets its own method name.Schema.string()/integer()/number()/bool()returnLiteralSchema,object()returnsObjectSchemaandarray(items)returnsArraySchema, each with covariant returns. Options are oneToolOptionsclass that takes generated enum types (PreToolSpeechMode,ToolExecutionMode, ...), as the workflow builder does; a key that doesn't apply to the tool's kind isinvalid_option. Transfer options areToolTransferOptions, and the system tool constructor params are nested classes inSystemToolOptions.Shared rules where the new SDKs deviate from JS on purpose (same as .NET, PHP, Ruby and Rust):
typeon an emptied query schema doesn't count as content.missing_url.type. Body, response and params then write"type": "object"; the querytypestays synthetic and is written only if it was loaded. A declared non-object type is kept and reported asbody_not_objectatbody,response,paramsorquery.constant_value: nullsurvives load andtoJson(). The generated model reads null as unset, sobuild()reportsconstant_type_mismatch.query_params_schemakeeps all its fields, and loadedallowed_valuesandrequired_constraints(and their groups) keep fields the builder doesn't model. Edits are overlaid on the loaded object.Latest review fixes from the other ports.
omit()on one isomitted_required, whateveroptional()says.build()asinvalid_model, whiletoJson()writes them back. This covers schema fields of the wrong shape, clientparametersthat aren't an object, systemparamswithout asystem_tool_type, and webhookapi_schemaparts that aren't objects.constant_valueis not treated as a metadata key.{}, and numeric property names stay a JSON object in JavaScript key order.Constants and the Java model.
build()serializes the model it produced and compares every schema constant with the wire config. A constant the model would change or drop is reported asconstant_type_mismatchwith its path; nothing is changed silently. Integers beyond thelongrange are rejected bytoJson()too, as in the other SDKs. Two limits are specific to Java, because the generatedLiteralJsonSchemaPropertyConstantValueholds anintor adouble:intrange (for example3000000000, or9007199254740993for anumber) is written exactly bytoJsonString(), butbuild()reports it, since the model would truncate it.9007199254740992.5), and an integer beyondlongnested inside an object or array constant, are reported the same way.An integer that JavaScript would read and write back as a double (
123456789012345680000) is accepted and sent as that double.Fern. The package, its tests and its fixtures are in
.fernignorewith a why-comment. The README has a new "Agent tools as code" section.Testing
javac --release 8 -Xlint:allagainst the generated classes, and the tests compile with--release 8(checks the Java 8 API level).gradle --no-daemon compileJavaandgradle --no-daemon test, Gradle 8.14.3) passes on this PR. Locally,gradle compileJavaingradle:8.14.3-jdk11passed; later Docker runs couldn't start because the local Docker daemon's storage began returning I/O errors.com.elevenlabs.api.agenttoolspasses 60/60 (21 fixtures, the fixture-count check and 38 builder tests), andcom.elevenlabs.api.agentworkflowsstill passes 34/34.🤖 Generated with Claude Code