Repository navigation
feat: Add agent tools as code (tool builder) - #930
Conversation
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]>
PR SummaryMedium Risk Overview
The package is Reviewed by Cursor Bugbot for commit c9709f7. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
🟡 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
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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.
- 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]>
- 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]>


Summary
Adds
elevenlabs.agent_tools, a chained builder for webhook, client and system agent tools, next to the workflow builder.build()returns the requesttools.create()takes,SystemTool.build_config()returns the entryagents.create()takes inbuilt_in_tools, andto_json_string()writes the sametool_configs/*.jsonfile as the CLI and the other SDKs. It is a port of the JavaScript builder and passes the same 21 shared fixtures.Details
agent_workflowsconventions: state is kept in wire format,to_json()uses itscanonical()helper (shared throughagent_tools/_wire.py),build()produces the generated models withconstruct_type, and transfers reuse itsDestination..fernignore. No generated files are touched.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()andSchema.object()are static methods. Inside the class body, annotations usebuiltins.booland@builtins.propertyso the method names don't shadow the builtins..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()reportsinvalid_option; chaining never raises.build_config()has a narrower return type on each kind:ToolRequestModelToolConfig_Webhook/_Client, andSystemToolConfigOutputfor system tools. The generatedConversationalConfigthatagents.create()/agents.update()take is built from the...Outputprompt models, soBuiltInToolsOutput(end_call=SystemTool.end_call().build_config())type-checks without a cast.path_params.order_id,response_timeout_secs). Issue codes are the same as the spec's.nullfields are read as absent (except insideconstant_valueanddynamic_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 JStools.test.ts). The extra tests sendbuild()throughtools.create()and system tools throughagents.create()on a mock transport, and load atools.get()response that has nulls.pytest .: 405 passed, 18 failed. The same 18 fail onorigin/main(355 passed, 18 failed). They are live API tests that needELEVENLABS_API_KEY.mypy .: no issues in 2804 files, with the lockfile's pydantic 2.10.6 and websockets 13.1.python tests/verify_types.pypasses.ruff checkandruff format --checkare clean on the new files.tools.create/agents.createstubbed and type-checked it with mypy. Nothing was sent to the real API.🤖 Generated with Claude Code