Using LiveKit Agents for a Stateless Text-Only Endpoint with Upstream Session Management

Hi livekit team
@livekit @LiveKit-Community @livekitteams @darryncampbell @CWilson @Muhammad_Usman_Bashir
We are evaluating the LiveKit Agent Framework (Python SDK) for a specific architectural use case and want to check technical feasibility and best practices.

Current System Architecture

  • We have an existing legacy chatbot microservice that handles user frontend connections, decision-tree routing, database persistence, and overall session state management.

  • We want to incrementally upgrade this system by routing queries requiring dynamic LLM responses to a dedicated agent service.

Core Requirement

We want to run LiveKit Agents primarily as a stateless, text-only processing service (Endpoint style) rather than a full real-time audio/video WebRTC pipeline.

Questions & Requirements:

  1. Stateless / External Session Injection:

    • Is it possible or recommended to run an Agent where session state & conversation history are strictly provided by an upstream service in the payload (e.g., passing session_id, chat_history, and current_query) rather than relying on LiveKit Server’s internal room/session persistence?
  2. Exposing Agents as an API / Non-WebRTC Triggers:

    • Can a LiveKit Agent be triggered via custom backend RPC or Direct API calls from our upstream service without establishing a full WebRTC connection loop from a frontend client?
      Can the agent receive an external session ID and history and generate responses without relying on a LiveKit-managed session?Can the AI logic be reused independently of the LiveKit server, or does the existing framework require server-side infrastructure even for chat-only use?
  3. Pure Text Mode (Stripping STT/TTS):

    • What is the recommended way to configure JobContext or Agent workers to skip audio tracks, STT, and TTS entirely, listening purely for text DataPackets / RPC events?

Hi Harshita, good questions. I am hoping this will be much easier in the near future. But short version: yes, you can use the Agents framework as a stateless text service, but you don’t need LiveKit rooms or WebRTC for that. Use the framework in-process inside your own API service, and use rooms only for clients that connect in real time.

  1. Stateless, with upstream session and history

Yes. An AgentSession doesn’t need a room. Build the agent from the history your service sends, run one turn, return the result, and discard the session. Nothing needs to persist on the LiveKit side.

 from livekit.agents import Agent, AgentSession, llm

 async def handle(session_id: str, chat_history: list[dict], query: str) -> str:
     ctx = llm.ChatContext.empty()
     for m in chat_history:                      # e.g. {"role": "user"|"assistant", "content": "..."}
         ctx.add_message(role=m["role"], content=m["content"])

     agent = Agent(instructions="...", chat_ctx=ctx, tools=[...])
     async with AgentSession(llm="openai/gpt-5.4-mini") as session:   # no STT/TTS/VAD, no room
         await session.start(agent)
         result = await session.run(user_input=query)
     # result.events holds the assistant message(s) and any tool calls/outputs
     return result

session.start(agent) without a room and session.run(user_input=…) are the same pattern the framework uses for agent tests and evals. Tools, handoffs and instructions all work. Your service stays the source of truth for session_id and history; send back the new turns and store them however you already do.

If all you need is “history plus query in, response out”, calling the LLM abstraction directly is even lighter: llm.chat(chat_ctx=ctx, tools=…). That works the same with LiveKit Inference (just an API key and secret) or with any provider plugin.

  1. Triggering by API or RPC without WebRTC

The worker and dispatch model is room-based: a dispatched agent joins a room, and clients talk to it through text streams (lk.chat), RPC or data packets. Even a backend that joins as a participant makes a WebRTC connection. So for request/response from your microservice, wrap the pattern above in your own HTTP endpoint (FastAPI or similar). The AI logic (agents, tools, ChatContext) runs independently of LiveKit Server. You only need LiveKit infrastructure if you use rooms, or LiveKit Inference for models.

  1. Text-only inside a room (for when you do want a live session)

Leave STT, TTS, and VAD out of AgentSession and turn off audio in the room I/O:

 from livekit.agents import room_io

 session = AgentSession(llm="openai/gpt-5.4-mini")
 await session.start(
     agent=agent,
     room=ctx.room,
     room_options=room_io.RoomOptions(
         audio_input=False, audio_output=False,
         text_input=True, text_output=True,
     ),
 )

The agent then takes user text from the lk.chat text-stream topic and replies as text. You can seed history the same way, by passing chat_ctx to the Agent.

Recommendation for an incremental migration: keep your microservice as the session owner and call an in-process agent per request (option 1). Add a room-based text or voice agent later if you want streaming or real-time voice on the frontend.