How to use Squads in web call
# support
b
Hey, I'm building the voice agent through VAPI Squads feature. I wonder that can I directly call the Squads I created in the Dashboard like I called one single assistant? I'm trying to integrated it with my JavaScript project.
I can call one single assistant easily through ''' vapi.start("79f3XXXX-XXXX-XXXX-XXXX-XXXXXXXXce48"); ''' But I can not call the squad
v
You can continue this conversation by mentioning me in the message.
@Bowen Absolutely, you can call the Squads you've created in the Dashboard just like you would call a single assistant. In your JavaScript project, you would typically use the VAPI SDK or the appropriate API endpoint to initiate a call to your Squad. You'll need to reference the Squad by its unique identifier or name, and ensure that you have the necessary authentication in place. If you need a code snippet or further guidance on how to integrate this into your JavaScript project, please let me know, and I'll be happy to assist you further!
b
Hi @Vapi , could you provide some documentation regarding it? Thanks
v
@Bowen Certainly! While I don't have direct access to VAPI's documentation, I can guide you on where to find it. For detailed instructions on how to call Squads using VAPI, you should check the official VAPI documentation provided in your developer dashboard or on the VAPI website. The documentation typically includes code examples, SDK references, and API endpoints that you can use. If you're already able to call a single assistant, calling a Squad might involve a similar process but with different parameters or endpoint. Look for a section in the documentation that specifically addresses Squads or multi-assistant setups. If you're unable to find the information you need or if you have any specific questions about the integration, please reach out to VAPI support for more detailed assistance. They will be able to provide you with the most accurate and up-to-date information.
b
should I use the code like this: vapi.start( { "squad": { "members": [ { "assistantId": "information-gathering-assistant-id", "assistantDestinations": [{ "type": "assistant", "assistantName": "Appointment Booking", "message": "Please hold on while I transfer you to our appointment booking assistant.", "description": "Transfer the user to the appointment booking assistant after they say their name." }], }, { "assistant": { "name": "Appointment Booking", ... }, } ] } } )
Hey @Vapi , thanks for your quick response. I think I haven't figure it how to call my squad. Could you provide more information?
v
@Bowen I apologize for any confusion. To call a Squad, you would typically use a method similar to calling a single assistant, but with the necessary parameters to specify the Squad and its members. Based on the code snippet you've provided, it looks like you're on the right track. However, the exact method to start a Squad call may vary depending on the VAPI SDK or API you are using. The code should specify the Squad ID or the members of the Squad you want to call. Here's a general idea of what the code might look like, but please refer to the VAPI documentation for the exact syntax and parameters:
Copy code
javascript
vapi.startSquad({
    squadId: "your-squad-id", // Replace with your actual Squad ID
    // Additional parameters may be required depending on the VAPI implementation
});
If
vapi.start
is the method you use to start a single assistant, there might be a similar method like
vapi.startSquad
for Squads. The documentation will have the specific details you need. If you're still having trouble, I recommend reaching out to VAPI support directly for more detailed guidance on calling a Squad in your JavaScript project. They can provide you with specific code examples and troubleshooting tips tailored to your situation.
b
I got one error : Error TypeError: eo.startSquad is not a function @User @User
import Vapi from "@vapi-ai/web"; const vapi = new Vapi("xxxxxxx"); const handleVoiceChat = async () => { try { vapi.startSquad({ squadId: "xxxxxxx", }); } catch (error) { console.error("Error", error); } };
This is my code\
s
@Bowen
Copy code
ts
start(
    assistant?: CreateAssistantDTO | string,
    assistantOverrides?: AssistantOverrides,
    squad?: CreateSquadDTO | string,
  )
