Agents as code
Overview
An agent is assembled from several parts. Its config is a large nested object, its webhook and client tools are created separately and attached by ID, and its workflow refers to those same tool IDs. Doing this by hand means creating each tool, copying the returned IDs into the agent’s config and its workflow’s nodes, then creating or updating the agent. A missing ID only shows up once the agent runs, and running the same script twice creates duplicate tools.
The Agent builder in the Python and JavaScript SDKs describes the whole agent in one definition: its settings, the tools it uses and its workflow. agents.push() then creates or updates every tool and the agent, filling in the tool IDs for you.
Use it to:
- Define an agent in code and review changes to it like any other code change.
- Validate agents in CI without an API key.
- Re-run a deploy script safely: tools that haven’t changed aren’t touched, and nothing is duplicated.
- Keep agents in a repository in the same layout as the CLI, and work on them with either.
The builder runs in the SDK. push() and pull() call the existing agents and tools endpoints,
and anything they create can be opened and edited in the dashboard.
Requirements
- Python: the
elevenlabspackage. The builder is imported fromelevenlabs.agent_builder, tools fromelevenlabs.agent_toolsand workflows fromelevenlabs.agent_workflows. - JavaScript: the
@elevenlabs/elevenlabs-jspackage. Everything is exported from the package root.
Define and push an agent
Agent(name, options) takes the agent’s name and its settings. This agent has a webhook tool that its workflow uses, and the built-in end-call tool:
The workflow’s tool node takes the Tool object itself rather than an ID. push() creates get_order, then writes its new ID into the node. Tools used only by the workflow don’t also need to be listed in tools.
Without an agent ID, push() creates a new agent each time, just as agents.create() does. Keep the returned ID and pass it on later pushes, or use a project, which records it for you:
AsyncElevenLabs has the same push() and pull() in Python, to await.
Agent options
The typed options cover the settings most agents change. Each one maps to a field of the agent’s config:
update() changes options after the agent is created, and add_tool() / addTool() adds one tool:
Other settings
conversation_config / conversationConfig and platform_settings / platformSettings take any setting the typed options don’t cover, in the same shape as agents.create(). In Python they can be the SDK’s generated models or dictionaries with snake_case keys. They’re merged with the typed options, so you can use both:
If a raw setting and a typed option set the same field, such as prompt and conversation_config.agent.prompt.prompt, validation reports an option_conflict instead of letting one silently win.
Tools
tools takes every kind of tool from tools as code, and each kind ends up in a different place:
agent.tools() returns every webhook and client tool the agent and its workflow use: the set push() creates and updates. Two different tools can’t share a name, but the same Tool object can be used in several places: it’s pushed once and gets one ID.
How push matches tools
Tool names aren’t unique in a workspace, so push() never looks tools up by name across the whole workspace. With an agent ID, it lists the tools that agent already uses and matches those by name. A tool with the same name that only another agent uses is never touched, so a push can’t change an agent you didn’t mean to. With a project, tools are matched by the IDs the project records instead.
For each tool, push() then:
- Leaves the tool alone if the existing one already matches the definition.
- Updates it if it differs.
- Creates it if there’s no match.
Push results
push() returns what it did to the agent and to each tool, keyed by tool name:
A "detached" tool is one the agent used before this push and no longer does. It’s removed from the agent but not deleted, since another agent may still use it.
Failed pushes
push() validates the agent before it makes any request, so an invalid agent writes nothing. If a request fails partway, for example after some tools are created, push() raises or throws an AgentPushError. Its result lists the tools already written and their IDs, so nothing is left unaccounted for. The original error is its cause.
Push options
Make the requests yourself
push() is optional. build() returns the request body for agents.create() and agents.update(), given the IDs of the tools the agent uses, keyed by tool name. Use it to create the tools in your own way first:
If a tool has no ID in the map, build() reports an unresolved_tool issue naming it.
Keep agents in version control
AgentProject reads and writes the CLI’s project layout, so the same repository works with the SDK and with elevenlabs agents push:
Pass a project to push() and it matches agents and tools by the IDs the project records, rather than by an agent ID you keep. It writes the configs it sent and any new IDs back to the project, so running the same script again updates the agent instead of creating another:
Edit an agent stored in a project
project.agent(name) loads an agent from its config file as an Agent. Tools listed in tools.json come back as Tool objects, and IDs of other tools stay in tool_ids / toolIds. Settings the builder doesn’t model are kept, so pushing it back only changes what you changed:
agent.workflow gives you the agent’s workflow to edit with the workflow builder, with its tool nodes pointing at the same Tool objects.
Pull an agent from the dashboard
agents.pull(agent_id) loads an existing agent as an Agent, with its webhook and client tools as Tool objects. With a project, it also writes the agent and its tools there and records their IDs, so an agent built in the dashboard can be moved into a repository:
Validate in CI
Validation needs no API key, so a CI job can check every agent in a project on each pull request, then push them on merge:
Projects support JSON config files only for now. If agents.json points at a YAML or TOML config,
opening the project raises an AgentProjectError.
Validation
validate() checks the agent and everything it uses, without needing tool IDs. build() and push() call it first. It raises or throws a single AgentValidationError whose issues list every problem, each with a code, a message and the path of the part it concerns:
An agent with no prompt is reported as a missing_prompt warning, which doesn’t fail validation. Pass on_warning / onWarning to validate() to receive warnings.