Running a task The task runs automatically upon cr...
# ask-ai
b
Running a task The task runs automatically upon creation. It must be created within the context of an existing
Agent
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.
Copy code
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?
t
Thanks for reaching out, mateuszkasprowicz. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely! The chat context from the
CollectConsent
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