From 7432347a941d46758fc6692d4b4b0df190958d99 Mon Sep 17 00:00:00 2001 From: Aviral Garg Date: Fri, 21 Mar 2025 13:25:46 -0700 Subject: [PATCH 1/3] Fix circular dependency in voice streamed example by renaming agents.py to my_workflow.py --- examples/voice/streamed/main.py | 8 +++++++- examples/voice/streamed/{agents.py => my_workflow.py} | 0 2 files changed, 7 insertions(+), 1 deletion(-) rename examples/voice/streamed/{agents.py => my_workflow.py} (100%) diff --git a/examples/voice/streamed/main.py b/examples/voice/streamed/main.py index aef3b36e..c429890a 100644 --- a/examples/voice/streamed/main.py +++ b/examples/voice/streamed/main.py @@ -13,7 +13,13 @@ from agents.voice import StreamedAudioInput, VoicePipeline -from .agents import MyWorkflow +# Use absolute import when running as script directly +try: + # First try relative import (for package use) + from .my_workflow import MyWorkflow +except ImportError: + # Fall back to direct import (for script use) + from my_workflow import MyWorkflow CHUNK_LENGTH_S = 0.05 # 100ms SAMPLE_RATE = 24000 diff --git a/examples/voice/streamed/agents.py b/examples/voice/streamed/my_workflow.py similarity index 100% rename from examples/voice/streamed/agents.py rename to examples/voice/streamed/my_workflow.py From 9473c788bad6f3bfb2ca88e03a1493e31a238ed8 Mon Sep 17 00:00:00 2001 From: Aviral Garg Date: Fri, 21 Mar 2025 16:18:04 -0700 Subject: [PATCH 2/3] Fix type-checking for circular dependency in voice streamed example --- examples/voice/streamed/main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/voice/streamed/main.py b/examples/voice/streamed/main.py index c429890a..230738c4 100644 --- a/examples/voice/streamed/main.py +++ b/examples/voice/streamed/main.py @@ -13,13 +13,13 @@ from agents.voice import StreamedAudioInput, VoicePipeline -# Use absolute import when running as script directly -try: - # First try relative import (for package use) +# Use absolute or relative import based on context +if __name__ == "__main__": + # When running as script, use absolute import + from my_workflow import MyWorkflow # type: ignore +else: + # When imported as module, use relative import from .my_workflow import MyWorkflow -except ImportError: - # Fall back to direct import (for script use) - from my_workflow import MyWorkflow CHUNK_LENGTH_S = 0.05 # 100ms SAMPLE_RATE = 24000 From fdf340495bf3e444e150ac069537acb1a1d9f659 Mon Sep 17 00:00:00 2001 From: Aviral Garg Date: Fri, 21 Mar 2025 16:26:19 -0700 Subject: [PATCH 3/3] Fix circular dependency in voice streamed example with cleaner import pattern --- examples/voice/streamed/main.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/voice/streamed/main.py b/examples/voice/streamed/main.py index 230738c4..95e93791 100644 --- a/examples/voice/streamed/main.py +++ b/examples/voice/streamed/main.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +from typing import TYPE_CHECKING import numpy as np import sounddevice as sd @@ -13,13 +14,18 @@ from agents.voice import StreamedAudioInput, VoicePipeline -# Use absolute or relative import based on context -if __name__ == "__main__": - # When running as script, use absolute import - from my_workflow import MyWorkflow # type: ignore -else: - # When imported as module, use relative import +# Import MyWorkflow class - handle both module and package use cases +if TYPE_CHECKING: + # For type checking, use the relative import from .my_workflow import MyWorkflow +else: + # At runtime, try both import styles + try: + # Try relative import first (when used as a package) + from .my_workflow import MyWorkflow + except ImportError: + # Fall back to direct import (when run as a script) + from my_workflow import MyWorkflow CHUNK_LENGTH_S = 0.05 # 100ms SAMPLE_RATE = 24000