famous-tailor-60615
03/21/2026, 5:27 AMtall-airline-16756
03/21/2026, 5:27 AMtall-airline-16756
03/21/2026, 5:28 AMfamous-tailor-60615
03/21/2026, 5:32 AMtall-airline-16756
03/21/2026, 5:32 AMfamous-tailor-60615
03/21/2026, 5:35 AMtall-airline-16756
03/21/2026, 5:35 AMagent.update_tools(). That lets you add, remove, or replace tools after the agent has been created, enabling the dynamic behavior you described.
What that enables for dynamic few-shot
• You can run your vector search on the user utterance, pick the most relevant tools and examples, then call agent.update_tools() to set the agent’s available toolset for that session/turn.
• When tools change at runtime, an AgentConfigUpdate is automatically added to the conversation history so the LLM is informed about added/removed tools — this helps the agent adapt without confusing context.
• You can also group related tools into toolsets (by ID) and swap entire sets when appropriate, which makes management easier for many tools.
How you might implement this (conceptual flow)
1. Encode user utterance → perform vector search to find top-N relevant tools and top-M examples.
2. Optionally re-rank/filter results (permissions, availability, similarity threshold).
3. Build the dynamic tool list (or toolset) for this request.
4. Call:
◦ Add or replace tools: await agent.update_tools([tool_a, tool_b, ...])
◦ Or incrementally: await agent.update_tools(agent.tools + [new_tool]) or remove with agent.tools - [tool_a]
1. Send the user utterance to the agent. The conversation history will include an AgentConfigUpdate reflecting the tool changes.
Practical tips and trade-offs
• Keep tool definitions concise so the LLM can match intent quickly.
• Limit the number of active tools per turn to improve tool-call accuracy.
• Use two-level retrieval (select tools first, then examples) to reduce prompt size and focus the few-shot examples.
• Cache common retrieval results to lower latency.
• Log retrieval and tool-call outcomes to iteratively improve selection and thresholds.
Questions to tailor a concrete example
• Which vector DB and embedding model are you using (or planning to use)?
• Do you use function-calling style tools (structured schemas) or free-text tool prompts?
• Do you want tools updated every single user turn, per session, or only on certain triggers?
• Would you like a code example showing the retrieval → agent.update_tools() → prompt flow in Python?
If you tell me your stack and desired trigger strategy (per-turn vs session vs conditional), I’ll provide a concrete implementation pattern and a sample snippet you can drop into your LiveKit Agents workflow.
Sources: Function tool definition | LiveKit Documentation | Prebuilt tools | LiveKit Documentation, with interactive elementsfamous-tailor-60615
03/21/2026, 5:36 AMtall-airline-16756
03/21/2026, 5:36 AMagent.update_tools() (or updateTools() in TypeScript). Use that to apply the results of a vector search and limit active tools/examples per turn.
• Below is a minimal Python-style conceptual example that ties a vector DB lookup (pick top tools) to agent.update_tools(), then runs the agent for that turn.
• I’ve also listed relevant repo examples you can use: dynamic tool creation and survey agent examples.
Minimal end-to-end pattern (conceptual Python pseudocode)
1. Do a vector search on the user utterance to find the most relevant tool IDs / example IDs.
2. Build the Tool objects (or look them up from a registry).
3. Call await agent.update_tools(selected_tools).
4. Send the user utterance to the agent; the conversation will receive an AgentConfigUpdate and then the agent will use the updated toolset.
Example pseudocode
# 1) Assume you have:
# - embed(text) -> embedding vector
# - vector_db.query(vec, top_k) -> list of {id, score, meta}
# - TOOL_REGISTRY: mapping tool_id -> Tool object (function_tool created earlier)
user_text = "I need to refund my last order"
vec = embed(user_text)
# 2) Retrieve top relevant items (tool descriptions or examples)
hits = vector_db.query(vec, top_k=10)
# 3) Choose top-N tools (dedupe & apply heuristics: permissions, availability)
# Example: take top 3 unique tool ids from hits
selected_tool_ids = []
for h in hits:
tool_id = h["meta"]["tool_id"] # store tool_id in vector item metadata
if tool_id not in selected_tool_ids:
selected_tool_ids.append(tool_id)
if len(selected_tool_ids) >= 3:
break
selected_tools = [TOOL_REGISTRY[t] for t in selected_tool_ids]
# 4) Update the agent's tools at runtime
await agent.update_tools(selected_tools)
# 5) Now ask the agent to handle the utterance
reply = await agent.generate_reply({"instructions": user_text})
# AgentConfigUpdate will be appended to the conversation automatically
Notes and variations
• Two-level retrieval: first retrieve top tools, then retrieve top few-shot examples only for those tools. Inject the examples into system/instructions or rely on tool schemas + example-based system prompt updates (you can change update_instructions() if you want to add dynamic few-shot examples to the prompt).
• If you generate tools dynamically (e.g., many similar tools for profile fields), create them with function_tool() factories and either register them in TOOL_REGISTRY or pass them directly to update_tools().
• Use re-ranking or a similarity threshold to avoid irrelevant tools.
• Limit active tools per turn (2–5) to improve tool-call accuracy.
TypeScript / JS equivalent
• Use agent.updateTools(...) or update the tool context in your agent session with the new toolset (examples in the docs and examples repo mirror the same API concepts).
• Example usage patterns and helper functions for dynamic creation exist in the examples repo.
Concrete examples and repos to inspect
• Dynamic tool creation example (complete script): examples/dynamic_tool_creation.py — shows generating tools at runtime and registering them.
• Survey agent (Python) example: examples/survey/survey_agent.py — shows real-world agent workflows that change behavior based on session state.
• Shopify voice shopper example: a complex example of dynamic agent/tool behavior and MCP integration.
Next steps I can help with
• If you tell me your stack I’ll produce runnable code:
◦ Python or TypeScript?
◦ Vector DB (Pinecone, Milvus, Weaviate, FAISS, etc.) and embedding model?
◦ Do you use function-calling (structured schemas) or free-text tool prompts?
◦ When should tools be updated: every turn, per session, or on triggers?
• I can also provide a full sample that:
◦ Implements two-level retrieval (tools -> examples),
◦ Updates agent tools,
◦ Optionally updates the system prompt with the few-shot examples,
◦ Includes caching and a suggested similarity threshold.
Which language and vector DB would you like the runnable example in?
Sources: Function tool definition | LiveKit Documentation | Build a salary negotiation coach with a LemonSlice avatar | LiveKit | Agents and handoffs | LiveKit Documentation | Agent Builder | LiveKit Documentation | External data and RAG | LiveKit Documentation, with interactive elements