Class: LiveKit::AgentDispatchServiceClient

Inherits:
Twirp::Client
  • Object
show all
Includes:
AuthMixin
Defined in:
lib/livekit/agent_dispatch_service_client.rb

Overview

Client for LiveKit’s Agent Dispatch Service, which manages agent assignments to rooms This client handles creating, deleting, and retrieving agent dispatches

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AuthMixin

#auth_header

Constructor Details

#initialize(base_url, api_key: nil, api_secret: nil) ⇒ AgentDispatchServiceClient

Returns a new instance of AgentDispatchServiceClient.



13
14
15
16
17
# File 'lib/livekit/agent_dispatch_service_client.rb', line 13

def initialize(base_url, api_key: nil, api_secret: nil)
  super(File.join(Utils.to_http_url(base_url), "/twirp"))
  @api_key = api_key
  @api_secret = api_secret
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



11
12
13
# File 'lib/livekit/agent_dispatch_service_client.rb', line 11

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



11
12
13
# File 'lib/livekit/agent_dispatch_service_client.rb', line 11

def api_secret
  @api_secret
end

Instance Method Details

#create_dispatch(room_name, agent_name, metadata: nil) ⇒ LiveKit::Proto::AgentDispatch

Creates a new agent dispatch for a named agent

Parameters:

  • The room to dispatch the agent to

  • The name of the agent to dispatch

  • (defaults to: nil)

    Optional metadata to include with the dispatch

Returns:

  • Dispatch that was just created



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/livekit/agent_dispatch_service_client.rb', line 24

def create_dispatch(
  # room to dispatch agent to
  room_name,
  # agent to dispatch
  agent_name,
  # optional, metadata to send along with the job
  metadata: nil
)
  request = Proto::CreateAgentDispatchRequest.new(
    room: room_name,
    agent_name: agent_name,
    metadata: ,
  )
  self.rpc(
    :CreateDispatch,
    request,
    headers: auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room_name)),
  )
end

#delete_dispatch(dispatch_id, room_name) ⇒ LiveKit::Proto::AgentDispatch

Deletes an existing agent dispatch

Parameters:

  • The ID of the dispatch to delete

  • The room name associated with the dispatch

Returns:

  • AgentDispatch record that was deleted



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/livekit/agent_dispatch_service_client.rb', line 48

def delete_dispatch(dispatch_id, room_name)
  request = Proto::DeleteAgentDispatchRequest.new(
    dispatch_id: dispatch_id,
    room: room_name,
  )
  self.rpc(
    :DeleteDispatch,
    request,
    headers: auth_header(VideoGrant.new(roomAdmin: true, room: room_name)),
  )
end

#get_dispatch(dispatch_id, room_name) ⇒ LiveKit::Proto::AgentDispatch?

Retrieves a specific agent dispatch by ID

Parameters:

  • The ID of the dispatch to retrieve

  • The room name associated with the dispatch

Returns:

  • The agent dispatch if found, nil otherwise



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/livekit/agent_dispatch_service_client.rb', line 64

def get_dispatch(dispatch_id, room_name)
  request = Proto::ListAgentDispatchRequest.new(
    dispatch_id: dispatch_id,
    room: room_name,
  )
  res = self.rpc(
    :ListDispatch,
    request,
    headers: auth_header(VideoGrant.new(roomAdmin: true, room: room_name)),
  )
  if res.agent_dispatches.size > 0
    return res.agent_dispatches[0]
  end
  nil
end

#list_dispatch(room_name) ⇒ Array<LiveKit::Proto::AgentDispatch>

Lists all agent dispatches for a specific room

Parameters:

  • The room name to list dispatches for

Returns:

  • Array of agent dispatches



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/livekit/agent_dispatch_service_client.rb', line 83

def list_dispatch(room_name)
  request = Proto::ListAgentDispatchRequest.new(
    room: room_name,
  )
  res = self.rpc(
    :ListDispatch,
    request,
    headers: auth_header(VideoGrant.new(roomAdmin: true, room: room_name)),
  )
  res.agent_dispatches
end