little-king-41579
12/25/2025, 5:44 AMtall-airline-16756
12/25/2025, 5:44 AMtall-airline-16756
12/25/2025, 5:44 AM@function_tool and how to update userdata with your answers dict.
The right pattern is to accept the agent run context (commonly RunContext) in your function tool, ensure userdata.data_collection exists, then update it. Example:
@function_tool()
async def update_answers(self, context: RunContext, answers: dict[str, Any]):
"""Update collected answers stored in session userdata."""
# Ensure data_collection exists
if not hasattr(context.session.userdata, "data_collection"):
context.session.userdata.data_collection = {}
context.session.userdata.data_collection.update(answers)
return None, "Answers updated successfully."
And when creating the session, initialize userdata so data_collection is present:
session = AgentSession(
userdata={"data_collection": {}},
stt=..., llm=..., tts=..., vad=...
)
If that doesn’t work for you, tell me:
• The exact error or behavior you see (traceback/logs).
• Which Agent framework version or SDK you’re using.
• The structure of self.session.userdata in your environment (if different).
I can then give a targeted fix.
Sources: Agents and handoffs | LiveKit docs | Tool definition and use | LiveKit docslittle-king-41579
12/25/2025, 5:45 AMtall-airline-16756
12/25/2025, 5:46 AManswers parameter in your @function_tool. Two clear options:
1) Docstring (simple)
@function_tool()
async def update_answers(self, context: RunContext, answers: dict[str, Any]):
"""
Update collected answers in session userdata.
Args:
answers: A dict mapping question IDs to the user's answers.
Example: {"q1": "foo", "q2": "bar"}.
"""
# ...
2) Typed annotation with Annotated + Field (recommended for LLM/tool schema)
from typing import Annotated
from pydantic import Field
@function_tool()
async def update_answers(
self,
context: RunContext,
answers: Annotated[dict[str, Any], Field(description="Dict mapping question IDs to answers, e.g. {'q1':'foo', 'q2':'bar'}")]
):
# ...
Use the docstring for human readers; use Annotated + Field when you want the description included in the tool/function schema sent to the LLM. Which approach do you prefer or are you targeting LLM function-calling behavior?
Sources: Building Multi-Agent Architectures with LiveKit Agents | How to test your agent using another agent | Building a Moviefone-style Theater Assistant | LiveKit docs | Tool definition and use | LiveKit docs | Azure OpenAI LLM plugin guide | LiveKit docslittle-king-41579
12/25/2025, 6:03 AMtall-airline-16756
12/25/2025, 6:03 AMupdate_answers (the error says the answers property must include additionalProperties: false).
Two safe fixes:
1) Quick fix — supply a raw JSON schema with additionalProperties: False for `answers`:
raw_schema = {
"name": "update_answers",
"description": "Update answers with question IDs and values",
"parameters": {
"type": "object",
"properties": {
"answers": {
"type": "object",
"description": "Dict mapping question IDs to answer values",
"additionalProperties": False
}
},
"required": ["answers"]
}
}
2) Recommended — let LiveKit auto-generate a correct schema by using type hints / Pydantic instead of a manual schema:
from livekit.agents import function_tool
from typing import Any
@function_tool()
async def update_answers(self, answers: dict[str, Any]) -> str:
"""Update collected answers (mapping question IDs to values)."""
# implementation...
return "Answers updated"
Which approach are you using now — raw schema or @function_tool/type hints? Share that and any current parameter definition and I’ll give the exact code to fix it.
Sources: Tool definition and use | LiveKit docs