I am trying to do a sample tavus test I have code ...
# ask-ai
b
I am trying to do a sample tavus test I have code like below, but 2 agents are joining. I cant figure out why. Any ideas?
Copy code
import asyncio
import logging
from dotenv import load_dotenv
from livekit import agents
from livekit.agents import AgentSession, JobContext, WorkerOptions, cli, llm, RoomOutputOptions
from livekit.plugins import openai, silero, tavus

load_dotenv()

# Configure logging
logging.basicConfig(level=<http://logging.INFO|logging.INFO>)
logger = logging.getLogger("official-tavus-agent")

# Tavus Configuration
TAVUS_API_KEY = "**"
PERSONA_ID = "**"
REPLICA_ID = "**"

async def entrypoint(ctx: JobContext):
    """Official Tavus integration following the documentation exactly."""
    
    # Connect to the room first
    await ctx.connect()

    # Create initial chat context
    initial_ctx = llm.ChatContext()
    initial_ctx.messages.append(llm.ChatMessage(
        role="system",
        content="You are a helpful AI assistant. Keep responses brief and conversational.",
    ))

    # Create agent session with STT, LLM, TTS
    session = AgentSession(
        stt=openai.STT(),
        llm=openai.LLM(),
        tts=openai.TTS(),
        vad=silero.VAD.load(),
        chat_ctx=initial_ctx,
    )

    # Create avatar session with official parameters
    avatar = tavus.AvatarSession(
        replica_id=REPLICA_ID,
        persona_id=PERSONA_ID,
        tavus_api_key=TAVUS_API_KEY,
        avatar_participant_name="Tavus-avatar-agent",
    )

    # Start the avatar and wait for it to join
    await avatar.start(session, room=ctx.room)

    # Start agent session with audio disabled (avatar handles audio)
    await session.start(
        room=ctx.room,
        room_output_options=RoomOutputOptions(
            # Disable audio output to the room. The avatar plugin publishes audio separately.
            audio_enabled=False,
        ),
    )

    # Keep the session alive
    await asyncio.sleep(1)


if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
t
Thanks for reaching out, Jacob. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you clarify what you mean by "2 agents are joining"? Are you seeing two separate agents in the room, or is the same agent being duplicated? Additionally, are there any specific error messages or logs that might help identify the issue?
b
See the generic agent-* and tavus agent, in the UI + my own video
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!