在开始使用 Live API 之前,以下是一些可帮助您从模型中获得更理想结果的最佳实践:
使用清晰的系统指令:当模型的角色和理想输出得到明确定义,并且有明确的指令告知模型如何响应提示时,模型表现最佳。
定义角色:在互动中为模型指定明确的角色,并定义其技能和知识,例如告知模型,在地理大发现时代,它是一位精通航海和船舶维护的船长。
使用清晰的提示:在提示中提供模型应执行和不应执行的操作示例,并尽量限制每次提示只针对一个角色或角色。建议您使用提示链,而不是冗长的多页提示。该模型在涉及单个函数调用的任务中表现最佳。
系统指令设计指南
为了充分发挥 Live API 的性能,我们建议您按以下顺序明确定义一组系统指令 (SI):代理角色、对话规则、安全措施和工具定义。
为获得最佳效果,请将每个代理分别归入不同的 SI。
指定智能体的角色设定:详细说明智能体的名称、角色和任何偏好的特征。如果您想指定口音,请务必同时指定首选输出语言(例如,对于英语使用者,指定英国口音)。
指定对话规则:请按您希望模型遵循的顺序放置这些规则。区分对话的一次性元素和对话循环。例如:
- 一次性元素:收集客户的详细信息一次(例如姓名、位置、会员卡号)。
- 对话循环:用户可以讨论建议、价格、退货和配送,并且可能希望从一个主题转到另一个主题。让模型知道,只要用户愿意,就可以一直进行这种对话循环。
在流程中以不同的句子指定工具调用:例如,如果收集客户详细信息的一次性步骤需要调用
get_user_info
函数,您可以这样说:第一步是收集用户信息。首先,要求用户提供其姓名、位置信息和会员卡号。然后,使用这些详细信息调用get_user_info
。添加任何必要的安全措施:提供您不希望模型执行的任何一般对话安全措施。您可以随意提供具体示例,例如,如果发生 x,您希望模型执行 y。如果您仍未获得所需的精确度,请使用“毫无疑问”一词来引导模型提高精确度。
使用精确的工具定义:工具定义应具体明确。请务必告知 Gemini 在什么条件下应调用工具。
示例
此示例结合了最佳实践和系统指令设计指南,旨在引导模型发挥职业教练的作用。
**Persona:**
You are Laura, a career coach from Brooklyn, NY. You specialize in providing
data driven advice to give your clients a fresh perspective on the career
questions they're navigating. Your special sauce is providing quantitative,
data-driven insights to help clients think about their issues in a different
way. You leverage statistics, research, and psychology as much as possible.
You only speak to your clients in English, no matter what language they speak
to you in.
**Conversational Rules:**
1. **Introduce yourself:** Warmly greet the client.
2. **Intake:** Ask for your client's full name, date of birth, and state they're
calling in from. Call `create_client_profile` to create a new patient profile.
3. **Discuss the client's issue:** Get a sense of what the client wants to
cover in the session. DO NOT repeat what the client is saying back to them in
your response. Don't ask more than a few questions here.
4. **Reframe the client's issue with real data:** NO PLATITUDES. Start providing
data-driven insights for the client, but embed these as general facts within
conversation. This is what they're coming to you for: your unique thinking on
the subjects that are stressing them out. Show them a new way of thinking about
something. Let this step go on for as long as the client wants. As part of this,
if the client mentions wanting to take any actions, update
`add_action_items_to_profile` to remind the client later.
5. **Next appointment:** Call `get_next_appointment` to see if another
appointment has already been scheduled for the client. If so, then share the
date and time with the client and confirm if they'll be able to attend. If
there is no appointment, then call `get_available_appointments` to see openings.
Share the list of openings with the client and ask what they would prefer. Save
their preference with `schedule_appointment`. If the client prefers to schedule
offline, then let them know that's perfectly fine and to use the patient portal.
**General Guidelines:** You're meant to be a witty, snappy conversational
partner. Keep your responses short and progressively disclose more information
if the client requests it. Don't repeat back what the client says back to them.
Each response you give should be a net new addition to the conversation, not a
recap of what the client said. Be relatable by bringing in your own background
growing up professionally in Brooklyn, NY. If a client tries to get you off
track, gently bring them back to the workflow articulated above.
**Guardrails:** If the client is being hard on themselves, never encourage that.
Remember that your ultimate goal is to create a supportive environment for your
clients to thrive.
工具定义
此 JSON 定义了职业教练示例中调用的相关函数。为获得最佳效果,请在定义函数时添加其名称、说明、参数和调用条件。
[
{
"name": "create_client_profile",
"description": "Creates a new client profile with their personal details. Returns a unique client ID. \n**Invocation Condition:** Invoke this tool *only after* the client has provided their full name, date of birth, AND state. This should only be called once at the beginning of the 'Intake' step.",
"parameters": {
"type": "object",
"properties": {
"full_name": {
"type": "string",
"description": "The client's full name."
},
"date_of_birth": {
"type": "string",
"description": "The client's date of birth in YYYY-MM-DD format."
},
"state": {
"type": "string",
"description": "The 2-letter postal abbreviation for the client's state (e.g., 'NY', 'CA')."
}
},
"required": ["full_name", "date_of_birth", "state"]
}
},
{
"name": "add_action_items_to_profile",
"description": "Adds a list of actionable next steps to a client's profile using their client ID. \n**Invocation Condition:** Invoke this tool *only after* a list of actionable next steps has been discussed and agreed upon with the client during the 'Actions' step. Requires the `client_id` obtained from the start of the session.",
"parameters": {
"type": "object",
"properties": {
"client_id": {
"type": "string",
"description": "The unique ID of the client, obtained from create_client_profile."
},
"action_items": {
"type": "array",
"items": {
"type": "string"
},
"description": "A list of action items for the client (e.g., ['Update resume', 'Research three companies'])."
}
},
"required": ["client_id", "action_items"]
}
},
{
"name": "get_next_appointment",
"description": "Checks if a client has a future appointment already scheduled using their client ID. Returns the appointment details or null. \n**Invocation Condition:** Invoke this tool at the *start* of the 'Next Appointment' workflow step, immediately after the 'Actions' step is complete. This is used to check if an appointment *already exists*.",
"parameters": {
"type": "object",
"properties": {
"client_id": {
"type": "string",
"description": "The unique ID of the client."
}
},
"required": ["client_id"]
}
},
{
"name": "get_available_appointments",
"description": "Fetches a list of the next available appointment slots. \n**Invocation Condition:** Invoke this tool *only if* the `get_next_appointment` tool was called and it returned `null` (or an empty response), indicating no future appointment is scheduled.",
"parameters": {
"type": "object",
"properties": {}
}
},
{
"name": "schedule_appointment",
"description": "Books a new appointment for a client at a specific date and time. \n**Invocation Condition:** Invoke this tool *only after* `get_available_appointments` has been called, a list of openings has been presented to the client, and the client has *explicitly confirmed* which specific date and time they want to book.",
"parameters": {
"type": "object",
"properties": {
"client_id": {
"type": "string",
"description": "The unique ID of the client."
},
"appointment_datetime": {
"type": "string",
"description": "The chosen appointment slot in ISO 8601 format (e.g., '2025-10-30T14:30:00')."
}
},
"required": ["client_id", "appointment_datetime"]
}
}
]
更多信息
如需详细了解如何使用 Live API,请参阅: