i am trying override llm_node in Agent class but t...
# ask-ai
b
i am trying override llm_node in Agent class but this method is not being called , after on_enter on exit is called and i can see logs of llm_node being called
t
Thanks for reaching out, Dinesh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m looking at your issue with the
llm_node
override not being called. To help diagnose, please confirm a few things and paste the minimal code around your agent and session initialization. 1. Which LLM class and model ID are you using (for example
openai.LLM(model="gpt-4o-mini")
or
openai.realtime.RealtimeModel
)? 2. Are you using a realtime model (RealtimeModel / Gemini Live / OpenAI Realtime)? If yes,
llm_node
is bypassed — the realtime hook is
realtime_audio_output_node
. 3. Share the Agent subclass method signature for your override (the exact
async def llm_node(...)
block) and how you create/start the
AgentSession
. 4. Any logs you see around
on_enter
,
on_exit
, and any logging inside
llm_node
. Once I have that, I’ll point out the likely cause and exact code changes to get your override called. Sources: Pipeline nodes and hooks | LiveKit docs
b
Copy code
This file is a merged representation of a subset of the codebase, containing specifically included files, combined into a single document by Repomix.
The content has been processed where content has been compressed (code blocks are separated by ⋮---- delimiter).

<file_summary>
This section contains a summary of this file.

<purpose>
This file contains a packed representation of a subset of the repository's contents that is considered the most important context.
It is designed to be easily consumable by AI systems for analysis, code review,
or other automated processes.
</purpose>

<file_format>
The content is organized as follows:
1. This summary section
2. Repository information
3. Directory structure
4. Repository files (if enabled)
5. Multiple file entries, each consisting of:
  - File path as an attribute
  - Full contents of the file
</file_format>

<usage_guidelines>
- This file should be treated as read-only. Any changes should be made to the
  original repository files, not this packed version.
- When processing this file, use the file path to distinguish
  between different files in the repository.
- Be aware that this file may contain sensitive information. Handle it with
  the same level of security as you would the original repository.
</usage_guidelines>

<notes>
- Some files may have been excluded based on .gitignore rules and Repomix's configuration
- Binary files are not included in this packed representation. Please refer to the Repository Structure section for a complete list of file paths, including binary files
- Only files matching these patterns are included: app/modules/pipeline/pipeline_agent.py
- Files matching patterns in .gitignore are excluded
- Files matching default ignore patterns are excluded
- Content has been compressed - code blocks are separated by ⋮---- delimiter
- Files are sorted by Git change count (files with more changes are at the bottom)
</notes>

</file_summary>

<directory_structure>
app/
  modules/
    pipeline/
      pipeline_agent.py
</directory_structure>

<files>
This section contains the contents of the repository's files.

<file path="app/modules/pipeline/pipeline_agent.py">
def get_key_from_agent_name(agent_name: str) -> str | None
⋮----
match = re.search(r"\$([^$]+)\$", agent_name.lower())
⋮----
def get_agent_id_str_for_kb(agent_id_str: str, agent_name:str, session: AgentSession) -> str
⋮----
# Mapping logic for agent_id to KB agent ID string
# This is a placeholder implementation; replace with actual mapping as needed
⋮----
switched_agent_id = session.userdata.current_switched_agent_id
⋮----
class CustomPipelineAgent(Agent)
⋮----
# TODO:add metadata
⋮----
tools = [
⋮----
# *dynamic_tools,
⋮----
#  ! temporary code to get the function tools based on the agent name
key = get_key_from_agent_name(agent_name)
⋮----
# elif key == "dtmf":
⋮----
# self.otp_tools.start_otp_tracking,
# self.otp_tools.stop_otp_tracking,
# self.otp_tools.reset_otp_tracking,
⋮----
# define voice mail tool
# ! the prompt here needs to be same as PipelineAgentTools.end_call_on_voice_mail
⋮----
"""
                use this tool only if the user speaks a complete voicemail message which can be attributed to being an automated voicemail system with certainty
                """
⋮----
# Then call the main function to end the call
⋮----
tools = [*tools, end_call_on_voice_mail]
⋮----
async def on_enter(self) -> None
⋮----
# if self.welcome_message:
#     await self.session.say(self.welcome_message)
# else:
#     await self.session.say("No welcome message for you")
⋮----
#     await self.session.generate_reply(
#         instructions="Greet the user with a warm welcome, or as per the specific instructions"
#     )
⋮----
# async def on_exit(self) -> None:
#     logger.bind(
#         ctx="pipeline.agent.on_exit",
#         agent_id=self.agent_id,
#         agent_name=self.agent_name,
#         room_name=self.room_name
#     ).info("Agent session ended")
#
#     # await self.session.generate_reply(
#     #     instructions="Thank the user for calling, and ask if there is anything else you can help with"
#     # )
#     pass
⋮----
async def search_kb(self, query: str) -> str
⋮----
log = logger.bind(
⋮----
# Call the vector store search function
agent_id_str = get_agent_id_str_for_kb(self.agent_id, self.agent_name, self.session)
⋮----
search_results = await vector_store_client.search(query, agent_id_str)
⋮----
# Extract and combine results into a single string
combined_results = "Context search results:"
⋮----
# Skip the distance field and only include content
⋮----
# * RAG content
⋮----
# * Handle interruption
⋮----
query_content = new_message.text_content if new_message.text_content else ""
⋮----
rag_content = await self.search_kb(query_content)
⋮----
# The user has interrupted to say: "{query_content}"
⋮----
#     Acknowledge their input naturally and continue the conversation smoothly.
#     Don't repeat what you were saying before - instead, respond directly to their interruption and move forward with the conversation.
⋮----
#     Keep your response conversational and in Indian English/Hinglish as appropriate.
⋮----
#     Use this context if relevant:
⋮----
log = logger.bind()
⋮----
new_message = chat_ctx.items[-1]
⋮----
# ? to handle RAG at initialization
⋮----
# * RAG content
⋮----
# Fetch user context for embedded calls
⋮----
user_context = await EmbeddedAgentUtil.fetch_user_context(
</file>

</files>
t
Thanks — I’m responding to your issue where your
llm_node
override isn’t being called while `on_enter`/`on_exit` are. Quick checklist and next steps so I can pinpoint the problem: 1. Which LLM class and model ID are you using in your AgentSession? (Example:
openai.LLM(model="gpt-4o-mini")
or
openai.realtime.RealtimeModel
) 2. Paste the exact
async def llm_node(...)
method from your
CustomPipelineAgent
(including the signature). 3. Paste the AgentSession creation / start code where you pass the agent instance. Notes to check immediately: • If you are using a realtime model (e.g.,
openai.realtime.RealtimeModel
),
llm_node
will be bypassed — realtime agents use
realtime_audio_output_node
instead. • Ensure your override signature matches:
Copy code
async def llm_node(
    self,
    chat_ctx: ChatContext,
    tools: list[FunctionTool],
    model_settings: ModelSettings
) -> AsyncIterable[llm.ChatChunk]:
• Add an explicit log at the top of your
llm_node
(e.g., "Entering custom llm_node") to confirm invocation. Send the three items above and I’ll tell you exactly what to change.
b
openai.LLM(model="gpt-4o-mini") async def llm_node( self, chat_ctx: ChatContext, tools: List[Any], model_settings: ModelSettings, ) -> Any: print("###CustomPipelineAgent-> llm_node called") new_message = chat_ctx.items[-1] # ? to handle RAG at initialization if ( isinstance(new_message, ChatMessage) and new_message.type == "message" and new_message.role == "user" ): # * RAG content query_content = new_message.text_content if new_message.text_content else "" content = await self.fixed_search(query_content) chat_ctx.add_message( role="assistant", content=content, ) return super().llm_node(chat_ctx, tools, model_settings)
t
You're using a compatible LLM (
openai.LLM(model="gpt-4o-mini")
), so
llm_node
should be invoked. The override you shared needs a couple of fixes so your code actually runs as the framework expects. Changes to make: 1. Use the exact async generator signature and return type:
Copy code
async def llm_node(
    self,
    chat_ctx: ChatContext,
    tools: list[FunctionTool],
    model_settings: ModelSettings,
) -> AsyncIterable[llm.ChatChunk]:
1. Log immediately and yield from the base implementation using
async for
(don’t return the coroutine directly):
Copy code
print("### CustomPipelineAgent -> llm_node called")

new_message = chat_ctx.items[-1]
if isinstance(new_message, ChatMessage) and new_message.type == "message" and new_message.role == "user":
    query_content = new_message.text_content or ""
    content = await self.fixed_search(query_content)
    chat_ctx.add_message(role="assistant", content=content)

async for chunk in super().llm_node(chat_ctx, tools, model_settings):
    yield chunk
1. Ensure imports/typing are correct:
ChatContext
,
ChatMessage
,
ModelSettings
,
FunctionTool
,
AsyncIterable
, and
llm.ChatChunk
. If you make those changes and still don’t see the "llm_node called" print, paste: • The exact AgentSession creation/start code, and • Any runtime logs around session start and processing.