what is needed to make ai callable annotatd params...
# ask-ai
a
what is needed to make ai callable annotatd params optional vs required?
g
To make parameters optional or required in LiveKit's function system, you can control this by setting default values for the parameters. Parameters without default values are automatically required, while those with default values are optional. For example, in the function definition, if you omit a default value for a parameter, it becomes required. Conversely, if you provide a default value, the parameter is considered optional.
Copy code
from livekit.agents.llm import FunctionContext, TypeInfo
from typing import Annotated, Optional

fnc_ctx = FunctionContext()

@fnc_ctx.ai_callable(
    name="finalize_conversation",
    description="Finalize the conversation and initiate grading/scoring."
)
async def finalize_conversation(
        is_over: Annotated[bool, TypeInfo(description="Whether conversation should be considered finished.")],
        hints: Annotated[int, TypeInfo(description="Number of hints requested by user")],
        notes: Annotated[Optional[str], TypeInfo(description="Additional notes about the conversation")] = None
) -> str:
    if is_over:
        return f"Conversation ended with {hints} hints used" + (f" Notes: {notes}" if notes else "")
    return "Conversation continues"
In this example,
is_over
and
hints
are required because they lack default values, while
notes
is optional due to its default value of
None
. Sources: - LiveKit Slack Discussion 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.