prehistoric-alligator-43413
11/24/2025, 6:15 PMtall-airline-16756
11/24/2025, 6:15 PMtall-airline-16756
11/24/2025, 6:15 PMFunctionContext was removed in Agents v1.x. Below is what to change and two recommended approaches for passing context (RAG or tools).
Acknowledgement
• You're asking how to pass function context to an agent for RAG and why from livekit.agents.llm import FunctionContext errors.
What to do
• Remove any import/usage of FunctionContext (it's deprecated/removed).
• Use one of these approaches:
1) Inject RAG context by overriding llm_node (recommended for RAG)
• Add your retrieval result into the chat context before the LLM call.
• Example pattern:
from livekit.agents import Agent, ChatContext, ModelSettings, ChatChunk
class RAGAgent(Agent):
async def llm_node(self, chat_ctx: ChatContext, tools: list, model_settings: ModelSettings) -> AsyncIterable[ChatChunk]:
rag_context = await retrieve_rag_context(chat_ctx.messages[-1].text)
chat_ctx.add_message(role="system", content=rag_context)
return Agent.default.llm_node(self, chat_ctx, tools, model_settings)
2) Expose functionality via tools using @function_tool (recommended for callable functions)
• Define tools as methods on your Agent with @function_tool() and call them from the agent or LLM.
• Example pattern:
from livekit.agents import Agent, function_tool
class Assistant(Agent):
@function_tool()
async def retrieve_knowledge_base(self, query: str) -> str:
return await my_rag_function(query)
Key points
• Do not import `FunctionContext`; it no longer exists in v1.x.
• Use @function_tool for callable tools and override llm_node to inject external context for RAG.
• Ensure your imports use function_tool from livekit.agents.llm (or from livekit.agents import function_tool depending on your code layout).
If you want, paste the small code snippet where you currently import/use FunctionContext and I’ll show the exact replacement for your case.
Sources: Agents v0.x migration guide - Python | LiveKit docs | Agents v0.x migration guide - Node.js | LiveKit Docs | Tool definition and use | LiveKit docs | External data and RAG | LiveKit Docsprehistoric-alligator-43413
11/24/2025, 6:16 PMtall-airline-16756
11/24/2025, 6:16 PMFunctionContext and registering callables. That API is removed. Replace that pattern with either tool methods (@function_tool) or inject RAG context via llm_node. Two concise fixes:
1) If you want callable KB functions, define them as tools on the Agent:
from livekit.agents import Agent, function_tool
class KBAgent(Agent):
@function_tool()
async def search_knowledge_base(self, query: str) -> str:
return await search_knowledge_base(query) # your impl
@function_tool()
async def get_knowledge_base_stats(self) -> str:
return await get_knowledge_base_stats() # your impl
No FunctionContext needed — the agent registers these tools automatically.
2) If you just want to inject KB content (RAG) into the prompt, override llm_node and add system/context messages:
from livekit.agents import Agent, ChatContext, ModelSettings, ChatChunk
class RAGAgent(Agent):
async def llm_node(self, chat_ctx: ChatContext, tools: list, model_settings: ModelSettings) -> AsyncIterable[ChatChunk]:
if knowledge_base.enabled:
rag_context = await retrieve_rag_context(chat_ctx.messages[-1].text)
chat_ctx.add_message(role="system", content=rag_context)
return Agent.default.llm_node(self, chat_ctx, tools, model_settings)
If you paste the few lines where you currently call FunctionContext I’ll rewrite them directly into one of these patterns for your code.