-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat: answering machine detection #4906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
ce60b71
add AMD interface
chenghao-mou 26d3aaa
add amd event emitter
chenghao-mou 5672b37
update event emitter
chenghao-mou 7e67624
add amd hold
chenghao-mou 1786e0c
refactor amd result and example
chenghao-mou 1131225
Merge branch 'main' into feat/amd
chenghao-mou b69884e
minor fixes
chenghao-mou 44d845f
clean up example
chenghao-mou a3222bd
clean up and refactoring
chenghao-mou 404bc2b
fix example
chenghao-mou 3be962f
disable AMD after first use
chenghao-mou 8517423
Merge branch 'main' into feat/amd
chenghao-mou 0ee8791
refactoring
chenghao-mou 1b78498
use function call for prediction
chenghao-mou 9dc196c
exclude silence from speech duration calculation
chenghao-mou 56c0b38
minor refactoring
chenghao-mou 9baf7df
more fixes
chenghao-mou 865737a
Merge branch 'main' into feat/amd
chenghao-mou 3c845c3
fix type issues
chenghao-mou 348e1a3
move amd out of session
chenghao-mou 25bcf65
use llm prediction when timing out
chenghao-mou 0feb3e7
refactor based on feedback
chenghao-mou 46eca3c
reformat
chenghao-mou 772b731
add docstring
chenghao-mou 0b4bd23
update to use str enum
chenghao-mou 8790091
use string match in example instead
chenghao-mou a7925e2
rename amd -> machine detection/detector
chenghao-mou 382c9b4
address comments
chenghao-mou efa2286
clean up autocomplete error
chenghao-mou 265bdf1
rename to amd
chenghao-mou 91dadc0
address comments
chenghao-mou 4cfcae9
rename
chenghao-mou 6751e9a
address more comments
chenghao-mou 8bed855
fix type issues
chenghao-mou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import logging | ||
|
|
||
| from dotenv import load_dotenv | ||
|
|
||
| from livekit.agents import ( | ||
| AMD, | ||
| Agent, | ||
| AgentServer, | ||
| AgentSession, | ||
| JobContext, | ||
| JobProcess, | ||
| cli, | ||
| inference, | ||
| ) | ||
| from livekit.plugins import silero | ||
| from livekit.plugins.turn_detector.multilingual import MultilingualModel | ||
|
|
||
| logger = logging.getLogger("basic-agent") | ||
|
|
||
| load_dotenv("../agents/.env") | ||
|
|
||
|
|
||
| class MyAgent(Agent): | ||
| def __init__(self) -> None: | ||
| super().__init__( | ||
| instructions=( | ||
| "You are reaching out to a customer with a phone call. " | ||
| "You are calling to see if they are home. " | ||
| "You might encounter an answering machine with a DTMF menu or IVR system. " | ||
| "If you do, you will try to leave a message to ask them to call back." | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| server = AgentServer() | ||
|
|
||
|
|
||
| def prewarm(proc: JobProcess): | ||
| proc.userdata["vad"] = silero.VAD.load() | ||
|
|
||
|
|
||
| server.setup_fnc = prewarm | ||
|
|
||
|
|
||
| @server.rtc_session() | ||
| async def entrypoint(ctx: JobContext): | ||
| ctx.log_context_fields = { | ||
| "room": ctx.room.name, | ||
| } | ||
| session = AgentSession( | ||
| stt=inference.STT("deepgram/nova-3", language="multi"), | ||
| llm=inference.LLM("openai/gpt-4.1-mini"), | ||
| tts=inference.TTS("cartesia/sonic-3", voice="9626c31c-bec5-4cca-baa8-f8ba9e84c8bc"), | ||
| turn_detection=MultilingualModel(), | ||
| vad=ctx.proc.userdata["vad"], | ||
| preemptive_generation=True, | ||
| ) | ||
|
|
||
| await session.start( | ||
| agent=MyAgent(), | ||
| room=ctx.room, | ||
| ) | ||
|
|
||
| async with AMD(session, llm="openai/gpt-5-mini") as detector: | ||
| result = await detector.execute() | ||
|
|
||
| if result.category == "human": | ||
| logger.info("human answered the call, proceeding with normal conversation") | ||
| elif result.category == "machine-ivr": | ||
| logger.info("ivr menu detected, starting navigation") | ||
| elif result.category == "machine-vm": | ||
| logger.info("voicemail detected, leaving a message") | ||
| speech_handle = session.generate_reply( | ||
| instructions=( | ||
| "You've reached voicemail. Leave a brief message asking " | ||
| "the customer to call back." | ||
| ), | ||
| ) | ||
| await speech_handle.wait_for_playout() | ||
| session.shutdown() | ||
| elif result.category == "machine-unavailable": | ||
| logger.info("mailbox unavailable, ending call") | ||
| session.shutdown() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| cli.run_app(server) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from .classifier import AMDCategory, AMDResult | ||
| from .detector import AMD | ||
|
|
||
| __all__ = ["AMD", "AMDCategory", "AMDResult"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.