colossal-xylophone-68609
05/08/2026, 11:39 AMtall-airline-16756
05/08/2026, 11:39 AMtall-airline-16756
05/08/2026, 11:40 AMchat_ctx inside a tool. You can get it from the RunContext passed into the tool function: context.session.chat_ctx.
Example:
@function_tool()
async def my_tool(self, context: RunContext):
# read current chat context
current_context = context.session.chat_ctx
# modify or copy before passing on
new_ctx = current_context.copy()
# ...use new_ctx or current_context as needed
Notes:
• Each agent has its own `chat_ctx`; the full session history is in session.history.
• Use chat_ctx.copy() when passing context to tasks or handoffs to avoid mutating the original. Sources: Agents and handoffs | LiveKit Documentation | Function tool definition | LiveKit Documentation | Chat context | LiveKit Documentation | Tasks and task groups | LiveKit Documentation, with interactive elementscolossal-xylophone-68609
05/08/2026, 11:43 AMtall-airline-16756
05/08/2026, 11:43 AMself.chat_ctx inside a tool: you should not rely on self.chat_ctx there. Inside a tool the correct place to get the chat context is the RunContext passed into the tool: context.session.chat_ctx.
Quick reasons:
• Tools receive context (the RunContext) rather than the agent instance, so self.chat_ctx may not be set or reflect the current session.
• Use context.session.chat_ctx and chat_ctx.copy() if you need to modify or pass a snapshot to tasks/handoffs.
If you want, tell me the tool signature you're using and I can show the exact snippet for it.
, with interactive elementscolossal-xylophone-68609
05/08/2026, 11:44 AMtall-airline-16756
05/08/2026, 11:44 AMhistory rather than an agent's chat_ctx.
Examples:
Python (inside a tool with context: RunContext):
full_history = context.session.history
Node.js (inside a tool):
const fullHistory = context.session.history;
Notes:
• chat_ctx is per-agent turn; session.history contains the full conversation across agents.
• If you need a mutable snapshot, copy it before editing. Sources: Chat context | LiveKit Documentation, with interactive elements