Hi everyone, I am building a voice agent that can ...
# agents
l
Hi everyone, I am building a voice agent that can simulate particular conversation template. In that conversation, I need to implement a 30 seconds wait time, where agents becomes silent and doesn't listen the user. After 30 seconds time is up, it needs to continue the conversation. I tried agent function tools and hardcoding it but failed to implement it. Agent was misbehaving in both cases. (Reacted to speech and forgot the timer) My stach is: backend: fast api frontend react Does anyone know how to accomplish it?
b
Here are a few options: The most straightforward way to attempt it would be the session input:
Copy code
self.session.input.set_audio_enabled(False)
If you need more granular control you can mute specific participant tracks:
Copy code
await job_ctx.api.room.mute_published_track(
    api.MuteRoomTrackRequest(
        room=job_ctx.room.name,
        identity=user.identity,
        track_sid=user_audio_track_sid,
        muted=True,
    )
)
You can also use RoomIO and unset the participant and set it up again after 30 secs.
šŸ™Œ 1
r
What @brave-island-45242 suggests is exactly right. One other option is to use manual turn control: https://docs.livekit.io/agents/build/turns/#manual
šŸ™Œ 2
l
Thank you guys!
šŸ‘Œ 1
@brave-island-45242 What design pattern should I use for very structured conversation simulation. Lets say agent needs to walk the user through 2 parts conversation with particular flow. As an example, government person asking user 10 questions and then in the next part, another 10 questions. I tried one agent design with hardcoded restrictions and with function tools. Agent fluctuated during the conversation and lost the flow. I also tried 2 agent design, one handing off to the second agent. It also failed to follow strict flow
b
Hmm hard to tell without knowing the specifics of what you tried. I would probably make the following function tools: • get_pending_questions() • register_question(question_number, question_answer) • remove_registered_question(question_number) <in case it needs a fix> • verify_complete_form() And the rest would be managed just by code to try to offset as much complexity of the agent as possible. Though this might work better if the questions are not that complex. Otherwise you might want to experiment with tasks. Though it is an experimental feature.
l
do you guys know, how can I make agent ask only particular questions? I used loop with
say()
method to make the agent say each question. But in between, agent says some questions on its own. I adjusted isntructions to strictly follow the questions but it still misbehaves code snippet
Copy code
async def _run_part1(self):
        """Handles Part 1 of the test."""
        await self.state_machine.transition_to(TestState.PART1_INTRO)
        intro_text = self.conversation.get_part_greeting_script("part1")
        await self.session_manager.say(intro_text, allow_interruptions=False)

        await self.state_machine.transition_to(TestState.PART1_SPEAKING)
        self.timing_manager.start_section(TestState.PART1_SPEAKING.value)
        
        for question in PART1_QUESTIONS['home']:
            if self.timing_manager.is_section_overtime():
                break
            await self.session_manager.say(question, allow_interruptions=True)
            await asyncio.sleep(8)

        await self.state_machine.transition_to(TestState.PART1_FINISH)
the output is kinda "Agent Thank you. Moving on. What do you like most about your home? What do you like about where you live?"
b
How well the agent follows instructions usually depends on the prompt and the capabilities of the LLM. Meaning that you will either need to change the prompt, change the LLM and/or (more reliable in my opinion) structure the conversation in a way the LLM hallucinates less. All of this is just trial an error in my experience. It is understandable why'd you go to a state machine to try to control the flow of the conversation in a predictable way. But I don't think it synergizes greatly with a non-deterministic process like gen AI. I'd reckon is better to either let the agent try to handle the list of questions by itself. Or maybe trying to think of an agent as the node in the state machine if you want to go that route.