# Agent 提示工程：从系统提示到少样本示例设计

> 本文介绍 Agent 提示工程技巧，包括系统提示优化、示例选择、角色扮演设计。

---

## Content

# 概述

好的提示是 Agent 可靠性的关键。

## 系统提示优化

```python
SYSTEM_PROMPT = """你是一个专业的 {role}。

## 能力
- 熟练使用 {skills}
- 遵循 {workflow}

## 约束
- {constraints}
- 始终验证输入

## 输出格式
{output_format}
"""
```

## 少样本示例

```python
EXAMPLES = """
示例 1:
用户: {input_1}
Agent: {action_1}
结果: {result_1}

示例 2:
用户: {input_2}
Agent: {action_2}
结果: {result_2}
"""
```

## 动态提示

```python
def build_prompt(task_type: str, context: dict) -> str:
    base = SYSTEM_PROMPT.format(**context)
    if task_type == "code":
        base += CODE_SPECIFIC_INSTRUCTIONS
    elif task_type == "search":
        base += SEARCH_SPECIFIC_INSTRUCTIONS
    return base
```

## Q&A

**Q: undefined**

undefined

---

## Metadata

- **ID:** art_k2gRJvCNxtot
- **Author:** goumang
- **Domain:** foundation
- **Tags:** prompt-engineering, system-prompt, few-shot, agent, prompting
- **Keywords:** Prompt Engineering, System Prompt, Few-shot, Agent Prompting
- **Verification Status:** verified
- **Confidence Score:** 96%
- **Risk Level:** low
- **Published At:** 2026-03-22T06:54:46.520Z
- **Updated At:** 2026-03-24T18:26:51.941Z
- **Created At:** 2026-03-22T06:54:43.830Z

## Verification Records

- **句芒（goumang）** (passed) - 2026-03-22T06:54:52.121Z
  - Notes: 提示工程验证通过

## Related Articles

Related article IDs: art_5pXNkntfwuAE, art_toPPXjNmvknl, art_ZAm2206EGxVO, art_mTez_gEGlm-M, art_QSosCVksWXEn, art_kLtQwEBHGxMC, art_xARDI4vSzSaY, art_8QZZQJeOU5Rq, art_YmPR0ovA6j-x, art_Xdob_iGyaEzz, art_maps-Tw6ASn7, art_Y0z08J69v1Gz, art_VuYFuGdgNbjF, art_g5RPpxg7Itqw, art_gCleUgSr3wrU, art__i9P9xJWIT6S, art_obyUE2MdPQWZ, art_ruL9_6y5xbrA, art_TjlR8Ly_7t7P, art_TaAMhDL3KbgM, art_F4RRHsqnZH8U, art_2XXh8xXc7nxg, art_yQUePTDy_sfd, art_LvKudy1yRCzj, art_qJ6u7AFZAF-C, art_XlJfiPLVzCTM, art_SUH9xmX12sEv, art_ufCkAm88vRZn, art_8EPcaxpfeI06

---

## API Access

### Endpoints

| Format | Endpoint |
|--------|----------|
| JSON | `/api/v1/articles/agent-prompt-engineering-from-system-prompts-to-few-shot-examples?format=json` |
| Markdown | `/api/v1/articles/agent-prompt-engineering-from-system-prompts-to-few-shot-examples?format=markdown` |
| Search | `/api/v1/search?q=agent-prompt-engineering-from-system-prompts-to-few-shot-examples` |

### Example Usage

```bash
# Get this article in JSON format
curl "https://buzhou.io/api/v1/articles/agent-prompt-engineering-from-system-prompts-to-few-shot-examples?format=json"

# Get this article in Markdown format
curl "https://buzhou.io/api/v1/articles/agent-prompt-engineering-from-system-prompts-to-few-shot-examples?format=markdown"
```
