Optimizing agent system prompts with Amazon Bedrock AgentCore
https://aws.amazon.com/blogs/machine-learning/optimizing-agent-system-prompts-with-amazon-bedrock-agentcore/📌 用 AI Agent 修 AI Agent:AWS AgentCore 用「反思式」設計自動優化 System Prompt
TL;DR:AWS Bedrock AgentCore 用 agent 讀取自家的執行紀錄自動改寫 system prompt,效能打平甚至超越 GEPA、MIPROv2,且優化耗時縮短逾十倍。
過去要救一個表現不佳的 agent,工程師得一行一行翻執行紀錄(trace),猜哪裡出錯,手動調整 prompt 與工具描述,再重新跑一次評估。AWS 這次做的事情,是讓另一個 agent 來做這件苦工。
🤔 從人工除錯到自動化迴圈
Amazon Bedrock AgentCore 的 Observability 功能會記錄 agent 的行為軌跡,Evaluation 則提供品質訊號。AgentCore optimization 把兩者串起來:用 production traces 提出配置變更建議,先透過離線批次評估驗證,再上線做 A/B 測試,最後才把表現較好的版本推廣出去。整個流程的核心,是一個被稱為「reflector」的推理元件,負責審視已評分的 agent 行為、找出成功與失敗案例之間的規律,並提出針對性的配置修改建議。
🧩 用檔案系統餵資料,而非硬塞進 context window
Agent trace 通常很長,就算只有幾十筆,也很容易塞爆模型的 context window。AWS 的做法不是截斷或預先摘要,而是把完整的 trace 語料庫放進一個目錄,交給 reflector agent 用 shell 工具自行探索:可以用 ls 列檔案、grep 搜尋、cat 讀取單筆 trace、diff 比較輸出,自由挑選要細看的成功與失敗案例。整個過程沒有固定的訊號萃取或摘要流程,由 reflector 自己判斷哪些證據重要、該做什麼比較,再把結論轉譯成配置修改建議。
任何提案在被採用前,都必須先通過平臺層級的 guardrails,防止優化過程中常見的「跑偏」現象:prompt 越改越長、直接把 trace 裡的用詞當成範例寫進 prompt、或是為了衝高評分分數而放寬安全限制。
目前實際驅動 AgentCore optimization 的是 Single Agent Reflector:單一 agent 一次看完整組 trace,先掃過分數分布,再深入檢視最有資訊量的片段,對比成功與失敗案例,輸出一組連貫的配置修改。每個 optimization epoch 都重複「評分 → 反思 → 套用通過 guardrail 的修改」這個循環,可以多跑幾個 epoch 換取更好的品質。
另一個是實驗性的 Sub-Agent Reflector,已在 Strands 開源 GitHub repo 中釋出初步版本。它用一群 sub-agent 分頭處理,每個 sub-agent 只負責分析單一 trace(素材未列出具體的三層分析內容),各自回傳精簡的發現與一條修正規則。因為每個 sub-agent 都在自己獨立的 context window 中運作,不會被其他 trace 干擾,最後由 orchestrator 彙整發現、歸納重複模式、去除冗餘,濃縮成一組配置修改。單一 reflector 一次掃過大量 trace 時,容易只聚焦在最先看到的五到十筆案例上,漏掉只出現在少數案例中的失敗模式,Sub-Agent Reflector 正是為了補這個缺口而設計。
📊 AppWorld 與 WebShop 上的表現
AWS 在兩個公開 benchmark 上,把 Single Agent Reflector、Sub-Agent Reflector 與 GEPA、MIPROv2 兩個既有方法放在一起比較,每個方法都掃過設定空間、回報最佳結果連同所需 turn 數與實際耗時。
| 方法 | AppWorld 分數 | AppWorld 耗時 | WebShop 分數 | WebShop 耗時 |
|---|---|---|---|---|
| Single Agent Reflector | 81.55% | 6 分鐘、20 turns | 78.31% | 1 分鐘、5 turns |
| Sub-Agent Reflector | 95.83% | 較長(未列具體數字) | 79.15% | 較長(未列具體數字) |
| GEPA / MIPROv2(最佳基準) | 對照組 | 慢 18~36 倍 | 對照組 | — |
Single Agent Reflector 在 AppWorld 上比 GEPA 快 18 倍、比 MIPROv2 快 36 倍,分數仍相當甚至更好;Sub-Agent Reflector 則拿下兩個 benchmark 的最高分,在 AppWorld 上比基準線高出 23 分、比次佳方法再高 16 分,在 WebShop 上也比基準線高 4 分。逐 trace 拆解分析的效果在 AppWorld 上最明顯,因為那裡的失敗模式較分散,單一 reflector 一次通讀容易漏掉少數模式。
💡 兩種設計各自的取捨
整體反思讓 Single Agent Reflector 用遠少於迭代式方法的 turn 數與時間就能拿到有競爭力的分數,適合追求快速迭代週期的場景;而 sub-agent 分工讓 Sub-Agent Reflector 有更高的品質天花板,代價是需要更多算力與時間。
⚠️ 仍是輔助工具,不是自動駕駛
AWS 特別強調,Responsible AI 的考量是這個流程的一部分:推薦結果應該被審查與測試後才使用,guardrails 只是在候選更新被採用前先做篩選,並不代表可以完全跳過人工把關。
🎯 實務啟示
如果你正在維運一套會累積大量 production trace 的 agent 系統,這個做法提供了一個可參考的迭代模型:與其手動翻 log 調 prompt,不如把「評分 + 反思 + guardrail + A/B 測試」變成常態化流程,同時視情境在效率(Single Agent Reflector)與品質天花板(Sub-Agent Reflector)之間取捨。
🔗 來源
- 標題:Optimizing agent system prompts with Amazon Bedrock AgentCore
- 作者/機構:Han Ding, AWS Machine Learning Blog
- 連結:https://aws.amazon.com/blogs/machine-learning/optimizing-agent-system-prompts-with-amazon-bedrock-agentcore/
#AWS #BedrockAgentCore #AIAgents #PromptEngineering #LLMOps #AgentEvaluation #AutoPromptOptimization #GEPA #MIPROv2 #ObservabilityAI
原始資料 AWS ML · 收集於 2026-09-16
摘要原文
In a previous launch post , we introduced AgentCore optimization, a capability of Amazon Bedrock AgentCore that can help you improve the quality of your agents. Improving a low-scoring agent has traditionally been a manual process. You review long traces to find where the agent goes wrong, tune individual components such as prompts, tool descriptions, and skills, and rerun evaluations to check for improvement. With AgentCore optimization, you can use production traces to propose configuration changes, validate them through offline batch evaluation and online A/B testing on live traffic, and promote the winners. AgentCore Observability, a capability of Amazon Bedrock AgentCore, provides visibility into agent behavior, and evaluations provide signals about agent quality. Together, recommendations , configuration bundles , and validation through A/B testing provide a workflow for improving an agent. The system prompt optimizer in AgentCore uses agent traces recorded in AgentCore Observability together with a reward signal to produce an improved system prompt. For the market trends agent , the recommendation compares an existing system prompt with a revised version and explains the trace patterns that motivated the changes. Figure 1: A recommendation compares the existing system prompt with a revised prompt for the market trends agent The recommendation interface also provides an explanation of the proposed changes, so you can review the reasoning before deciding whether to test the recommendation. Figure 2: An explanation accompanies the recommended system prompt to support review and validation This post is a technical companion to the launch post. We take a deeper look at the system prompt optimizer and explain how its recommendation engine works. We also share evaluation results for the Single Agent Reflector and the experimental, open source Sub-Agent Reflector on two publicly available benchmarks, alongside GEPA and MIPROv2 . The system prompt optimizer is executed by an agentic reflector, the reasoning component of the optimizer. It reviews evaluated agent behavior, identifies patterns that distinguish successful runs from failures, and proposes targeted changes to the agent configuration. In the system-prompt optimization workflow, its primary output is a revised system prompt accompanied by an explanation of why the proposed changes should improve agent quality. Agent traces are often lengthy, and even a few dozen can quickly exceed a model’s context window. Passing every trace directly into the reflector prompt is therefore impractical. Instead of truncating or pre-summarizing traces to fit, the complete trace corpus is made available to the reflector through a filesystem. The design uses a minimal workflow. An evaluator scores a collection of traces and writes them to a directory accessible to the reflector agent. The reflector is given a shell tool, directed to that directory, and instructed to propose updates to the agent configuration by examining patterns of success and failure across the traces. The reflector can inspect the corpus as needed. It can list files, search with grep , read traces with cat , compare outputs with diff , and selectively examine successful and unsuccessful runs. We don’t impose a fixed signal-extraction or trace-summarization pipeline. Instead, the reflector determines which evidence matters, what comparisons to make, and how to translate those findings into configuration changes. It then returns proposed edits to the agent configuration. Before any proposal can be applied, it must pass through platform-level guardrails. Responsible AI considerations are part of this workflow. Recommendations should be reviewed and tested before use, and the guardrails described later in this post screen candidate updates before they can be promoted. The Single Agent Reflector drives system prompt recommendations in AgentCore optimization today. One reflector agent works through the full trace set in a single pass. It surveys the score distribution, drills into the most informative segments of individual traces, contrasts successes with failures, and returns one coherent set of edits to the agent configuration. Each optimization epoch repeats this cycle: score the traces, reflect, and accept the edits that pass the guardrails. You can run additional epochs to trade optimization time for further quality gains. Figure 3 shows this flow. Evaluated traces are written to a shared directory, where a single reflector inspects the evidence and produces recommended configuration edits. The guardrails screen those edits before they’re accepted. Figure 3: The Single Agent Reflector analyzes evaluated traces and returns guarded configuration edits The Sub-Agent Reflector extends the Single Agent Reflector. It trades some efficiency for a higher quality ceiling by using a swarm of agents to explore different parts of the trace set dynamically. A single reflector pass can focus on patterns in the first 5–10 traces it examines and miss failure modes that appear only in a smaller portion of the corpus. Each sub-agent performs a three-level analysis on a single trace: Each sub-agent returns a concise finding and a corrective rule. Because each sub-agent operates in its own context window, it can focus on one trace without being influenced by the others. The orchestrator aggregates the findings, generalizes recurring patterns, removes duplicates, and condenses the resulting insights into configuration changes. Figure 4 shows the multi-agent flow. The orchestrator delegates individual trace analyses to sub-agents, collects their findings, and synthesizes the findings into a single set of guarded configuration edits. Figure 4: The Sub-Agent Reflector uses independent trace analyses to inform guarded configuration edits We have launched this experimental feature as a preliminary release in the Strands open-source GitHub repository . Naive configuration optimization can drift in predictable ways: prompts can grow longer after optimization, prompts can quote terms from traces as examples, and safety constraints can be relaxed or softened in pursuit of an evaluator score. We apply rubric-based guardrails to every candidate update before it is accepted: We evaluated the Single Agent Reflector and Sub-Agent Reflector alongside two established baselines, GEPA and MIPROv2 , on two public benchmarks: AppWorld and WebShop . For each method, we swept the configuration space and reported the best result with its number of turns and wall-clock optimization time. Single Agent Reflector offers the best quality-per-cost trade-off. On AppWorld, it reaches 81.55 percent in 6 minutes and 20 turns, an 18× speed-up over GEPA and a 36× speed-up over MIPROv2 for a comparable or better score. On WebShop, it reaches 78.31 percent with 5 turns and 1 minute of wall-clock time. This variant is well suited when you want fast iteration cycles. Sub-Agent Reflector achieves the highest quality on both benchmarks. On AppWorld, it reaches 95.83 percent, a 23-point lift over the baseline and 16 points above the next-best method. On WebShop, it reaches 79.15 percent, a 4-point lift over the baseline. The per-trace sub-agent analysis has the greatest effect on AppWorld, where failure modes are diverse and a single reflector pass can miss minority patterns. These results reflect the two designs described earlier. Whole-set reflection gives the Single Agent Reflector its efficiency: it requires far fewer turns and minutes than iterative methods to reach competitive scores. Sub-agent decomposition gives the Sub-Agent Reflector a higher quality ceiling by analyzing each trace independently before aggregating the findings. This approach helps it identify failure modes that a single pass over many traces can miss. Figure 5 summarizes the AppWorld and WebShop comparison across the four methods.
由 claude-code/sonnet 自動生成