Skip to content

feat: Agents as code: Agent builder, agents.push/pull and CLI project layout - #939

Merged
PaulAsjes merged 3 commits into
mainfrom
feat/agent-builder
Nov 20, 2026
Merged

PaulAsjes merged 3 commits into
mainfrom
feat/agent-builder

Conversation

@PaulAsjes

Copy link
Copy Markdown
Collaborator

Summary

Python port of the agents-as-code Agent builder from elevenlabs/elevenlabs-js#497, whose shape was approved there. One Agent definition brings together an agent's settings, its tools and its workflow. client.conversational_ai.agents.push(agent) then creates or updates the agent and every tool it uses. AgentProject keeps agents in the ElevenLabs CLI's project files, so one repo works with both the SDK and elevenlabs agents push.

Usage

from elevenlabs import ElevenLabs
from elevenlabs.agent_builder import Agent, AgentProject
from elevenlabs.agent_tools import Schema, SystemTool, Tool
from elevenlabs.agent_workflows import Workflow

get_order = (
    Tool.webhook("get_order", "Look up an order by its number")
    .get("https://api.example.com/orders/{order_id}")
    .path_param("order_id", Schema.string().describe("The order number, e.g. A-1042"))
)

wf = Workflow()
(
    wf.converse("triage", "Find out what the caller needs")
    .when("Caller gave an order number")
    .tool("lookup", [get_order])  # a Tool object, not an id: push fills the id in
    .on_success()
    .converse("resolve", "Explain the order status")
)

agent = Agent(
    "Support line",
    prompt="You are a support agent for Acme.",
    first_message="Hi, how can I help?",
    voice_id="21m00Tcm4TlvDq8ikWAM",
    tools=[SystemTool.end_call()],
    workflow=wf,
)

client = ElevenLabs()
result = client.conversational_ai.agents.push(agent)  # creates get_order and the agent
client.conversational_ai.agents.push(agent, agent_id=result.agent_id)  # later: updates only what changed

agent.validate()  # in CI, no API key needed; raises AgentValidationError

# Keep agents in git, in the CLI's layout
project = AgentProject.open(".")
client.conversational_ai.agents.push(agent, project=project)
client.conversational_ai.agents.pull("agent_123", project=project)

AsyncElevenLabs has the same push and pull, which you await.

Details

What's ported: everything in the JS PR, including its review fixes.

  • The Agent builder:
    • typed options, the raw conversation_config / platform_settings, conflict detection;
    • system tools go into built_in_tools;
    • the same issue codes as JS.
  • Push and pull:
    • push matches tools by recorded id with a project, and otherwise by name among the tools the agent already uses;
    • tools that already match the server are unchanged and send no request; tools the agent stops using are reported as detached, never deleted;
    • AgentPushError carries the partial result;
    • pull uses the CLI's config shape.
  • AgentProject in the CLI layout: 0600 file permissions, O_NOFOLLOW, paths kept inside the project, and the CLI's formatting and file naming.
  • Workflow tool references: tool nodes and subagent tool_ids accept Tool objects. Workflow.from_json(data, tools_by_id=...) swaps ids for Tool objects through a module-private function.
  • Typed options use the generated models: each option is built as a piece of the generated ConversationalConfig, and the wire path is read from the serialized piece. Field names the model doesn't declare are rejected, so a wrong name fails instead of being a hand-typed snake_case path.

Where Python differs from JS:

  • build() returns a TypedDict. The Python SDK has no generated create-agent request model, so build() returns a TypedDict of generated models, used as agents.create(**agent.build(tool_ids=...)).
  • Tool requests send a dict body. The generated client ignores additional_body_parameters when the request is a pydantic model. Tool create and update therefore send {"tool_config": wire}. Agent create and update send typed kwargs plus the full config as extra body parameters, as in JS.
  • The unchanged check compares modeled fields only. Unlike the JS one, the Python tool builder keeps fields it doesn't model. Comparing the whole tool would never match a tool rebuilt in code.
  • Responses are converted back with only the fields the server sent. .dict() would fill in model defaults, which would then end up in pulled config files.
  • Bad values become issues. A wrong value in a raw config dict or a typed option, such as a string for temperature, is reported as an invalid_config issue instead of raising.
  • One implementation of push and pull. Push and pull are written once as a generator of API calls, with small sync and async runners, so the steps aren't duplicated.
  • File I/O is synchronous. AgentProject reads and writes files synchronously, including when called from the async client.

