Is it possible to make a @function_tool that does ...
# ask-ai
g
Is it possible to make a @function_tool that does not send the TTS to the client, only send text? If yes, can i have a guideline, or an example of Agent class?
t
Thanks for reaching out, Phuong. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely! You can create a
@function_tool
that sends just text—no TTS involved—to the client in LiveKit. Let me share an example of how you might set up an Agent class specifically for text-only communication: Example Agent Class for Text-Only Output:
Copy code
class MyAgent(Agent):
    def __init__(self) -> None:
        super().__init__(
            instructions="You are a helpful assistant.",
        )

    @function_tool
    async def get_weather(self, location: str):
        """Called when the user asks about the weather.
        
        Args:
            location: The location to get the weather for
        """
        return f"The weather in {location} is sunny today."
Configuration for Text-Only Communication:
Copy code
async def entrypoint(ctx: JobContext):
    session = AgentSession(
        llm=openai.LLM(model="gpt-4o-mini"),
        # Notice we don’t need TTS or STT here
    )
    await session.start(
        agent=MyAgent(),
        room=ctx.room,
        room_input_options=RoomInputOptions(text_enabled=True, audio_enabled=False),
        room_output_options=RoomOutputOptions(transcription_enabled=True, audio_enabled=False),
    )
Key Points:Text-Only Configuration: We set
room_input_options
and
room_output_options
to enable text input and disable audio, keeping things simple. • No TTS Needed: Since audio output is off, the Agent doesn’t need a TTS instance. • Function Tool: The
@function_tool
decorator helps the agent handle specific tasks and return text responses without any TTS. This way, your agent sends only text to the client, making it perfect for text-only interactions. If you have any questions or want to explore this more, just let me know!
g
No, my agent is a voice-enabled one, but i just one tool that don't go through the TTS but only send text to the client.
t
Right now, it’s not possible to set up a voice-enabled agent where only certain
@function_tool
responses skip the TTS while others still have audio. The options available let you turn off audio output for the whole session using
RoomOutputOptions(audio_enabled=False)
, but this affects all responses, not just specific tools. If you have a particular scenario in mind or need a hand figuring things out, just let me know! I’m here to help and can also pass your request along for more support if needed.