-
Notifications
You must be signed in to change notification settings - Fork 2.8k
support agent.say in before_llm_cb #1460
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
Conversation
🦋 Changeset detectedLatest commit: 8ee3b09 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| "speech_id": speech_handle.id, | ||
| }, | ||
| ) | ||
| playing_lock.release() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we wrap playing_lock.release() in finally block?
something like
await playing_lock.acquire()
try:
...(existing logic)
finally:
playing_lock.release()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be okay as if the main speech failed we should stop the whole speech handle and its nested speeches.
|
Nice mate ! Took me a while to figure this out. I went a different route and since before_llm_cb is always called after user_stopped_speaking I create the handle there. async def delayed_starter_words_generator(event, agent):
await event.wait()
starter_words = None
if agent.starter_words:
starter_words = agent.starter_words
agent.starter_words = None
yield starter_words # Then yield the response
async def say_starter_words(agent):
start_time = time.perf_counter()
event = asyncio.Event()
gen = delayed_starter_words_generator(event, agent)
# Store the event on the agent to access it in before_llm_cb
agent.starter_words_event = event
await agent.say(gen)and then all you need to do is async def before_llm_cb(agent, chat_ctx):
logger.debug("Entering before_llm_cb.")
if hasattr(agent, 'starter_words_event'):
filler = random.choice(FILLER_OPTIONS)
agent.starter_words = filler
agent.starter_words_event.set()
agent.starter_words_event = NoneFor those scared that it might block their queue you can add fallbacks to force release. I put this there in case the PR is not approved for people that would face this problem and are considering writing monkey patches 🐒 Otherwise this is an important feature and it would be great to have it as part of the official SDK 👽 |
This pr supports calling
agent.sayinside abefore_llm_cb, it will playout the content of say first then the returned llm stream