#Show me a python code in how to create an agent and tools for it?

1 messages · Page 1 of 1 (latest)

sharp hamletBOT
#
AI-generated Answer for dinesh_85560

Below is the minimal, working Python flow using only what’s documented: create tools, create an agent that references them, then (optionally) register a client tool handler and start a session.

Prereqs:

  • pip install elevenlabs requests
  • Set ELEVENLABS_API_KEY in your environment

Python:

import os
import requests
from elevenlabs import ElevenLabs, ToolRequestModel, ToolRequestModelToolConfig_Client
from elevenlabs.conversational_ai.conversation import Conversation, ClientTools

API_KEY = os.environ["ELEVENLABS_API_KEY"]
BASE = "https://api.elevenlabs.io"
headers = {"xi-api-key": API_KEY, "Content-Type": "application/json"}

1) Create a server (webhook) tool via API

webhook_tool = requests.post(
f"{BASE}/v1/convai/tools",
json={
"tool_config": {
"type": "webhook",
"name": "getWeather",
"description": "Fetch current weather from your HTTP endpoint.",
"api_schema": {
"url": "https://example.com/weather", # replace with your webhook URL
"method": "GET"
}
}
},
headers=headers
).json()
weather_tool_id = webhook_tool["id"]

2) Create a client tool via SDK

client = ElevenLabs(api_key=API_KEY)
client_tool = client.conversational_ai.tools.create(
request=ToolRequestModel(
tool_config=ToolRequestModelToolConfig_Client(
name="logMessage",
description="Log a message on the client.",
expects_response=False,
)
)
)
client_tool_id = client_tool.id

3) Create an agent that can use the tools (reference tool_ids)

agent_resp = requests.post(
f"{BASE}/v1/convai/agents/create",
json={
"name": "Weather helper",
"conversation_config": {
"agent": {
"prompt": {
"prompt": "You are a helpful assistant. Use tools when appropriate.",
"llm": "gpt-4o-mini",
"tool_ids": [client_tool_id, weather_tool_id]
# System tools are enabled via built_in_tools by name if needed.
}
}
}
},
headers=headers
).json()
agent_id = agent_resp["agent_id"]

4) (Optional) Register the client tool handler and start a session

def log_message(parameters):
print(parameters.get("message"))

client_tools = ClientTools()
client_tools.register("logMessage", log_message)

conversation = Conversation(
client=client,
agent_id=agent_id,
client_tools=client_tools,
)
conversation.start_session()

Notes:

  • Tools must now be attached to agents by ID using prompt.tool_ids; legacy prompt.tools is deprecated per the migration guide. For system tools (e.g., end_call), use prompt.built_in_tools (referenced by name). (elevenlabs.io)
  • Create tool (POST /v1/convai/tools) supports webhook and client tools; example above uses both documented shapes. (elevenlabs.io)
  • Creating an agent is done via POST /v1/convai/agents/create; include your tool IDs under conversation_config.agent.prompt.tool_ids. The update schema shows the same fields (llm, tool_ids, built_in_tools). (elevenlabs.io)
  • Client tools must be registered in code with ClientTools.register(name, fn), and the name must match the tool’s configuration. (elevenlabs.io)

References:

  • Create tool (API): POST /v1/convai/tools. (elevenlabs.io)
  • Create agent (API): POST /v1/convai/agents/create. (elevenlabs.io)
  • Agent tools deprecation and prompt.tool_ids.
torn cove
#

Give an example of creating and agent to use built int transfer_to_agent tool

sharp hamletBOT
#
AI-generated Answer for dinesh_85560

Here’s a minimal Python example that creates an agent configured with the built‑in transfer_to_agent system tool and two transfer rules. Replace AGENT_ID_1 / AGENT_ID_2 with the target agent IDs you want to transfer to.

