Skip to main content

Agent Runtime with iOS

VideoSDK empowers you to integrate an AI voice agent into your iOS app within minutes. This guide shows you how to connect an iOS (SwiftUI) frontend with an AI agent created and configured entirely from the VideoSDK dashboard.

Prerequisites

important

You need a VideoSDK account to generate a token and an agent from the dashboard.

Step 1: Clone the sample project

Clone the repository to your local environment.

git clone https://github.com/videosdk-live/agents-quickstart.git
cd mobile-quickstarts/ios/

Step 2: Environment Configuration

Create a Meeting Room

Create a meeting room using the VideoSDK API:

curl -X POST https://api.videosdk.live/v2/rooms \
-H "Authorization: YOUR_VIDEOSDK_AUTH_TOKEN" \
-H "Content-Type: application/json"

Use the returned roomId in your configuration files.

Configuration Files

Update the following files with your credentials. The Agent and Version IDs will be retrieved in a later step.

MeetingViewController.swift (line 14):

var token = "YOUR_VIDEOSDK_AUTH_TOKEN" // Add Your token here
var agentId = "YOUR_AGENT_ID"
var versionId = "YOUR_VERSION_ID"

JoinScreenView.swift (line 13):

let meetingId: String = "YOUR_MEETING_ID"

Step 3: iOS Frontend Modifications

Step 1: Add Connect Agent Button

In MeetingView.swift, add a button to connect the agent.

MeetingView.swift
// Add this button to your view hierarchy
Button(action: {
meetingVC.connectAgent()
}) {
Text("Connect Agent")
}
.disabled(meetingVC.isAgentConnected)

Step 2: Implement Connect Logic

In MeetingViewController.swift, add the logic to call the dispatch API.

MeetingViewController.swift
// Add state to track if the agent is connected
@Published var isAgentConnected = false

// ...

func connectAgent() {
guard let url = URL(string: "https://api.videosdk.live/v2/agent/general/dispatch") else { return }

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue(token, forHTTPHeaderField: "Authorization")

let body: [String: Any] = [
"agentId": agentId,
"meetingId": room?.id ?? "",
"versionId": versionId
]

request.httpBody = try? JSONSerialization.data(withJSONObject: body)

URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("Connect error: \(error.localizedDescription)")
return
}
if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 {
DispatchQueue.main.async {
self.isAgentConnected = true
print("Agent connected successfully")
}
} else {
print("Failed to connect agent")
}
}.resume()
}

Step 4: Creating the AI Agent from Dashboard (No-Code)

Step 1: Create Your Agent

First, follow our detailed guide to Build a Custom Voice AI Agent in Minutes. This will walk you through creating the agent's persona, configuring its pipeline (Realtime or Cascading), and testing it directly from the dashboard.

Step 2: Get Agent and Version ID

Once your agent is created, you need to get its agentId and versionId to connect it to your frontend application.

  1. After creating your agent, go to the agent's page and find the JSON editor on right side. Copy the agentId.

  2. To get the versionId, click on 3 dots besides Deploy button and click on "Version History" in it. Copy the version id via copy button of the version you want.

Get agentId and versionId

Step 3: Configure IDs in Frontend

Now, update your MeetingViewController.swift file with these IDs.

MeetingViewController.swift
var agentId = "paste_your_agent_id_here"
var versionId = "paste_your_version_id_here"

Step 5: Run the iOS Frontend

  1. Open Xcode:

    open videosdk-agents-quickstart-ios.xcodeproj
  2. Configure your development team:

    • Select the project in Xcode
    • Go to "Signing & Capabilities"
    • Select your development team
  3. Build and run:

    • Select your target device or simulator
    • Press Cmd + R to build and run

Step 6: Connect and Interact

  1. Join the meeting from the app and allow microphone permissions.
  2. When you join, click the "Connect Agent" button to call the agent into the meeting.
  3. Talk to the agent in real time.

Troubleshooting

Common Issues

  1. Build Errors:

    • Ensure Xcode 15.0+ is installed
    • Check iOS deployment target (13.0+)
    • Verify VideoSDK package dependency
  2. Authentication Issues:

    • Verify VIDEOSDK_AUTH_TOKEN in MeetingViewController.swift
    • Check token permissions include allow_join
  3. Meeting Connection Issues:

    • Ensure YOUR_MEETING_ID is correct
    • Verify network connectivity
    • Check VideoSDK account status
  4. AI Agent Issues:

    • Verify agentId and versionId are set correctly
    • Check for errors in the Xcode console when connecting the agent.

Got a Question? Ask us on discord