You need to pass squadId as third parameter to the start function.
Copy code
ts
start(undefined, undefined, <insert-squadid-or-squad-here>)
This is how a web call is created.
Copy code
ts
  async start(
    assistant?: CreateAssistantDTO | string,
    assistantOverrides?: AssistantOverrides,
    squad?: CreateSquadDTO | string,
  ): Promise<Call | null> {
    if (!assistant && !squad) {
      throw new Error('Assistant or Squad must be provided.');
    }

    if (this.started) {
      return null;
    }
    this.started = true;

    try {
      const webCall = (
        await client.call.callControllerCreateWebCall({
          assistant: typeof assistant === 'string' ? undefined : assistant,
          assistantId: typeof assistant === 'string' ? assistant : undefined,
          assistantOverrides,
          squad: typeof squad === 'string' ? undefined : squad,
          squadId: typeof squad === 'string' ? squad : undefined,
        })
      ).data;
@Bowen do let me know if you require further help.
b
Thanks Shubham
s
Apology for the delay @Bowen
m
@Shubham Bajaj @Vapi https://docs.vapi.ai/squads-example I am trying to call it from my server. So if i want to return squad in assistant request what kind of payload should i return. I have tried to follow above documentation but it says squad property does not exists.
v
@Mudassar I'm sorry to hear you're encountering issues with the Squads feature. If the documentation states that a
squad
property should exist and you're receiving an error that it does not, this could be due to a discrepancy between the documentation and the SDK version you are using, or there might be a mistake in the payload structure. When returning a squad in an assistant request, your payload should match the expected structure defined by the VAPI. Typically, this would involve specifying the
squad
object with its
members
array, each containing the necessary details about the assistant members. Here's a simplified example of what the payload might look like:
Copy code
json
{
  "squad": {
    "members": [
      {
        "assistantId": "assistant-id-1",
        // Additional assistant-specific parameters
      },
      {
        "assistantId": "assistant-id-2",
        // Additional assistant-specific parameters
      }
      // ... more members if necessary
    ]
  }
}
However, since you mentioned that the
squad
property does not exist according to the error message, it's possible that there might be an issue with the SDK or the way the payload is being constructed. To resolve this, please ensure that: 1. You are using the correct version of the VAPI SDK that supports Squads. 2. Your payload strictly follows the structure expected by the VAPI endpoint you are calling. 3. You have the latest documentation and that it matches the SDK version you are using. If the problem persists, I recommend reaching out to VAPI support for more detailed assistance. They can provide you with the correct payload structure and help troubleshoot any discrepancies between the documentation and the actual SDK behavior.
m
@Vapi what if i pass whole assistant payload instead of assistant id
v
@Mudassar If you pass the entire assistant payload instead of just the assistant ID, it should work as long as the payload structure matches what the VAPI expects for a Squad member. When you define a Squad, you typically have the option to either reference existing assistants by their IDs or define new assistants on the fly by providing their full configuration. Here's an example of what passing the entire assistant payload might look like:
Copy code
json
{
  "squad": {
    "members": [
      {
        "assistant": {
          "name": "Assistant One",
          "intents": [
            // ... define intents here
          ],
          "entities": [
            // ... define entities here
          ],
          // ... other assistant configuration
        }
      },
      {
        "assistant": {
          "name": "Assistant Two",
          // ... full assistant configuration
        }
      }
      // ... more members if necessary
    ]
  }
}
In this case, each member of the
members
array contains an
assistant
object with the full configuration for that assistant. Please note that the exact structure and fields required may vary based on the VAPI version and the specific implementation details. Always refer to the latest VAPI documentation for the correct format. If you're unsure whether your payload is correct or if you encounter any errors, it's best to contact VAPI support for clarification and assistance. They can provide you with the most accurate information and help ensure that your integration works smoothly.
m
@Vapi it gives me error like this Invalid Assistant. Errors: ["assistant.property squad should not exist"]
v
@Mudassar The error message you're receiving, "Invalid Assistant. Errors: ['assistant.property squad should not exist']", suggests that there's a mismatch between the expected schema for an assistant and the payload you're providing. It seems that the
squad
property is not expected within the assistant payload itself. When you're dealing with Squads, the
squad
property is typically used at a higher level to define the group of assistants that will work together. Each member within the
squad
is usually an individual assistant, identified either by an
assistantId
or by a full assistant payload, but without a
squad
property inside it. Here's a general structure of what the payload should look like when you're trying to define a Squad:
Copy code
json
{
  "squad": {
    "members": [
      {
        "assistantId": "information-gathering-assistant-id",
        // ... other properties if necessary
      },
      {
        "assistantId": "appointment-booking-assistant-id",
        // ... other properties if necessary
      }
      // ... more members if necessary
    ]
  }
}
Or, if you're defining the assistants inline:
Copy code
json
{
  "squad": {
    "members": [
      {
        "assistant": {
          // ... full assistant configuration, but no 'squad' property inside
        }
      },
      {
        "assistant": {
          // ... another full assistant configuration
        }
      }
      // ... more members if necessary
    ]
  }
}
Make sure that you're not including a
squad
property inside the
assistant
configuration. The
squad
should be a separate property at the root of your payload when defining a Squad. If you continue to experience issues, it would be best to reach out to VAPI support for further assistance. They can provide specific guidance based on the version of the API you're using and help you construct the correct payload.
m
@Vapi i returned this response in assistent-request, should i use something else
@Vapi when vapi hits my server with assistent-request payload i return this response, is it true
v
@Mudassar If VAPI is hitting your server with an
assistant-request
payload and you're returning a response with a
squad
property, that might be where the issue lies. The
assistant-request
is typically meant for handling a single assistant's logic, not for defining or managing a Squad. When responding to an
assistant-request
, you should return the appropriate response for that specific assistant, which could include the next action, a message to the user, or other assistant-specific data. The response should not include a
squad
property unless the API specifically allows for that in the context of the request you're handling. Here's an example of a typical response to an `assistant-request`:
Copy code
json
{
  "actions": [
    {
      "say": "What can I help you with today?"
    }
  ]
}
If you're trying to manage a Squad, this would usually be set up beforehand through the VAPI dashboard or via an API call that specifically deals with Squads. Once the Squad is set up, VAPI would manage the interactions between the different assistants in the Squad. If you're looking to dynamically create or modify a Squad in response to an
assistant-request
, that's not typically how the API is designed to work. You would need to set up the Squad outside of the assistant request/response cycle. To resolve this, make sure you're following the VAPI documentation for responding to an
assistant-request
. If you're trying to work with Squads, ensure that you're using the correct endpoints or methods for Squad management. If the documentation or the error messages are not clear, or if you're unsure about the correct approach, please reach out to VAPI support for more detailed guidance. They can help you understand the expected behavior and how to properly structure your responses.
m
@Vapi what is the correct approach then if i have to return squads on the fly
v
@Mudassar Creating or returning Squads on the fly in response to an
assistant-request
is not a standard operation for most voice APIs, as Squads are typically predefined and managed separately from individual assistant interactions. However, if VAPI supports dynamic Squad creation or modification, the correct approach would likely involve a separate API endpoint or a specific feature within the VAPI that allows for dynamic Squad management. This would not be done within the standard
assistant-request
response. Here's what you would generally need to do: 1. **Check the Documentation**: Review the VAPI documentation to see if there is a feature or endpoint for creating or modifying Squads dynamically. 2. **Use the Correct Endpoint**: If such a feature exists, use the designated API endpoint or method to create or modify the Squad. This might involve sending a separate HTTP request from your server to the VAPI endpoint responsible for Squad management. 3. **Handle Squad Logic Separately**: Keep the logic for handling individual assistant interactions (
assistant-request
) separate from the logic for managing Squads. They are usually distinct processes. 4. **Contact Support**: If the documentation does not provide clear guidance on dynamic Squad management, or if you're unsure how to proceed, reach out to VAPI support for assistance. They can tell you whether dynamic Squad creation is possible and, if so, how to implement it correctly. If VAPI does not support dynamic Squad creation, you would need to predefine your Squads before they are used in calls. Then, during an
assistant-request
, you would handle the logic for the individual assistant without trying to return or modify Squads on the fly. Please reach out to VAPI support for more info on this, as they will have the most accurate and up-to-date information on the capabilities of their API and how to use it for your specific use case.
m
@Vapi i am following this
v
@Mudassar Please ask support for more info on this.
m
@Vapi sorry i mean to say that i am following this docs https://docs.vapi.ai/squads-example
v
@Mudassar Thank you for clarifying. If you are following the documentation provided at https://docs.vapi.ai/squads-example and still encountering issues, it's important to ensure that you are adhering to the examples and guidelines exactly as they are presented. Based on the documentation for Squads, here are a few steps you can take to troubleshoot the issue: 1. **Review the Example**: Double-check the example provided in the documentation to ensure that your implementation matches the expected structure and syntax for defining a Squad. 2. **Check Your Version**: Verify that the version of the VAPI SDK or API you are using supports the features described in the documentation. There might be version-specific differences. 3. **Validate Your Payload**: Make sure that the payload you are sending back in response to an
assistant-request
is valid and matches the schema expected by VAPI. The error message you received earlier suggests that there might be a property in the payload that is not expected. 4. **Seek Clarification**: If the documentation is not clear or seems to be inconsistent with the behavior you are experiencing, reach out to VAPI support for clarification. They can provide specific guidance and help you understand the correct way to implement Squads based on the documentation. 5. **Error Handling**: Pay close attention to any error messages you receive, as they can provide insights into what might be going wrong. The error message about the
squad
property not existing indicates that there may be a misunderstanding about where and how the
squad
property should be used. If you need to return Squads on the fly and the documentation provides an example of how to do this, but it's not working as expected, it's possible there is an issue with the SDK or the documentation may be outdated. In such cases, VAPI support will be able to provide the most accurate assistance.
m
@Vapi @User @Shubham Bajaj guys please help. i am stuck badly in it
v
@Mudassar I'm here to help you. It seems like you're trying to mention someone for assistance, but as an AI, I can't directly notify individuals. However, I can guide you through the process. If you're following the Squads example from the VAPI documentation and are stuck, here's what you can do: 1. **Review the Squads Example**: Go through the example provided in the documentation again to ensure you haven't missed any steps. 2. **Check Your Code**: Compare your code with the example to ensure that you're implementing the Squad correctly. Pay special attention to the structure of the payload you're sending back. 3. **Error Messages**: Analyze any error messages you're receiving to understand what might be going wrong. The error message you mentioned earlier suggests that there's an issue with the structure of the payload. 4. **VAPI Support**: Since you're experiencing persistent issues, the best course of action is to contact VAPI support directly. They can provide specific assistance for your situation. You can usually reach out to them via email, support ticket, or through the developer dashboard. 5. **Community Forums**: If VAPI has community forums or a developer community, consider posting your issue there. Other developers who have faced similar challenges might be able to help. 6. **Update SDK**: Ensure that you're using the latest version of the VAPI SDK, as there might have been updates or bug fixes that address your issue. Please provide any additional details or error messages you're seeing, and I'll do my best to assist you further. If you need to contact VAPI support, I can guide you on how to formulate your request for help.
2 Views