broad-painter-9222
11/14/2025, 9:24 PMAgent which is active within an AgentSession. The task takes control of the session until it returns a result. Await the task to receive its result.
from livekit.agents import Agent, function_tool, get_job_context
class CustomerServiceAgent(Agent):
def __init__(self):
super().__init__(instructions="You are a friendly customer service representative.")
async def on_enter(self) -> None:
if await CollectConsent(chat_ctx=self.chat_ctx):
await self.session.generate_reply(instructions="Offer your assistance to the user.")
else:
await self.session.generate_reply(instructions="Inform the user that you are unable to proceed and will end the call.")
job_ctx = get_job_context()
await job_ctx.api.room.delete_room(api.DeleteRoomRequest(room=job_ctx.room.name))
in this example from your documentation is the chat context from the CollectConsent task passed/preserved in the CustomerServiceAgent?tall-airline-16756
11/14/2025, 9:24 PMtall-airline-16756
11/14/2025, 9:25 PMCollectConsent task is thoughtfully preserved and passed along to the CustomerServiceAgent. When the CollectConsent task is created, it uses the chat_ctx parameter set to self.chat_ctx from the CustomerServiceAgent, which means the conversation history is shared seamlessly between the task and the agent.
This approach helps keep everything consistent throughout your session, so the agent can smoothly use the results from the CollectConsent task in its workflow. This way, you won’t need to repeat any information, making your experience much more comfortable and efficient.
Sources: Workflows | LiveKit docs | complex-agents/personal_shopper/personal_shopper.py