11import Foundation
2+ import LiveKit
23
34/// Main configuration for a conversation session
45public struct ConversationConfig : Sendable {
@@ -15,6 +16,51 @@ public struct ConversationConfig: Sendable {
1516 /// Called when the agent disconnects or the conversation ends
1617 public var onDisconnect : ( @Sendable ( ) -> Void ) ?
1718
19+ /// Called whenever the startup state transitions
20+ public var onStartupStateChange : ( @Sendable ( ConversationStartupState ) -> Void ) ?
21+
22+ /// Controls timings and retry behavior for the initialization handshake
23+ public var startupConfiguration : ConversationStartupConfiguration
24+
25+ /// Controls microphone pipeline behaviour and VAD callbacks.
26+ public var audioConfiguration : AudioPipelineConfiguration ?
27+
28+ /// Called when a startup-related error occurs
29+ public var onError : ( @Sendable ( ConversationError ) -> Void ) ?
30+
31+ /// Called when LiveKit detects speech activity while muted.
32+ public var onSpeechActivity : ( @Sendable ( SpeechActivityEvent ) -> Void ) ?
33+
34+ /// Called for each agent response with the associated event identifier.
35+ public var onAgentResponse : ( @Sendable ( _ text: String , _ eventId: Int ) -> Void ) ?
36+
37+ /// Called when an agent response correction is received.
38+ public var onAgentResponseCorrection : ( @Sendable ( _ original: String , _ corrected: String , _ eventId: Int ) -> Void ) ?
39+
40+ /// Called for each user transcript event.
41+ public var onUserTranscript : ( @Sendable ( _ text: String , _ eventId: Int ) -> Void ) ?
42+
43+ /// Called when conversation metadata arrives.
44+ public var onConversationMetadata : ( @Sendable ( ConversationMetadataEvent ) -> Void ) ?
45+
46+ /// Called when the agent emits a tool response event.
47+ public var onAgentToolResponse : ( @Sendable ( AgentToolResponseEvent ) -> Void ) ?
48+
49+ /// Called when the agent detects an interruption.
50+ public var onInterruption : ( @Sendable ( _ eventId: Int ) -> Void ) ?
51+
52+ /// Called whenever a VAD score is emitted.
53+ public var onVadScore : ( @Sendable ( _ score: Double ) -> Void ) ?
54+
55+ /// Called when audio alignment metadata is emitted.
56+ public var onAudioAlignment : ( @Sendable ( AudioAlignment ) -> Void ) ?
57+
58+ /// Called when feedback availability changes.
59+ public var onCanSendFeedbackChange : ( @Sendable ( Bool ) -> Void ) ?
60+
61+ /// Called when a client tool call is received without a registered handler.
62+ public var onUnhandledClientToolCall : ( @Sendable ( ClientToolCallEvent ) -> Void ) ?
63+
1864 public init (
1965 agentOverrides: AgentOverrides ? = nil ,
2066 ttsOverrides: TTSOverrides ? = nil ,
@@ -24,6 +70,21 @@ public struct ConversationConfig: Sendable {
2470 userId: String ? = nil ,
2571 onAgentReady: ( @Sendable ( ) -> Void ) ? = nil ,
2672 onDisconnect: ( @Sendable ( ) -> Void ) ? = nil ,
73+ onStartupStateChange: ( @Sendable ( ConversationStartupState ) -> Void ) ? = nil ,
74+ startupConfiguration: ConversationStartupConfiguration = . default,
75+ audioConfiguration: AudioPipelineConfiguration ? = nil ,
76+ onError: ( @Sendable ( ConversationError ) -> Void ) ? = nil ,
77+ onSpeechActivity: ( @Sendable ( SpeechActivityEvent ) -> Void ) ? = nil ,
78+ onAgentResponse: ( @Sendable ( _ text: String , _ eventId: Int ) -> Void ) ? = nil ,
79+ onAgentResponseCorrection: ( @Sendable ( _ original: String , _ corrected: String , _ eventId: Int ) -> Void ) ? = nil ,
80+ onUserTranscript: ( @Sendable ( _ text: String , _ eventId: Int ) -> Void ) ? = nil ,
81+ onConversationMetadata: ( @Sendable ( ConversationMetadataEvent ) -> Void ) ? = nil ,
82+ onAgentToolResponse: ( @Sendable ( AgentToolResponseEvent ) -> Void ) ? = nil ,
83+ onInterruption: ( @Sendable ( _ eventId: Int ) -> Void ) ? = nil ,
84+ onVadScore: ( @Sendable ( _ score: Double ) -> Void ) ? = nil ,
85+ onAudioAlignment: ( @Sendable ( AudioAlignment ) -> Void ) ? = nil ,
86+ onCanSendFeedbackChange: ( @Sendable ( Bool ) -> Void ) ? = nil ,
87+ onUnhandledClientToolCall: ( @Sendable ( ClientToolCallEvent ) -> Void ) ? = nil ,
2788 ) {
2889 self . agentOverrides = agentOverrides
2990 self . ttsOverrides = ttsOverrides
@@ -33,6 +94,21 @@ public struct ConversationConfig: Sendable {
3394 self . userId = userId
3495 self . onAgentReady = onAgentReady
3596 self . onDisconnect = onDisconnect
97+ self . onStartupStateChange = onStartupStateChange
98+ self . startupConfiguration = startupConfiguration
99+ self . audioConfiguration = audioConfiguration
100+ self . onError = onError
101+ self . onSpeechActivity = onSpeechActivity
102+ self . onAgentResponse = onAgentResponse
103+ self . onAgentResponseCorrection = onAgentResponseCorrection
104+ self . onUserTranscript = onUserTranscript
105+ self . onConversationMetadata = onConversationMetadata
106+ self . onAgentToolResponse = onAgentToolResponse
107+ self . onInterruption = onInterruption
108+ self . onVadScore = onVadScore
109+ self . onAudioAlignment = onAudioAlignment
110+ self . onCanSendFeedbackChange = onCanSendFeedbackChange
111+ self . onUnhandledClientToolCall = onUnhandledClientToolCall
36112 }
37113}
38114
@@ -101,6 +177,21 @@ extension ConversationConfig {
101177 userId: userId,
102178 onAgentReady: onAgentReady,
103179 onDisconnect: onDisconnect,
180+ onStartupStateChange: onStartupStateChange,
181+ startupConfiguration: startupConfiguration,
182+ audioConfiguration: audioConfiguration,
183+ onError: onError,
184+ onSpeechActivity: onSpeechActivity,
185+ onAgentResponse: onAgentResponse,
186+ onAgentResponseCorrection: onAgentResponseCorrection,
187+ onUserTranscript: onUserTranscript,
188+ onConversationMetadata: onConversationMetadata,
189+ onAgentToolResponse: onAgentToolResponse,
190+ onInterruption: onInterruption,
191+ onVadScore: onVadScore,
192+ onAudioAlignment: onAudioAlignment,
193+ onCanSendFeedbackChange: onCanSendFeedbackChange,
194+ onUnhandledClientToolCall: onUnhandledClientToolCall,
104195 )
105196 }
106197}
0 commit comments