agents
agents copied to clipboard
Race condition in (or near) ChatContext
Bug Description
I have a time-consuming process in one of my function_tool's. This process appends utterances to ChatContext via say and generate_reply I have noticed that the following scenario is possible:
- User speaks and its utterance is appended to
ChatContext. - Agent decides to do a
function_call. - User speaks again.
function_callfrom (2) concludes and appends an agent's utterance toChatContext.- User utterance from (3) is appended to
ChatContext - Agent speaks.
- ChatContext goes to an LLM to generate response. (6 and 7 may be in different order, I am not sure)
- Agent immediately responds without waiting for a user, because it sees an utterace from (5).
Synthetic example:
- Agent: Hi, give me the street name and number.
- User: Oxford road... hm... wait.. Have it, 61.
- Agent: You provided a street name only and I need a number, too. Thank you for the number.
It obviously is very confusing an unnatural.
Can someone point me where to look for a possible bug or improvement? ChatContext logic is somehow convoluted.
Expected Behavior
V1 - agent ignores late utterance.
- Agent: Hi, give me the street name and number.
- User: Oxford road... hm... wait.. Have it, 61.
- Agent: You provided a street name only and I need a number, too.
- User: I think i told you it is 61.
V2 - agent retriggers function_tool
- Agent: Hi, give me the street name and number.
- User: Oxford road... hm... wait.. Have it, 61.
- Agent: Thank you.
Reproduction Steps
1. Create a lengty `function_call` that appends to `ChatContext`
2. Talk to an agent to trigger a function call then start speaking again while the `function_call` is in progress.
Operating System
python:3.13-slim-bookworm
Models Used
google.LLM(model="gemini-2.5-flash")
Package Versions
Package Version
---------------------------------------- ---------------
aiofiles 25.1.0
aiohappyeyeballs 2.6.1
aiohttp 3.13.2
aiosignal 1.4.0
annotated-types 0.7.0
anthropic 0.74.0
anyio 4.11.0
arrow 1.4.0
attrs 25.4.0
av 15.1.0
babel 2.17.0
backoff 2.2.1
beanie 2.0.0
cachetools 6.2.2
certifi 2025.11.12
cffi 2.0.0
charset-normalizer 3.4.4
click 8.2.1
colorama 0.4.6
coloredlogs 15.0.1
debugpy 1.8.17
deepeval 3.7.2
distro 1.9.0
dnspython 2.8.0
docstring-parser 0.17.0
eval-type-backport 0.3.0
execnet 2.1.2
filelock 3.20.0
flatbuffers 25.9.23
frozenlist 1.8.0
fsspec 2025.10.0
google-api-core 2.28.1
google-api-python-client 2.187.0
google-auth 2.43.0
google-auth-httplib2 0.2.1
google-auth-oauthlib 1.2.2
google-cloud-speech 2.34.0
google-cloud-texttospeech 2.33.0
google-genai 1.51.0
googleapis-common-protos 1.72.0
grpcio 1.76.0
grpcio-status 1.76.0
h11 0.16.0
hf-xet 1.2.0
httpcore 1.0.9
httplib2 0.31.0
httpx 0.28.1
huggingface-hub 0.36.0
humanfriendly 10.0
idna 3.11
importlib-metadata 8.7.0
inform 1.35
iniconfig 2.3.0
jinja2 3.1.6
jiter 0.12.0
lazy-model 0.3.0
livekit 1.0.19
livekit-agents 1.3.2
livekit-api 1.0.7
livekit-blingfire 1.0.0
livekit-plugins-google 1.3.2
livekit-plugins-openai 1.3.2
livekit-plugins-silero 1.3.2
livekit-plugins-turn-detector 1.3.2
livekit-protocol 1.1.0
markdown-it-py 4.0.0
markupsafe 3.0.3
mdurl 0.1.2
mpmath 1.3.0
multidict 6.7.0
nest-asyncio 1.6.0
nestedtext 3.7
networkx 3.5
numpy 2.3.5
oauthlib 3.3.1
ollama 0.6.1
onnxruntime 1.23.1
openai 2.8.1
opentelemetry-api 1.38.0
opentelemetry-exporter-otlp 1.38.0
opentelemetry-exporter-otlp-proto-common 1.38.0
opentelemetry-exporter-otlp-proto-grpc 1.38.0
opentelemetry-exporter-otlp-proto-http 1.38.0
opentelemetry-proto 1.38.0
opentelemetry-sdk 1.38.0
opentelemetry-semantic-conventions 0.59b0
packaging 25.0
pillow 12.0.0
pluggy 1.6.0
portalocker 3.2.0
posthog 5.4.0
prometheus-client 0.23.1
propcache 0.4.1
proto-plus 1.26.1
protobuf 6.33.1
psutil 7.1.3
pyasn1 0.6.1
pyasn1-modules 0.4.2
pycparser 2.23
pydantic 2.12.4
pydantic-core 2.41.5
pydantic-settings 2.12.0
pyfiglet 1.0.4
pygments 2.19.2
pyjwt 2.10.1
pymongo 4.15.4
pyparsing 3.2.5
pytest 9.0.1
pytest-asyncio 1.3.0
pytest-repeat 0.9.4
pytest-rerunfailures 16.1
pytest-xdist 3.8.0
python-dateutil 2.9.0.post0
python-dotenv 1.2.1
pyyaml 6.0.3
regex 2025.11.3
requests 2.32.5
requests-oauthlib 2.0.0
rich 14.2.0
rsa 4.9.1
safetensors 0.6.2
sentry-sdk 2.45.0
setuptools 80.9.0
shellingham 1.5.4
six 1.17.0
sniffio 1.3.1
sounddevice 0.5.3
sympy 1.14.0
tabulate 0.9.0
tenacity 9.1.2
tokenizers 0.22.1
torch 2.9.1+cpu
tqdm 4.67.1
transformers 4.57.1
typer 0.20.0
types-protobuf 6.32.1.20251105
typing-extensions 4.15.0
typing-inspection 0.4.2
tzdata 2025.2
uritemplate 4.2.0
urllib3 2.5.0
watchfiles 1.1.1
websockets 15.0.1
wheel 0.45.1
yarl 1.22.0
zipp 3.23.0
Session/Room/Call IDs
No response
Proposed Solution
Additional Context
No response
Screenshots and Recordings
No response