Skip to content

Add the agent workflows-as-code builder - #7

Merged
PaulAsjes merged 7 commits into
mainfrom
pma/agent-workflows
Nov 20, 2026
Merged

PaulAsjes merged 7 commits into
mainfrom
pma/agent-workflows

Conversation

@PaulAsjes

Copy link
Copy Markdown
Collaborator

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
  • Package: com.elevenlabs.api.agentworkflows, listed in .fernignore with a note on why. Generated code is untouched.
  • Surface: Workflow (fromAgent, fromJson, node, remove, insertBetween, build, toJson, toJsonString), the verbs converse / tool / transfer / end / goTo on the workflow, nodes and branches, plus when, onSuccess, onFailure, onResult(ResultBranches), up() and update(NodeUpdate). Options are fluent classes whose nested values use the generated types (PositionInput, EntryBehavior, TransferTypeEnum, WorkflowToolLocatorSchemaOverridesValue, ...). The optional sugar is overloads: a String or an Expr where a Condition is expected.
  • build() validates, then converts the wire tree with the SDK's own ObjectMappers.JSON_MAPPER into AgentWorkflowRequestModel. It throws WorkflowValidationException with every issue; build(onWarning) also receives warnings.
  • Fixes the other ports carry: the transition-presence model (forward checks, BFS and edge_order apply only when forward_condition is present, and backward conditions follow the same routing rules from the target); insertBetween on a bidirectional edge is rejected with cannot_insert_bidirectional; position is accepted for node kinds with no field map (say, update_state, newer types).
  • Canonical JSON (CanonicalJson, public so the tools builder can reuse it, like Destination):
    • Keys are sorted the way a JS object orders them, with array-index keys first.
    • Escaping matches JSON.stringify.
    • Doubles are written per Number.prototype.toString (1e-7, 1.5e-7, 1e+21, 123456789012345680000). The shortest digits are computed exactly with BigDecimal, because Double.toString is not always the shortest form before JDK 19.
    • Whole doubles are written as integers, and integers above 2^53 exactly as written.
    • Loading reads numbers without rounding and keeps document order.
  • Unknown node types: the generated union's discriminator is read by reflection. An unmodelled type gets an unknown_node_type warning, because the generated deserializer would match it to some other member. The README shows how to send toJson() through additionalProperty("workflow", ...) instead.
  • fromAgent drops nulls the generated models write for required fields they don't have (for example label: null on response conditions).
  • Java 8 language and APIs only, as build.gradle targets.

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.
  • New tests: 34.
    • WorkflowFixtureTest: all 10 fixtures, plus a count check. Each output is compared byte for byte with JSON.stringify(expected, null, 2), and each one is then round-tripped through the typed build() model.
    • CanonicalJsonTest: 8 tests.
    • WorkflowBuilderTest: 15 tests.

🤖 Generated with Claude Code

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]>
@cursor

cursor Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
New optional library code and tests atop generated types; no changes to auth, payment, or core client wiring.

Overview
Introduces a hand-written com.elevenlabs.api.agentworkflows package (excluded from Fern) for defining agent workflows in Java with a fluent chain API—converse, tool, transfer, end, goTo, conditional routing, and onResult—then emitting AgentWorkflowRequestModel via build() or canonical JSON via toJsonString().

CanonicalJson matches other ElevenLabs SDKs (sorted keys, JavaScript number formatting, 2-space indent). Workflows can be loaded from agents or JSON, edited (node, insertBetween, remove), validated with aggregated WorkflowValidationException issues, and laid out automatically while preserving loaded ids/positions/edge order.

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.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

PaulAsjes and others added 3 commits November 19, 2026 15:28
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]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

"bidirectional edge would drop its reverse route. Remove the backward condition first",
sourceId
);
return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 60480d9. Configure here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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).

Fix All in Cursor

❌ 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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f3540c2. Configure here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

PaulAsjes and others added 2 commits November 19, 2026 17:28
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]>
@PaulAsjes
PaulAsjes merged commit 4a826aa into main Nov 20, 2026
4 checks passed
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