Follow-up Response:
Yes, the custom AgentTask is running inside an active AgentSession. Here are the specific details:
AgentSession Setup:
python
Apply to total_agent....
session = AgentSession(
stt=deepgram.STT(model="nova-2"),
llm=openai.LLM(model="gpt-4o"),
tts=openai.TTS(voice="alloy"),
vad=silero.VAD.load(),
_turn_detection_=MultilingualModel(),
_min_endpointing_delay_=0.5,
_max_endpointing_delay_=3.0
)
Task Creation Context:
The AgentTask is created inside the agent's on_user_turn_completed method, which is called by LiveKit's framework when a user completes their turn:
class TotalInterviewAgent(Agent):
async def on_user_turn_completed(self, _turn_ctx_, _new_message_):
# This is where we create the task
self.interview_task = InterviewPlanningTask(...)
_# Then immediately call the task's evaluate_and_plan method_
result = await self.interview_task.evaluate_and_plan(turn_ctx, new_message, 1)
Task's llm_node Override:
class InterviewPlanningTask(AgentTask[str]):
async def llm_node(self, _chat_ctx_, tools, _model_settings_):
# This is where the error occurs
return await self.session.agent.llm.generate(chat_ctx) # RuntimeError here
The specific error:
The error happens when the task tries to access the LLM through self.session.agent.llm.generate() - it seems like even though we're inside an active session, the task doesn't have the proper activity context to access the session's LLM.
Question: Should the AgentTask be accessing the LLM differently, or should we be passing the LLM instance to the task constructor instead of trying to access it through the session?