Skip to content

feat: Add agent tools as code (tool builder) - #930

Merged
PaulAsjes merged 3 commits into
mainfrom
feat/tool-builder
Nov 13, 2026
Merged

PaulAsjes merged 3 commits into
mainfrom
feat/tool-builder

Conversation

@PaulAsjes

Copy link
Copy Markdown
Collaborator

Summary

Adds elevenlabs.agent_tools, a chained builder for webhook, client and system agent tools, next to the workflow builder. build() returns the request tools.create() takes, SystemTool.build_config() returns the entry agents.create() takes in built_in_tools, and to_json_string() writes the same tool_configs/*.json file as the CLI and the other SDKs. It is a port of the JavaScript builder and passes the same 21 shared fixtures.

Details
  • Port of Add a tool builder: webhook, client and system tools as code elevenlabs-js#486. It follows agent_workflows conventions: state is kept in wire format, to_json() uses its canonical() helper (shared through agent_tools/_wire.py), build() produces the generated models with construct_type, and transfers reuse its Destination.
  • The package is listed in .fernignore. No generated files are touched.
  • Names are snake_case: path_param, query_param, from_variable, system_provided, allowed_from, require_any_of, build_config, to_json_string, from_response, as_webhook, Header.env_var, AuthConnection.env_var, body_schema. Schema.bool() and Schema.object() are static methods. Inside the class body, annotations use builtins.bool and @builtins.property so the method names don't shadow the builtins.
  • Options are keyword arguments: .options(response_timeout_secs=10), .transfer(cond, dest, transfer_type="sip_refer"), .assign(var, path, sanitize=True). options() accepts every option for every tool kind and stays typed. If an option doesn't apply to the tool's kind, build() reports invalid_option; chaining never raises.
  • build_config() has a narrower return type on each kind: ToolRequestModelToolConfig_Webhook / _Client, and SystemToolConfigOutput for system tools. The generated ConversationalConfig that agents.create() / agents.update() take is built from the ...Output prompt models, so BuiltInToolsOutput(end_call=SystemTool.end_call().build_config()) type-checks without a cast.
  • Issue paths are snake_case to match the Python method names (path_params.order_id, response_timeout_secs). Issue codes are the same as the spec's.
  • When loading, null fields are read as absent (except inside constant_value and dynamic_variable_placeholders). The API's defaults for unset fields are kept and written back unchanged. Keys the generated models don't know are kept too. The JS serializers strip those keys for known tool types.

Testing

  • pytest tests/agent_tools: 50 passed (21 shared fixtures plus a count check, and 28 unit tests that mirror the JS tools.test.ts). The extra tests send build() through tools.create() and system tools through agents.create() on a mock transport, and load a tools.get() response that has nulls.
  • pytest .: 405 passed, 18 failed. The same 18 fail on origin/main (355 passed, 18 failed). They are live API tests that need ELEVENLABS_API_KEY.
  • mypy .: no issues in 2804 files, with the lockfile's pydantic 2.10.6 and websockets 13.1. python tests/verify_types.py passes. ruff check and ruff format --check are clean on the new files.
  • I ran the README example with tools.create / agents.create stubbed and type-checked it with mypy. Nothing was sent to the real API.

🤖 Generated with Claude Code

Port of the agent tools builder to Python, in elevenlabs.agent_tools next
to agent_workflows. Webhook, client and system tools are written as
chains; build() returns the ToolRequestModel tools.create() takes,
SystemTool.build_config() the built_in_tools entry agents.create() takes,
and to_json_string() the canonical tool_configs/*.json file. Validation
reports every problem at once in a ToolValidationError.

Runs the 21 shared tool fixtures, copied into tests/agent_tools/fixtures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PaulAsjes
PaulAsjes marked this pull request as ready for review November 10, 2026 13:03
@PaulAsjes
PaulAsjes requested a balanced review from Copilot November 10, 2026 13:03
@cursor

cursor Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
New public SDK surface that shapes tool and agent configs sent to the Conversational AI API; logic is large but additive and heavily fixture-tested.

Overview
Adds elevenlabs.agent_tools, a fluent API to define webhook, client, and system agent tools in Python instead of hand-writing nested JSON. Tool.webhook() / Tool.client() / SystemTool.* chain methods for HTTP shape, params, headers, transfers, and options; Schema expresses param JSON schemas and value sources (describe(), from_variable(), constant(), etc.).

build() emits payloads for conversational_ai.tools.create() / update(); SystemTool.build_config() feeds built_in_tools on agent create/update. to_json_string() matches CLI tool_configs/*.json. Loading via Tool.from_json() / from_response() round-trips API wire format, with ToolValidationError listing all validation issues. Unknown tool types (e.g. MCP) pass through with warnings.

The package is .fernignored (hand-maintained, mirrors the JS builder). README documents usage; 21 shared JSON fixtures plus Python-specific tests cover validation, round-trip, and mocked API sends.

Reviewed by Cursor Bugbot for commit c9709f7. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI 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.

🟡 Changes recommended

Unresolved defects reject supported list-valued literal types, discard retained query-schema fields, accept empty value sources, and allow dynamic SIP transfers without the required transfer type.

4 open issues
What changed in this PR

Adds elevenlabs.agent_tools, a chained builder for webhook, client, and system agent tools alongside the existing workflow builder.

Changes:

  • Adds schema builders, validation, loading, and serialization into SDK request models and CLI-compatible JSON.
  • Supports headers, authentication, response assignments, and system-tool transfers.
  • Adds usage documentation, 21 shared fixtures, and Python-specific integration tests.
File Description
tests/​agent_tools/​test_tools.py Tests builders, validation, loading, and SDK request serialization.
tests/​agent_tools/​test_fixtures.py Runs shared fixtures and checks expected JSON.
tests/​agent_tools/​fixtures/​21-errors-auth-placeholder.json Covers conflicting auth-resolved path parameters.
tests/​agent_tools/​fixtures/​20-url-placeholders.json Covers environment and auth URL placeholders.
tests/​agent_tools/​fixtures/​19-knowledge-base.json Covers knowledge-base search strategies.
tests/​agent_tools/​fixtures/​18-header-and-auth-sources.json Covers environment-backed headers and authentication.
tests/​agent_tools/​fixtures/​17-errors-missing-body.json Covers missing request-body validation.
tests/​agent_tools/​fixtures/​16-load-api-defaults.json Covers preservation of loaded API defaults.
tests/​agent_tools/​fixtures/​15-errors-missing-url.json Covers missing URLs and invalid body schemas.
tests/​agent_tools/​fixtures/​14-errors-system.json Covers invalid system-tool transfers and options.
tests/​agent_tools/​fixtures/​13-errors-schema.json Covers schema validation errors.
tests/​agent_tools/​fixtures/​12-errors-webhook.json Covers webhook validation errors.
tests/​agent_tools/​fixtures/​11-edit-loaded.json Covers editing loaded webhook tools.
tests/​agent_tools/​fixtures/​10-unknown-type.json Covers unknown tool-type preservation.
tests/​agent_tools/​fixtures/​09-round-trip.json Covers tool configuration round trips.
tests/​agent_tools/​fixtures/​08-required-order.json Covers required-property ordering after edits.
tests/​agent_tools/​fixtures/​07-value-sources.json Covers schema value sources and constraints.
tests/​agent_tools/​fixtures/​06-other-system-tools.json Covers skip-turn parameters and options.
tests/​agent_tools/​fixtures/​05-transfer-to-agent.json Covers agent transfer destinations and settings.
tests/​agent_tools/​fixtures/​04-transfer-to-number.json Covers phone and SIP transfers.
tests/​agent_tools/​fixtures/​03-client-tool.json Covers client parameters and options.
tests/​agent_tools/​fixtures/​02-request-body.json Covers request bodies, authentication, and assignments.
tests/​agent_tools/​fixtures/​01-docs-example.json Covers the documented webhook example.
tests/​agent_tools/​fixture_runner.py Interprets shared fixture operations.
tests/​agent_tools/​__init__.py Establishes the test package.
src/​elevenlabs/​agent_tools/​validate.py Validates schema sources, types, and constraints.
src/​elevenlabs/​agent_tools/​tool.py Implements tool builders, loading, and serialization.
src/​elevenlabs/​agent_tools/​schema.py Implements reusable immutable schema builders.
src/​elevenlabs/​agent_tools/​header.py Adds header and authentication value helpers.
src/​elevenlabs/​agent_tools/​errors.py Defines structured validation issues and exceptions.
src/​elevenlabs/​agent_tools/​_wire.py Shares wire-format helpers and normalizes loaded nulls.
src/​elevenlabs/​agent_tools/​__init__.py Exports the public builder API.
README.md Documents tool creation and agent integration.
.fernignore Protects the hand-maintained package from regeneration.

Review effort: Balanced

Comment thread src/elevenlabs/agent_tools/schema.py Resolved
Comment thread src/elevenlabs/agent_tools/tool.py Resolved
Comment thread src/elevenlabs/agent_tools/tool.py Resolved
Comment thread src/elevenlabs/agent_tools/validate.py Resolved

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

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 c0befba. Configure here.

Comment thread src/elevenlabs/agent_tools/tool.py Resolved
- Require sip_refer for SIP URIs held in dynamic variables, not only static ones.
- Load empty params, body and response schemas with no type as objects.
- Validate a client tool's params object itself, so its require_any_of/require_all_of are checked.
- Treat an empty description or variable name as no value source, as the API does.
- Read a literal type list such as ["integer", "null"] by its non-null member, and allow a null constant for it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copilot AI 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.

🟡 Changes recommended

Round-trip serialization silently drops query-schema extension fields and explicit null constants, causing configuration loss and validation failures.

2 open issues
3 resolved since last review

Review effort: Balanced

Comment thread src/elevenlabs/agent_tools/_wire.py Resolved
- A literal's unset constant is "", so a null constant on a type like ["integer", "null"] is a real value: keep
  it when loading. A null constant on an object or array still means unset.
- Write back every field of a loaded query_params_schema, not only properties and required.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PaulAsjes
PaulAsjes merged commit 0d6ce50 into main Nov 13, 2026
6 checks passed
@PaulAsjes
PaulAsjes deleted the feat/tool-builder branch November 13, 2026 09:38
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.

3 participants