Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/agents/run_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import copy
import dataclasses
import json
from collections import deque
from collections.abc import Callable, Mapping, Sequence
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, Generic, Literal, Optional, Union, cast
Expand Down Expand Up @@ -2089,10 +2090,10 @@ def _build_agent_map(initial_agent: Agent[Any]) -> dict[str, Agent[Any]]:
Dictionary mapping agent names to agent instances.
"""
agent_map: dict[str, Agent[Any]] = {}
queue = [initial_agent]
queue: deque[Agent[Any]] = deque([initial_agent])

while queue:
current = queue.pop(0)
current = queue.popleft()
if current.name in agent_map:
continue
agent_map[current.name] = current
Expand Down
9 changes: 5 additions & 4 deletions src/agents/voice/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import base64
from collections import deque
from collections.abc import AsyncIterator
from typing import Any

Expand Down Expand Up @@ -52,9 +53,9 @@ def __init__(
self._turn_text_buffer = ""
self._queue: asyncio.Queue[VoiceStreamEvent] = asyncio.Queue()
self._tasks: list[asyncio.Task[Any]] = []
self._ordered_tasks: list[
asyncio.Queue[VoiceStreamEvent | None]
] = [] # New: list to hold local queues for each text segment
self._ordered_tasks: deque[asyncio.Queue[VoiceStreamEvent | None]] = (
deque()
) # New: deque to hold local queues for each text segment
self._dispatcher_task: asyncio.Task[Any] | None = (
None # Task to dispatch audio chunks in order
)
Expand Down Expand Up @@ -248,7 +249,7 @@ async def _dispatch_audio(self):
break
await asyncio.sleep(0)
continue
local_queue = self._ordered_tasks.pop(0)
local_queue = self._ordered_tasks.popleft()
while True:
chunk = await local_queue.get()
if chunk is None:
Expand Down