python
from elevenlabs import (
ConversationalConfig,
ElevenLabs,
AgentConfig,
PromptAgent,
PromptAgentInputToolsItem_System,
SystemToolConfigInputParams_TransferToAgent,
AgentTransfer,
)

Initialize the client

elevenlabs = ElevenLabs(api_key="YOUR_API_KEY")

Define transfer rules (targets + when to transfer)

transfer_rules = [
AgentTransfer(
agent_id="AGENT_ID_1",
condition="When the user asks for billing support.",
delay_ms=1000, # optional: add a short delay before transfer
transfer_message="I'm connecting you to our billing specialist.",
enable_transferred_agent_first_message=True, # optional: let target agent play its first message
),
AgentTransfer(
agent_id="AGENT_ID_2",
condition="When the user requests advanced technical help.",
delay_ms=0, # immediate transfer
transfer_message=None, # silent transfer
enable_transferred_agent_first_message=False,
),
]

Configure the built-in system tool

transfer_tool = PromptAgentInputToolsItem_System(
type="system",
name="transfer_to_agent",
description="Transfer the user to a specialized agent based on their request.",
params=SystemToolConfigInputParams_TransferToAgent(
transfers=transfer_rules
),
)

Create the agent with the transfer tool enabled

conversation_config = ConversationalConfig(
agent=AgentConfig(
prompt=PromptAgent(
prompt="You are a helpful assistant.",
first_message="Hi, how can I help you today?",
tools=[transfer_tool],
)
)
)

response = elevenlabs.conversational_ai.agents.create(
conversation_config=conversation_config
)
print(response)

Notes:

  • The LLM will call the transfer_to_agent tool when your rule conditions match; it selects the zero‑indexed agent_number based on the order of your transfers list and may include an optional reason. Ensure your account has at least viewer permissions on the target agents. (elevenlabs.io)

References:

  • Agent transfer (system tool), API usage and parameters. (elevenlabs.io)
  • Agent-to-agent transfer workflow overview and API example. (elevenlabs.io)

Sources:
Agent transfer | ElevenLabs Documentation
Agent transfer | ElevenLabs Documentation
Agent transfer | ElevenLabs Documentation

torn cove
#

tools is deprecated, show me to to use built_in_tools

sharp hamletBOT
#
AI-generated Answer for dinesh_85560

Short answer

  • The legacy field prompt.tools is deprecated and rejected since July 23, 2025. Use prompt.tool_ids for your client/server tools and prompt.built_in_tools for system tools by name (e.g., transfer_to_agent). (elevenlabs.io)

How to use built_in_tools (with transfer_to_agent)

  1. Create any webhook/client tools you need and keep their IDs
  • Create tools via POST /v1/convai/tools, then keep the returned id values. (elevenlabs.io)
  1. Create or update your agent to enable system tools by name
  • Send built_in_tools with the system tool names you want, and tool_ids with your standalone tool IDs.
  • Example request body for POST /v1/convai/agents/create:
    {
    "conversation_config": {
    "agent": {
    "prompt": {
    "built_in_tools": ["transfer_to_agent"],
    "tool_ids": ["<YOUR_TOOL_ID_1>", "<YOUR_TOOL_ID_2>"]
    }
    }
    },
    "name": "Support Orchestrator"
    }
    Notes:
  • Do not send prompt.tools in the same request; requests containing prompt.tools are now rejected. (elevenlabs.io)
  • Agent creation endpoint: POST /v1/convai/agents/create. (elevenlabs.io)
  1. Configure transfer rules for transfer_to_agent
  • Define which target agents can be transferred to and the conditions/rules. In the dashboard, add the Transfer to AI Agent tool, then set rules mapping “agent_number” (zero‑indexed) to specific agent IDs and optional delay/messages. Your LLM will call transfer_to_agent with an agent_number. (elevenlabs.io)

What system tool names can I pass in built_in_tools?

  • end_call, language_detection, transfer_to_agent, transfer_to_number, skip_turn, play_keypad_touch_tone, voicemail_detection. (elevenlabs.io)

