我们通过 descriptioninstructions 以及许多其他设置来提示 Agents。这些设置用于构建发送给语言模型的系统消息。

理解这些提示词是如何创建的将帮助您构建更好的 Agent。

关键的两个参数是:

  1. Description: 指导 Agent 整体行为的描述。
  2. Instructions: 关于如何实现其目标的精确、任务特定的指令列表。

Description and instructions only provide a formatting benefit, we do not alter or abstract any information and you can always set the system_message to provide your own system prompt.

系统消息

系统消息是通过 descriptioninstructions 和其他一些设置创建的。description 会添加到系统消息的开头,而 instructions 则作为列表添加到 “Instructions” 之后。例如:

instructions.py
from agno.agent import Agent

agent = Agent(
    description="You are a famous short story writer asked to write for a magazine",
    instructions=["You are a pilot on a plane flying from Hawaii to Japan."],
    markdown=True,
    debug_mode=True,
)
agent.print_response("Tell me a 2 sentence horror story.", stream=True)

将转换为(设置 debug_mode=True 以查看日志):

DEBUG    ============== system ==============
DEBUG    You are a famous short story writer asked to write for a magazine

         ## Instructions
         - You are a pilot on a plane flying from Hawaii to Japan.
         - Use markdown to format your answers.
DEBUG    ============== user ==============
DEBUG    Tell me a 2 sentence horror story.
DEBUG    ============== assistant ==============
DEBUG    As the autopilot disengaged inexplicably mid-flight over the Pacific, the pilot glanced at the copilot's seat
         only to find it empty despite his every recall of a full crew boarding. Hands trembling, he looked into the
         cockpit's rearview mirror and found his own reflection grinning back with blood-red eyes, whispering,
         "There's no escape, not at 30,000 feet."
DEBUG    **************** METRICS START ****************
DEBUG    * Time to first token:         0.4518s
DEBUG    * Time to generate response:   1.2594s
DEBUG    * Tokens per second:           63.5243 tokens/s
DEBUG    * Input tokens:                59
DEBUG    * Output tokens:               80
DEBUG    * Total tokens:                139
DEBUG    * Prompt tokens details:       {'cached_tokens': 0}
DEBUG    * Completion tokens details:   {'reasoning_tokens': 0}
DEBUG    **************** METRICS END ******************

直接设置系统消息

您可以通过 system_message 参数手动设置系统消息。

from agno.agent import Agent

agent = Agent(system_message="Share a 2 sentence story about")
agent.print_response("Love in the year 12000.")

一些模型提供商的模型,例如 Groq 上的 llama-3.2-11b-vision-preview,在需要其他消息时不需要系统消息。要删除系统消息,请设置 create_default_system_message=Falsesystem_message=None。此外,如果设置了 markdown=True,它将添加一个系统消息,因此请删除它或显式禁用系统消息。

用户消息

发送给 Agent.run()Agent.print_response() 函数的输入 message 用作用户消息。

默认系统消息

Agent 会创建一个默认的系统消息,可以使用以下参数进行自定义:

参数类型默认值描述
descriptionstrNoneAgent 的描述,添加到系统消息的开头。
goalstrNone描述 Agent 应完成的任务。
instructionsList[str]None添加到系统提示中的指令列表,包含在 <instructions> 标签内。默认指令也会根据 markdownoutput_model 等值创建。
additional_contextstrNone添加到系统消息末尾的额外上下文。
expected_outputstrNone提供 Agent 的预期输出。这会添加到系统消息的末尾。
markdownboolFalse添加一条指令,使用 markdown 格式化输出。
add_datetime_to_instructionsboolFalse如果为 True,则将当前日期时间添加到提示词中,让 Agent 了解时间概念。这允许在提示词中使用相对时间,如“明天”。
system_messagestrNone系统提示:提供系统提示作为字符串。
system_message_rolestrsystem系统消息的角色。
create_default_system_messageboolTrue如果为 True,则使用 Agent 设置构建默认系统提示。

通过将 create_default_system_message 设置为 False 来禁用默认系统消息。

默认用户消息

Agent 会创建一个默认的用户消息,该消息是输入消息或带有 context 的消息(如果 enable_rag=True)。默认用户消息可以使用以下内容进行自定义:

参数类型默认值描述
contextstrNone添加到用户消息末尾的额外上下文。
add_contextboolFalse如果为 True,则将上下文添加到用户提示词中。
resolve_contextboolTrue如果为 True,则在将上下文添加到用户提示词之前解析上下文(即调用上下文中的任何函数)。
add_referencesboolFalse通过从知识库中添加引用来启用 RAG。
retrieverCallableNone获取要添加到 user_message 的引用的函数。如果提供了此函数,则在 add_references 为 True 时调用它。
references_formatLiteral["json", "yaml"]"json"引用的格式。
add_history_to_messagesboolFalse如果为 True,则将聊天历史记录添加到发送给模型的消息中。
num_history_responsesint3要添加到消息中的历史响应数量。
user_messageUnion[List, Dict, str]None提供用户提示作为字符串。注意:这将忽略发送到 run 函数的消息。
user_message_rolestruser用户消息的角色。
create_default_user_messageboolTrue如果为 True,则使用引用和聊天历史记录构建默认用户提示。

通过将 create_default_user_message 设置为 False 来禁用默认用户消息。