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

**URL:** <https://community.livekit.io/t/using-livekit-agents-for-a-stateless-text-only-endpoint-with-upstream-session-management/2262>\
**Category:** Agents\
**Tags:** agent-development, livekit-cloud\
**Created:** [October 14, 2026, 7:37pm UTC](https://community.livekit.io/t/using-livekit-agents-for-a-stateless-text-only-endpoint-with-upstream-session-management/2262 "2026-10-14T19:37:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harshita\_Sukumar\_Patil](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/harshita_sukumar_patil/32/351_2.png) [@Harshita\_Sukumar\_Patil](https://community.livekit.io/u/Harshita_Sukumar_Patil)\
**Post date:** [October 14, 2026, 7:37pm UTC](https://community.livekit.io/t/using-livekit-agents-for-a-stateless-text-only-endpoint-with-upstream-session-management/2262/1 "2026-10-14T19:37:47Z")

</div>

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:**

2. **Exposing Agents as an API / Non-WebRTC Triggers:**

3. **Pure Text Mode (Stripping STT/TTS):**

---

<div class="post-metadata">

**Author:** ![CWilson](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/cwilson/32/135_2.png) [@CWilson](https://community.livekit.io/u/CWilson)\
**Post date:** [October 14, 2026, 11:16pm UTC](https://community.livekit.io/t/using-livekit-agents-for-a-stateless-text-only-endpoint-with-upstream-session-management/2262/2 "2026-10-14T23:16:17Z")

</div>

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.

```auto
 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:

```auto
 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.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/system/32/26_2.png) [@system](https://community.livekit.io/u/system)\
**Post date:** [October 29, 2026, 11:17pm UTC](https://community.livekit.io/t/using-livekit-agents-for-a-stateless-text-only-endpoint-with-upstream-session-management/2262/3 "2026-10-29T23:17:02Z")

</div>

Closed on October 29, 2026, 11:17pm UTC

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
