With reference to this issue - <https://github.com...
# agents
p
With reference to this issue - https://github.com/livekit/agents/issues/3072 When this RuntimeError occurs - the exception is not exposed as an Error event in AgentSession. This error causes issues where the agent goes into infinite loop and does not generate an audio. As per issue comments - this seems to be resolved in
1.2.3
but same piece of code is again modified in
1.2.6
Changelog
1.2.3 - Fix RuntimeError on scheduling speech and on mark_generation_done by @jayeshp19 in #3032
1.2.6 - fix: check if scheduling_paused after on_user_turn_completed callback by @longcw in #3091
I am looking to upgrade to 1.2.6 but what is the recommendation to handle these silent exceptions? Has anyone added a catchall exception in their code?
@jolly-air-155 - would appreciate if you can comment on how we can add a catch all error to not have such silent failures. Thank you
j
you can always catch the RuntimeError when using
session.say
or
session.generate_reply
in
on_user_turn_completed
callback
👀 1
p
Copy code
Exception in callback AgentActivity._create_speech_task.\u003clocals\u003e._mark_done_if_needed(\u003cTask finishe...\u003e result=None\u003e) at /usr/local/lib/python3.11/site-packages/livekit/agents/voice/agent_activity.py:329\nhandle: \u003cHandle AgentActivity._create_speech_task.\u003clocals\u003e._mark_done_if_needed(\u003cTask finishe...\u003e result=None\u003e) at /usr/local/lib/python3.11/site-packages/livekit/agents/voice/agent_activity.py:329\u003e\nTraceback (most recent call last):\n  File \"/usr/local/lib/python3.11/asyncio/events.py\", line 84, in _run\n    self._context.run(self._callback, *self._args)\n  File \"/usr/local/lib/python3.11/site-packages/livekit/agents/voice/agent_activity.py\", line 331, in _mark_done_if_needed\n    speech_handle._mark_done()\n  File \"/usr/local/lib/python3.11/site-packages/livekit/agents/voice/speech_handle.py\", line 210, in _mark_done\n    self._mark_generation_done()\n  File \"/usr/local/lib/python3.11/site-packages/livekit/agents/voice/speech_handle.py\", line 201, in _mark_generation_done\n    raise RuntimeError(\"cannot use mark_generation_done: no active generation is running.\")\nRuntimeError: cannot use mark_generation_done: no active generation is running.
@jolly-air-155 - Thanks for responding. This is the traceback I see. Are you saying the
callback
referred here is
on_user_turn_completed
callback and handling the exception in this callback should fix such issues? Also the above exception is not sent to the code when it occurs, rather this exception is retrieved when closing the agent session. Is it expected?
The agent session when into the above exception state after interruption. Unable to replicate it. Not enabled preemptive generation. After going into this state the session was not recoverable and any new LLM calls made did not generate speech and it was stuck in this state. Only when the agent session ended (as user disconnected from call). The above exception was retrieved, until then the agent session was running the llm calls but not generating audio
j
okay I see, you are talking about the
_mark_generation_done
, it should be already fixed in https://github.com/livekit/agents/pull/3032/files, which version of agents are you using? can you share the result of
pip list | grep livekit
?
from your traceback, it seems you are using an old version before the fix
p
Yes - I am using 1.2.2. I did see the PR you are refering merged in 1.2.3 I also see a new PR created at the same code changes in 1.2.6 - https://github.com/livekit/agents/pull/3091 I am looking to upgrade to 1.2.6. That should have all code fixes for this correct? Also to avoid such Runtime exception or exceptions that are not sent as
Error
event in agent session. Is there a catchall exception I can add?
j
yes, upgrade to agents>=1.2.3 will fix this, and feel free to report a bug if you see any exception that is not sent to the error callback but causes the agent unresponsive
p
Ack, will upgrade. But is there on way to do a catch all exception without having to explicitly report it as a bug
r
hi @proud-match-31207 did it fix the issue ? My agent stops speaking once this error happens
p
Yes haven't noticed this after upgrading to 1.2.6
r
@aloof-table-88981
thanks @proud-match-31207
a
We are also facing this. Will upgrade to >=1.2.3
r
@little-bear-29830