Repository navigation
Add the agent workflows-as-code builder - #7
Conversation
A hand-written builder in com.elevenlabs.api.agentworkflows that writes an agent workflow as a chain of verbs (converse, tool, transfer, end, goTo), validates the whole graph in build(), and returns the generated AgentWorkflowRequestModel. It implements the cross-SDK spec in elevenlabs-js docs/agents-as-code/workflow-spec.md, and toJsonString() writes the same bytes as the JS reference. The ten shared golden fixtures are vendored under src/test/resources and all pass. CanonicalJson and Destination are public so the tools builder can reuse them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PR SummaryLow Risk Overview
README documents usage; vendored cross-SDK golden fixtures and unit tests lock behavior to the shared agents-as-code spec. Reviewed by Cursor Bugbot for commit 2ee41e2. Bugbot is set up for automated code reviews on this repo. Configure here. |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The generated number-literal union narrows integers with intValue(), so a literal such as a millisecond timestamp wrapped silently in the request model. build() now passes such literals as doubles (exact up to 2^53, as JavaScript sends them); toJsonString() is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| "bidirectional edge would drop its reverse route. Remove the backward condition first", | ||
| sourceId | ||
| ); | ||
| return null; |
There was a problem hiding this comment.
Insert treats reverse-only edges as bidirectional
Medium Severity
insertBetween rejects any edge with a backward_condition, including backward-only edges that have no forward transition, and it only matches stored source→target. A reverse-only transition (the form fromJson already models for routing, BFS, and edge_order) cannot be spliced; looking it up from the semantic direction reports unknown_edge.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 60480d9. Configure here.
There was a problem hiding this comment.
Leaving this as is. The spec's insertBetween matches the stored source → target edge and rejects any edge with a backward condition (cannot_insert_bidirectional); JS, .NET, Go and Rust all do the same. Splicing reverse-only transitions would be Java-only behaviour.
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 3 total unresolved issues (including 2 from previous reviews).
❌ 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 f3540c2. Configure here.
| sourceId | ||
| ); | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Failed insert drops original edge
Medium Severity
insertBetween removes the original edge before the callback runs, then leaves it gone if the callback returns null. That records missing_insert_result but also deletes the source-to-target connection, so the same builder instance cannot recover the graph and later build() fails on a workflow that was valid before the insert.
Reviewed by Cursor Bugbot for commit f3540c2. Configure here.
There was a problem hiding this comment.
Leaving this as is. The spec removes the edge before calling insert, and JS, .NET, Go and Rust behave the same way. missing_insert_result stays recorded as an error, so build() on that workflow fails either way; restoring the edge wouldn't let the builder recover.
The generated node union falls back to structural matching when it doesn't know a discriminator, so a loaded node of a type this SDK version doesn't model (say future_survey) came back from build() as a different member (override_agent), with only an unknown_node_type warning that claimed the node was kept as given. build() now reports such nodes as invalid_model errors, alongside any other errors. toJson()/toJsonString() still keep them exactly as loaded, so the shared fixtures are unchanged; the fixture test now expects build() to reject the round-trip fixture's future_survey node. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>


Summary
This adds a hand-written builder that writes an agent workflow as Java code and turns it into the request model that agent create and update take. It follows the shared agents-as-code spec, so a workflow saved with
toJsonString()is byte-identical to what the JavaScript, Python, .NET and Rust SDKs write. All ten shared golden fixtures pass.Details
com.elevenlabs.api.agentworkflows, listed in.fernignorewith a note on why. Generated code is untouched.Workflow(fromAgent,fromJson,node,remove,insertBetween,build,toJson,toJsonString), the verbsconverse/tool/transfer/end/goToon the workflow, nodes and branches, pluswhen,onSuccess,onFailure,onResult(ResultBranches),up()andupdate(NodeUpdate). Options are fluent classes whose nested values use the generated types (PositionInput,EntryBehavior,TransferTypeEnum,WorkflowToolLocatorSchemaOverridesValue, ...). The optional sugar is overloads: aStringor anExprwhere aConditionis expected.build()validates, then converts the wire tree with the SDK's ownObjectMappers.JSON_MAPPERintoAgentWorkflowRequestModel. It throwsWorkflowValidationExceptionwith every issue;build(onWarning)also receives warnings.edge_orderapply only whenforward_conditionis present, and backward conditions follow the same routing rules from the target);insertBetweenon a bidirectional edge is rejected withcannot_insert_bidirectional;positionis accepted for node kinds with no field map (say,update_state, newer types).CanonicalJson, public so the tools builder can reuse it, likeDestination):JSON.stringify.Number.prototype.toString(1e-7,1.5e-7,1e+21,123456789012345680000). The shortest digits are computed exactly withBigDecimal, becauseDouble.toStringis not always the shortest form before JDK 19.unknown_node_typewarning, because the generated deserializer would match it to some other member. The README shows how to sendtoJson()throughadditionalProperty("workflow", ...)instead.fromAgentdrops nulls the generated models write for required fields they don't have (for examplelabel: nullon response conditions).build.gradletargets.Testing
docker run --rm -v "$PWD":/home/gradle/project -w /home/gradle/project gradle:8.14.3-jdk11 gradle test --no-daemon: 10,901 tests, 0 failures.WorkflowFixtureTest: all 10 fixtures, plus a count check. Each output is compared byte for byte withJSON.stringify(expected, null, 2), and each one is then round-tripped through the typedbuild()model.CanonicalJsonTest: 8 tests.WorkflowBuilderTest: 15 tests.🤖 Generated with Claude Code