Update foundational examples to use "user" role

Use system_instruction on LLM service constructors instead of adding
system messages to LLMContext. Messages added to context now use
"user" role.
This commit is contained in:
Aleix Conchillo Flaqué
2026-03-05 16:17:32 -08:00
parent 18494658c3
commit 593b75bc8b
179 changed files with 271 additions and 335 deletions

View File

@@ -122,11 +122,7 @@ async def load_conversation(params: FunctionCallParams):
await params.result_callback({"success": False, "error": str(e)})
# Test message munging ...
messages = [
{
"role": "system",
"content": """You are a helpful LLM in a WebRTC call. Your goal is to demonstrate your
system_instruction = """You are a helpful LLM in a WebRTC call. Your goal is to demonstrate your
capabilities in a succinct way. Your output will be spoken aloud, so avoid special characters that
can't easily be spoken, such as emojis or bullet points. Respond to what the user said in a creative
and helpful way.
@@ -151,13 +147,7 @@ indicate you should use the get_image tool are:
- Tell me about what you see.
- Tell me something interesting about what you see.
- What's happening in the video?
""",
},
# {"role": "user", "content": ""},
# {"role": "assistant", "content": []},
# {"role": "user", "content": "Tell me"},
# {"role": "user", "content": "a joke"},
]
"""
weather_function = FunctionSchema(
name="get_current_weather",
@@ -262,7 +252,10 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
),
)
llm = GoogleLLMService(api_key=os.getenv("GOOGLE_API_KEY"))
llm = GoogleLLMService(
api_key=os.getenv("GOOGLE_API_KEY"),
system_instruction=system_instruction,
)
# you can either register a single function for all function calls, or specific functions
# llm.register_function(None, fetch_weather_from_api)
@@ -272,7 +265,7 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
llm.register_function("load_conversation", load_conversation)
llm.register_function("get_image", get_image)
context = LLMContext(messages, tools)
context = LLMContext(tools=tools)
user_aggregator, assistant_aggregator = LLMContextAggregatorPair(
context,
user_params=LLMUserAggregatorParams(vad_analyzer=SileroVADAnalyzer()),
@@ -308,9 +301,9 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
client_id = get_transport_client_id(transport, client)
# Kick off the conversation.
messages.append(
context.add_message(
{
"role": "system",
"role": "user",
"content": f"Please introduce yourself to the user. Use '{client_id}' as the user ID during function calls.",
}
)