> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 提示词

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

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

关键的两个参数是：

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

<Note>
  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.
</Note>

## 系统消息

系统消息是通过 `description`、`instructions` 和其他一些设置创建的。`description` 会添加到系统消息的开头，而 `instructions` 则作为列表添加到 "Instructions" 之后。例如：

```python instructions.py theme={null}
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` 以查看日志）：

```js theme={null}
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` 参数手动设置系统消息。

```python theme={null}
from agno.agent import Agent

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

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

## 用户消息

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

## 默认系统消息

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

| 参数                              | 类型          | 默认值      | 描述                                                                              |
| ------------------------------- | ----------- | -------- | ------------------------------------------------------------------------------- |
| `description`                   | `str`       | `None`   | Agent 的描述，添加到系统消息的开头。                                                           |
| `goal`                          | `str`       | `None`   | 描述 Agent 应完成的任务。                                                                |
| `instructions`                  | `List[str]` | `None`   | 添加到系统提示中的指令列表，包含在 `<instructions>` 标签内。默认指令也会根据 `markdown`、`output_model` 等值创建。 |
| `additional_context`            | `str`       | `None`   | 添加到系统消息末尾的额外上下文。                                                                |
| `expected_output`               | `str`       | `None`   | 提供 Agent 的预期输出。这会添加到系统消息的末尾。                                                    |
| `markdown`                      | `bool`      | `False`  | 添加一条指令，使用 markdown 格式化输出。                                                       |
| `add_datetime_to_instructions`  | `bool`      | `False`  | 如果为 True，则将当前日期时间添加到提示词中，让 Agent 了解时间概念。这允许在提示词中使用相对时间，如“明天”。                   |
| `system_message`                | `str`       | `None`   | 系统提示：提供系统提示作为字符串。                                                               |
| `system_message_role`           | `str`       | `system` | 系统消息的角色。                                                                        |
| `create_default_system_message` | `bool`      | `True`   | 如果为 True，则使用 Agent 设置构建默认系统提示。                                                  |

<Tip>
  通过将 `create_default_system_message` 设置为 `False` 来禁用默认系统消息。
</Tip>

## 默认用户消息

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

| 参数                            | 类型                        | 默认值      | 描述                                                                    |
| ----------------------------- | ------------------------- | -------- | --------------------------------------------------------------------- |
| `context`                     | `str`                     | `None`   | 添加到用户消息末尾的额外上下文。                                                      |
| `add_context`                 | `bool`                    | `False`  | 如果为 True，则将上下文添加到用户提示词中。                                              |
| `resolve_context`             | `bool`                    | `True`   | 如果为 True，则在将上下文添加到用户提示词之前解析上下文（即调用上下文中的任何函数）。                         |
| `add_references`              | `bool`                    | `False`  | 通过从知识库中添加引用来启用 RAG。                                                   |
| `retriever`                   | `Callable`                | `None`   | 获取要添加到 user\_message 的引用的函数。如果提供了此函数，则在 `add_references` 为 True 时调用它。 |
| `references_format`           | `Literal["json", "yaml"]` | `"json"` | 引用的格式。                                                                |
| `add_history_to_messages`     | `bool`                    | `False`  | 如果为 True，则将聊天历史记录添加到发送给模型的消息中。                                        |
| `num_history_responses`       | `int`                     | `3`      | 要添加到消息中的历史响应数量。                                                       |
| `user_message`                | `Union[List, Dict, str]`  | `None`   | 提供用户提示作为字符串。注意：这将忽略发送到 run 函数的消息。                                     |
| `user_message_role`           | `str`                     | `user`   | 用户消息的角色。                                                              |
| `create_default_user_message` | `bool`                    | `True`   | 如果为 True，则使用引用和聊天历史记录构建默认用户提示。                                        |

<Tip>
  通过将 `create_default_user_message` 设置为 `False` 来禁用默认用户消息。
</Tip>
