1111 MetricsCollectedEvent ,
1212 RunContext ,
1313 cli ,
14+ inference ,
1415 metrics ,
1516 room_io ,
1617)
17- from livekit .agents .inference .bargein import BargeinDetector
1818from livekit .agents .llm import function_tool
1919from livekit .plugins import silero
2020from livekit .plugins .turn_detector .multilingual import MultilingualModel
@@ -37,7 +37,7 @@ def __init__(self) -> None:
3737 "you will speak english to the user" ,
3838 )
3939
40- async def on_enter (self ):
40+ async def on_enter (self ) -> None :
4141 # when the agent is added to the session, it'll generate a reply
4242 # according to its instructions
4343 self .session .generate_reply ()
@@ -47,7 +47,7 @@ async def on_enter(self):
4747 @function_tool
4848 async def lookup_weather (
4949 self , context : RunContext , location : str , latitude : str , longitude : str
50- ):
50+ ) -> str :
5151 """Called when the user asks for weather related information.
5252 Ensure the user's location (city or region) is provided.
5353 When given a location, please estimate the latitude and longitude of the location and
@@ -67,20 +67,20 @@ async def lookup_weather(
6767server = AgentServer ()
6868
6969
70- def prewarm (proc : JobProcess ):
70+ def prewarm (proc : JobProcess ) -> None :
7171 proc .userdata ["vad" ] = silero .VAD .load ()
7272
7373
7474server .setup_fnc = prewarm
7575
7676
7777@server .rtc_session ()
78- async def entrypoint (ctx : JobContext ):
78+ async def entrypoint (ctx : JobContext ) -> None :
7979 # each log entry will include these fields
8080 ctx .log_context_fields = {
8181 "room" : ctx .room .name ,
8282 }
83- session = AgentSession (
83+ session : AgentSession = AgentSession (
8484 # Speech-to-text (STT) is your agent's ears, turning the user's speech into text that the LLM can understand
8585 # See all available models at https://docs.livekit.io/agents/models/stt/
8686 stt = "deepgram/nova-3" ,
@@ -94,7 +94,7 @@ async def entrypoint(ctx: JobContext):
9494 # See more at https://docs.livekit.io/agents/build/turns
9595 turn_detection = MultilingualModel (),
9696 vad = ctx .proc .userdata ["vad" ],
97- bargein_detector = BargeinDetector (),
97+ bargein_detector = inference . BargeinDetector (),
9898 # allow the LLM to generate a response while waiting for the end of turn
9999 # See more at https://docs.livekit.io/agents/build/audio/#preemptive-generation
100100 preemptive_generation = True ,
@@ -108,11 +108,11 @@ async def entrypoint(ctx: JobContext):
108108 usage_collector = metrics .UsageCollector ()
109109
110110 @session .on ("metrics_collected" )
111- def _on_metrics_collected (ev : MetricsCollectedEvent ):
111+ def _on_metrics_collected (ev : MetricsCollectedEvent ) -> None :
112112 metrics .log_metrics (ev .metrics )
113113 usage_collector .collect (ev .metrics )
114114
115- async def log_usage ():
115+ async def log_usage () -> None :
116116 summary = usage_collector .get_summary ()
117117 logger .info (f"Usage: { summary } " )
118118
0 commit comments