Overlap: #938 also changes agent_workflows/graph.py and workflow.py. Whichever PR merges second will need a rebase.

Testing

  • pytest tests/agent_builder tests/agent_tools tests/agent_workflows: 197 passed. That is 51 new agent tests, 3 new workflow tests, and the 143 that were already there.
  • New tests run against an in-memory fake API (httpx MockTransport). They cover:
    • the sync and async push and pull;
    • every review-fix case from the JS PR;
    • project files on disk, including symlinks and 0600 permissions;
    • a byte-identical round trip of the CLI fixture project.
  • On Python 3.8, the same tests (without test_client_tool_decorator.py) pass with both pydantic 2.10 and 1.10: 178 each.
  • ruff check and mypy on the new and changed modules: clean.
  • Not run: a smoke test against the live API.

🤖 Generated with Claude Code

@PaulAsjes
PaulAsjes marked this pull request as ready for review November 18, 2026 17:06
@cursor

cursor Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Push/pull orchestrate multi-step API writes to agents and shared tools; mis-matching or partial failures are mitigated by validation-first behavior and AgentPushError partial results, but incorrect pushes could still alter live agent configs.

Overview
Adds elevenlabs.agent_builder so one Agent definition combines prompt/voice settings, Tool / system tools, and a Workflow, with client.conversational_ai.agents.push() validating first, then creating or updating tools (by project id or by name for that agent only) and the agent, filling tool ids into prompt and workflow. pull() reverses into Agent + Tool objects; optional AgentProject mirrors the ElevenLabs CLI layout and persists ids/configs on disk with safe file writes.

Workflows now accept Tool references in tool/subagent nodes (not just string ids); build() / to_json() take a tool_ids name→id map, with new validation for duplicate names and unresolved tools.

Sync and async clients share one generator-based push/pull implementation; README documents the feature. Large test suite with an in-memory fake API and CLI fixture round-trips.

Reviewed by Cursor Bugbot for commit 40588cd. 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.

Comment thread src/elevenlabs/agent_workflows/graph.py Resolved
PaulAsjes and others added 2 commits November 19, 2026 14:32
…out)

Port of the JS agents-as-code Agent builder: one Agent definition composing settings, tools and a workflow; client.conversational_ai.agents.push()/pull() on the sync and async clients; AgentProject reading and writing the ElevenLabs CLI's project files; workflow tool nodes accepting Tool objects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- tool_definition(): strip unmodeled keys inside Optional unions of models
  (such as an array's items), so a tool rebuilt in code still matches the
  stored copy and push doesn't PATCH it needlessly.
- Workflow tool nodes: two different Tool objects with the same name in
  one node's list are now a duplicate_tool_name issue.
- Workflow.to_json_string() takes tool_ids, like to_json().

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.

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 2e3e866. Configure here.

Comment thread src/elevenlabs/agent_builder/push.py Resolved
…on 3.8

- push(branch_id=...) without a project now reads the branch's config and
  gets its tools by id. The tools API's used_by_agent_id covers the main
  branch only, so a branch push could update a main-branch tool of the
  same name and report main-branch tools as detached.
- tool_definition(): resolve forward references to generated types, which
  Python 3.8 leaves unresolved in model annotations, so unmodeled keys
  inside Optional unions are stripped there too (fixes the 3.8 CI failure).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PaulAsjes
PaulAsjes merged commit c4247af into main Nov 20, 2026
6 checks passed
@PaulAsjes
PaulAsjes deleted the feat/agent-builder branch November 20, 2026 08:26
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.

2 participants