[Method 1] - Dashboard (No code)

You can create an agent and Retell LLM object using dashboard easily. Right now in Dashbaord it’s a one to one mapping between agent and LLM, but you can have multiple agents using the same LLM in API.

You can use the agent_id, llm_id and llm_url in API.

[Method 2] - LLM Creation via API

Use API to programmatically create LLM, suitable for automation and integration with your existing systems.

Step 1 - Create the LLM Object via API

There’re two types of LLMs you can create:

Option 1: Single Prompt LLM

Suitable for simple use cases where there’s one core task / topic for the call and a few tools the LLM can access.

Read more about how to define tools in Tool Calling.

// install the sdk: https://docs.retellai.com/get-started/sdk
import Retell from 'retell-sdk';
import { LlmResponse } from "retell-sdk/resources/llm.mjs";

const retellClient = new Retell({
  apiKey: "YOUR_API_KEY",
});

const llm: LlmResponse = await retellClient.llm.create({
  general_prompt:
    "You are a friendly agent that helps people retrieves weather information.",
  begin_message: "Hi, I'm your virtual weather assistant, how can I help you?",
  general_tools: [
    {
      type: "end_call",
      name: "end_call",
      description:
        "Hang up the call, triggered only after appointment successfully scheduled.",
    },
    {
      type: "custom",
      name: "get_weather",
      description:
        "Get the current weather, called when user is asking whether of a specific city.",
      parameters: {
        type: "object",
        properties: {
          city: {
            type: "string",
            description: "The city for which the weather is to be fetched.",
          },
        },
        required: ["city"],
      },
      speak_during_execution: true,
      speak_after_execution: true,
      url: "http://your-server-url-here/get_weawther",
    },
  ],
});

console.log(llm);

Option 2: Stateful Multi-Prompt LLM

Alternatively, you can create a stateful multi-prompt LLM which is suitable for complicated use cases where there are multiple stages / themes of call, each with access to different set of tools.

Read more about how to define states in LLM States.

// install the sdk: https://docs.retellai.com/get-started/sdk
import Retell from 'retell-sdk';
import { LlmResponse } from "retell-sdk/resources/llm.mjs";

const retellClient = new Retell({
  // Find the key in dashboard
  apiKey: "YOUR_API_KEY",
});

const llm: LlmResponse = await retellClient.llm.create({
  general_prompt: "You are ...",
  general_tools: [
    {
      type: "end_call",
      name: "end_call",
      description:
        "End the call with user only when user explicitly requests it.",
    },
  ],
  states: [
    {
      name: "information_collection",
      state_prompt: "You will follow the steps below to collect information...",
      edges: [
        {
          destination_state_name: "appointment_booking",
          description:
            "Transition to book an appointment if the user is due for an annual checkup based on the last checkup time collected.",
        },
      ],
      tools: [
        {
          type: "transfer_call",
          name: "transfer_to_support",
          description:
            "Transfer to the support team when user seems angry or explicitly requests a human agent",
          number: "16175551212",
        },
      ],
    },
    {
      name: "appointment_booking",
      state_prompt: "You will follow the steps below to book an appointment...",
      tools: [
        {
          type: "book_appointment_cal",
          name: "book_appointment",
          description:
            "Book an annual check up when user provided name, email, phone number, and have selected a time.",
          cal_api_key: "cal_live_xxxxxxxxxxxx",
          event_type_id: 60444,
          timezone: "America/Los_Angeles",
        },
      ],
    },
  ],
  starting_state: "information_collection",
  begin_message: "Hey I am a virtual assistant calling from Retell Hospital.",
});

console.log(llm);

Step 2 - Connect Retell LLM To Agent

To utilize the LLM you’ve developed, obtain the llm_websocket_url either from the API response or by copying and pasting it from the dashboard. Then, input it into an agent where you can customize and establish an entity for conducting voice conversations. Read more in Agent Guide.

const agent: AgentResponse = await retellClient.agent.create({
  llm_websocket_url: llm.llm_websocket_url,
  voice_id: "11labs-Adrian",
  agent_name: "Ryan",
});
console.log(agent);

👏 Congratulations! You’ve successfully created an agent. Now, you can:

  1. Initiate a phone call using the agent. (link)
  2. Start a web call with it. (link)
  3. Enhance the agent’s capabilities:
    • Incorporate additional functionalities, such as scheduling events in a calendar or invoking your custom functions. (link)
    • Segment the prompt into various states to minimize errors and improve the accuracy of function calls. (link)

Configure Who Speaks First

You can configure whether the agent or the user speaks first in the conversation. You can also configure what to say when the agent speaks first.