silly-baker-11446
08/30/2025, 3:17 AMtall-airline-16756
08/30/2025, 3:17 AMtall-airline-16756
08/30/2025, 3:18 AMllm_node method in an AgentTask without running into the pesky RuntimeError: no activity context found, the agent is not running, the key is to make sure your agent is properly started within an AgentSession. This error pops up because the agent isn’t active yet, so runtime parts like the LLM can’t be accessed.
Here’s a friendly little guide to safely override `llm_node`:
1. First, make sure you start the agent using await session.start(agent=...) before calling any methods that need the agent’s activity context.
2. When you override llm_node, call the default implementation with super().llm_node() or Agent.default.llm_node(). This keeps everything playing nicely with the agent’s lifecycle.
3. Feel free to add your own preprocessing (like injecting prompts) before handing things off to the default method.
Here’s an example to make it clearer:
class CustomAgent(Agent):
async def llm_node(self, chat_ctx, tools, model_settings):
# Custom preprocessing
user_query = chat_ctx.get_user_message().text_content
custom_prompt = f"Custom prompt: {user_query}"
chat_ctx.add_message(role="assistant", content=custom_prompt)
# Delegate to default implementation
async for chunk in super().llm_node(chat_ctx, tools, model_settings):
yield chunk
By following these steps, you’ll keep your agent active and make sure the llm_node method fits smoothly into the agent’s lifecycle. If you have any questions or need a hand, just let me know!
Sources: Pipeline nodes and hooks | LiveKit Docs | Modifying LLM output before TTS | LiveKit Docs | examples/voice_agents/llamaindex-rag/retrieval.py