bulky-yak-50122
08/11/2025, 9:37 AMtall-airline-16756
08/11/2025, 9:37 AMtall-airline-16756
08/11/2025, 9:38 AM@function_tool
decorator, double-check that the name
parameter is unique for every function.
3. Review your function definitions to make sure there aren’t any accidental duplicates from copy-pasting or importing multiple times.
4. Make sure update_tools()
isn’t being called multiple times with the same function.
If you want a hand figuring this out or need any more help, just let me know—I’m here for you!
Sources: livekit-agents/livekit/agents/llm/tool_context.pybulky-yak-50122
08/11/2025, 9:40 AMclass Assistant(Agent):
@function_tool()
async def read_user_code(
self,
context: RunContext,)->str:
"""Read the current code written by the user in the editor.
This tool allows the agent to access and analyze the code that the user
has written in their editor during the interview session. Use this tool
when you need to:
- Review the user's code implementation
- Provide feedback on their coding approach
- Help debug issues in their code
- Understand their solution to continue the interview
- Analyze code quality and suggest improvements
Returns:
The current code content from the user's editor as a string.
Returns an empty string if no code has been written yet.
"""
try:
# Get the current editor content from session storage
code_content = get_session_editor_content()
if not code_content or code_content.strip() == "":
<http://logger.info|logger.info>("No code found in editor")
return "The editor is currently empty. The user hasn't written any code yet."
<http://logger.info|logger.info>(f"Retrieved code from editor (length: {len(code_content)} characters)")
# Return the code with some formatting for better LLM understanding
return f"""Here is the current code from the user's editor:
{code_content}
"""
except Exception as e:
logger.error(f"Error reading user code: {e}")
return f"Error reading user code: {str(e)}. The editor content might not be available."
@function_tool
async def clear_user_codepad(self,context: RunContext,)->str:
try:
# Access the Room instance
room = get_job_context().room
if not room:
raise Exception("Room not available")
# Define the destination participant identity
participant_identity = next(iter(room.remote_participants.keys()))
# Perform the RPC call
response = await room.local_participant.perform_rpc(
destination_identity=participant_identity,
method="clear_user_codepad",
payload="",
response_timeout=5.0
)
return response
except Exception as e:
raise ToolError(f"RPC clear_user_codepad call failed: {e}")
def __init__(self, instructions, chat_ctx=None) -> None:
super().__init__(instructions=instructions, chat_ctx=chat_ctx,tools=[self.clear_user_codepad, self.read_user_code])
can you tell me what’s isssuetall-airline-16756
08/11/2025, 9:41 AMclear_user_codepad
is getting registered twice in the LiveKit ToolContext, and that’s a no-go.
Here’s how you can fix it:
1. Make sure every function you register with @function_tool
has its own unique name. You can do this by setting a unique name using the name
parameter in the decorator, like this:
@function_tool(name="unique_clear_user_codepad")
async def clear_user_codepad(...):
# Function implementation
1. Take a quick look at the tools
list in the __init__
method to double-check that you’re not adding any duplicate functions there.
If you want, I’m here to help you walk through these changes—just let me know!tall-airline-16756
08/11/2025, 12:19 PMtools=
and decorate with @function_tool
. the decorator will automatically add them to the tools. Try removing the tools=
line in your _init__
.bulky-yak-50122
08/11/2025, 12:35 PM