Background and migration details

  • Field changes and timelines (July 14 full compatibility, July 15 GET stops returning tools, July 23 rejection of prompt.tools), and the rule to reference system tools by name in prompt.built_in_tools. (elevenlabs.io)

Related docs

  • Overview of how tools work (client, webhook/server, system).
torn cove
#

Giev me examples with python constructs such as ConversationalConfig. The new client must include builtin tools

sharp hamletBOT
#
AI-generated Answer for dinesh_85560

Below are minimal, up-to-date Python examples that use ConversationalConfig with the new fields prompt.built_in_tools and prompt.tool_ids. The legacy prompt.tools array is deprecated and must not be used in new code.

Example 1 — Create an agent that enables built‑in system tools

  • Uses built_in_tools to enable system tools by name (e.g., end_call, language_detection, transfer_to_agent).
  • No legacy tools array.

Code:
"""
from elevenlabs import ElevenLabs, ConversationalConfig, AgentConfig, PromptAgent

client = ElevenLabs(api_key="YOUR_API_KEY")

cfg = ConversationalConfig(
agent=AgentConfig(
prompt=PromptAgent(
prompt="You are a helpful assistant.",
first_message="Hi! How can I help you today?",
# New way to enable system tools (by name):
built_in_tools=[
"end_call",
"language_detection",
"transfer_to_agent",
],
# For client/server (non-system) tools, reference IDs (see Example 2):
tool_ids=[],
)
)
)

resp = client.conversational_ai.agents.create(conversation_config=cfg)
print(resp)
"""

  • The tools migration replaces prompt.tools with prompt.tool_ids, and introduces prompt.built_in_tools for system tools by name. Using prompt.tools after July 23, 2025 is rejected. (elevenlabs.io)
  • Creating agents via the Python SDK with ConversationalConfig is supported as shown in the Agents create reference. (elevenlabs.io)
  • System tool names you can reference include end_call, language_detection, transfer_to_agent, transfer_to_number, skip_turn, play_keypad_touch_tone, and voicemail_detection. (elevenlabs.io)

Example 2 — Attach a webhook/client tool by ID and also enable built‑in tools

  • First create a tool and capture its id.
  • Then wire the tool via prompt.tool_ids and add system tools via prompt.built_in_tools.

Code:
"""
from elevenlabs import ElevenLabs, ConversationalConfig, AgentConfig, PromptAgent
from elevenlabs import ToolRequestModel, ToolRequestModelToolConfig_Client

client = ElevenLabs(api_key="YOUR_API_KEY")

1) Create a client tool (example) and get its ID

tool = client.conversational_ai.tools.create(
request=ToolRequestModel(
tool_config=ToolRequestModelToolConfig_Client(
name="open_url",
description="Open a provided URL in the user's browser.",
expects_response=False,
)
)
)
tool_id = tool.id

2) Create an agent that uses the tool by ID and enables built-in system tools

cfg = ConversationalConfig(
agent=AgentConfig(
prompt=PromptAgent(
prompt="You are a helpful assistant.",
first_message="Hello!",
tool_ids=[tool_id], # new: list of client/server tool IDs
built_in_tools=["transfer_to_agent", "end_call"], # new: system tools by name
)
)
)

resp = client.conversational_ai.agents.create(conversation_config=cfg)
print(resp)
"""

  • Manage tools via the /v1/convai/tools endpoints (create/list/update/delete); in code, use conversational_ai.tools.create and then place returned IDs in prompt.tool_ids. (elevenlabs.io)
  • Do not send both prompt.tools and prompt.tool_ids in the same request; use prompt.tool_ids (IDs) for client/server tools and prompt.built_in_tools (names) for system tools. (elevenlabs.io)

Notes

torn cove
#

What about PromptAgentApiModelOutput and ArrayJsonSchemaPropertyOutput