Share
Embed
Interventions と Plugins | Kiro と学ぶ Strands Agents 04
Level 300。Strands Agents の Agent に、危ない道具の前で人の承認を取る HumanInTheLoop、Hook と道具から止めて再開する Interrupts、Hook と道具をまとめる Plugins、要るときだけ手順を読む Strands Agents の Skills、Deny や Guide を返す Interventions と Steering を足す方法を、strandsagents.com の公式ドキュメントを元に、構成図、流れの図、コードと本物の出力で説明します。家電のお店の問い合わせ窓口のエージェント (データは架空) で、返金の前に端末で y/n/t と聞かれるところ、Cedar の決まりで bob の返金が聞かれずに拒否されるところ、interrupt で止まった Agent を答えで再開するところ、5,000 円を超える返金を Deny で止めるところ、強い言い方のメールが Steering で言い直されるところを、Strands Agents 1.64.0 と東京のリージョンの Amazon Bedrock で動かした出力で見せます。シリーズ「Kiro と学ぶ Strands Agents」の 04 です。
Riku INADA PRO
November 09, 2026
Transcript
46 slides
-
Kiro と学ぶ Strands Agents 04 作り込む Interventions と Plugins Interrupts、
Human in the loop、Skills 04 Level 300 / 2026-11 時点 2026 年 11 ⽉ 稲⽥ ⼤陸 アマゾン ウェブ サービス ジャパン © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. Kiro + Strands Agents 1 -
はじめに ⾃⼰紹介 稲⽥ ⼤陸 いなだ りく (いなりく) アマゾン ウェブ サービス
ジャパン合同会社 ソリューションアーキテクト 製造業のお客様を中⼼に⽀援 最近の取り組み AI 駆動開発ライフサイクルの推進 Kiro と AWS Amplify の情報発信 © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. X @inada_riku Speaker Deck speakerdeck.com/inariku Zenn zenn.dev/inariku GitHub github.com/inariku 2 -
はじめに シリーズの中の位置 いまは 04 Interventions と Plugins、次は 05 Sessions と
Memory はじめる 01–02 作り込む 03–07 確かめる 01 をはじめる 前に読む Hooks と Lifecycle 03 controls 02 Tools と MCP 04 と Plugins Strands Agents Interventions 次に読む 09 Observability と Evals 09 載せて広げる 08–10 Deploy と Secure 08 for production 10 Strands harness 05 Sessions と Memory output 06 Structured と Streaming 07 Multi-agent © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 3 -
はじめに 問い合わせ窓⼝のエージェントに、承認と判断を⾜す 問い合わせ窓⼝のエージェント: 家電のお店の配送と返⾦の問い合わせに答える (データは架空) 1 動く前に⼈の承認を取る 2 Interrupt で⽌めて再開する
3 Plugins と Skills で Agent を広げる © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 4 Interventions と Steering で判断を返す 4 -
04 Interventions と Plugins 第 1 部 y/n/t 動く前に⼈の 承認を取る
© 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 5 -
1 動く前に⼈の承認を取る 全部の呼び出しで聞くと、⼈は読まずに承認する 全部の呼び出しで聞く 全部の呼び出しで聞くと、 決定疲れで読まずに 承認するようになる hitl_min.py の出⼒の 2
⾏⽬ Tool #1: track_order classifier=True なら、 危ない呼び出しでだけ⽌まる。 配送を⾒る track_order は 聞かれずに動いた © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 6 -
1 動く前に⼈の承認を取る 危ない呼び出しだけ聞く最⼩の形 hitl_min.py from strands import Agent from strands.vended_interventions.hitl
import ( HumanInTheLoop) from d04.base import PROMPT, model from d04.shop import process_refund, track_order HumanInTheLoop を agent = Agent( model=model, tools=[track_order, process_refund], system_prompt=PROMPT, interventions=[HumanInTheLoop( classifier=True, ask="stdio", enable_trust=True)], ) agent("ORD-5521 の配送を確かめてから、9,800 円を返⾦して") ask="stdio" で © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. interventions に 渡す。 classifier=True で 分類器を使う。 端末に問いを出す。 enable_trust=True で t の答えを使う。 動かした出⼒は次の⾯ 7 -
1 動く前に⼈の承認を取る 端末に出る承認の問い hitl_min.py の出⼒ (端末で y と答えた) Tool #1:
track_order Tool #2: process_refund Approve "process_refund" — Financial transaction; issuing refund money? Input: {"order_id": "ORD-5521", "yen": 9800} (y/n/t): y 配送は11⽉2⽇到着済みです。 9,800円の返⾦を受け付けました。 process_refund の前で、分類器の理由と Input を添えて (y/n/t) と聞かれた。y と 答えたあとで返⾦が動いた © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 8 -
1 動く前に⼈の承認を取る 答え⽅と、分類器の既定 答え どうなるか y、yes その回だけ承認する t、trust enable_trust=True のとき、同じ道具のこのあとの呼び出しも、
Agent がある間ずっと承認する 拒否する。Agent は拒否されたと知り、利⽤者に伝えるか別の それ以外 ⼿を取る 分類器の既定は LLM judge で、Agent の モデル (auxiliary model を設定していればそちら) で動く。classifier を 付けないと、どの呼び出しでも聞く © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 9 -
1 動く前に⼈の承認を取る 分類器に任せない道具は ! で否定する 左から順に⾒て、最初に当たった所で決まる allowed_tools の t で信頼した
allowed_tools 分類器が 分類器が「危ない」 !process_refund 道具 にある 「安全」 か、分類器の失敗 必ず聞く 聞かずに動く 聞かずに動く 聞かずに動く 聞く allowed_tools=["!process_refund"] で t と答えた出⼒の 3〜5 ⾏⽬ (hitl_hard.py) Approve "process_refund"? Input: {"order_id": "ORD-5521", "yen": 9800} (y/n/t): t 返⾦処理ができませんでした。 否定した道具は分類器を通らず (問いに理由が無い)、t と答えても返⾦は拒否された © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 10 -
1 動く前に⼈の承認を取る Cedar を HumanInTheLoop の前に置く interventions=[cedar, HumanInTheLoop(...)] の順に並べる。Cedar が拒否すると
後ろは⾶ばされ、bob の返⾦は⼈に聞かずに拒否された (コードと出⼒は付録 A2、A3) © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 11 -
04 Interventions と Plugins interrupt desk-approval 第 2 部 Interrupt
で ⽌めて再開する © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. interruptResponse end_turn 12 -
2 Interrupt で⽌めて再開する ⽌めて、答えて、再開する アプリ Agent (Hook) agent("ORD-5521 を返⾦して") stop_reason="interrupt"、interrupts
event.interrupt(...) ⼈に聞いて答えを作る agent([{"interruptResponse": ...}]) stop_reason="end_turn" interrupt() が答えを返す result.stop_reason が interrupt の間は、result.interrupts ごとに interruptResponse を作り、agent(responses) で⽌まった所から再開する © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 13 -
2 Interrupt で⽌めて再開する Hook で、道具 1 回ごとに承認を取る interrupt_hook.py の 7〜15
⾏⽬ (import は A7) def approve(event: BeforeToolCallEvent): use = event.tool_use if use["name"] != "process_refund": return answer = event.interrupt( "desk-approval", reason=use["input"]) if answer != "y": event.cancel_tool = "担当者が断った" BeforeToolCallEvent で event.interrupt(name, reason=...) を呼ぶと、再開したあとに ⼈の答えが返る。 y でなければ、event.cancel_tool に理由を⼊れる。呼ぶ側の while は付録 A4 出⼒の 1〜2 ⾏⽬ (y と答えて再開した) interrupt desk-approval {'order_id': 'ORD-5521', 'yen': 9800} end_turn © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 14 -
2 Interrupt で⽌めて再開する 道具の中から割り込む interrupt_tool.py の 6〜15 ⾏⽬ (import は
A7) @tool(context=True) def process_refund(tool_context: ToolContext, order_id: str, yen: int): """注⽂の返⾦をする。""" answer = tool_context.interrupt( "refund-approval", reason={"order": order_id}) if answer != "y": return "担当者が断った" return f"{order_id} の {yen:,} 円を返⾦した" @tool(context=True) の道具で tool_context.interrupt( name, reason=...) で⽌める。 name は、その道具の中で 重ならなければよい。 再開の形は 13 枚⽬と同じ。 この回は n と答えた 出⼒の 1 ⾏⽬と 5 ⾏⽬ (5 ⾏⽬は agent.tool.process_refund() を直接呼んだ) interrupt refund-approval {'order': 'ORD-5521'} RuntimeError: cannot raise interrupt in direct tool call © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 15 -
2 Interrupt で⽌めて再開する クライアントとサーバーに分ける server() は呼ばれるたびに Agent を作る。⽌まった所は FileSessionManager に
残り、client() が答えを渡すと続きから返⾦が動いた (コードは付録 A5、A6) © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 16 -
04 Interventions と Plugins 第 3 部 Plugins と Skills
で Agent を広げる © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. plugins ContextInjector AgentSkills SKILL.md 17 -
3 Plugins と Skills で Agent を広げる plugins にプラグインを渡す plugin_attach.py
の 7〜13 ⾏⽬ (import は A7) clock = ContextInjector( lambda context: f"<now>{datetime.now():%H:%M}</now>") agent = Agent( model=model, plugins=[clock], callback_handler=None, system_prompt=PROMPT + "\n今の時刻は <now> にある。") print(agent("今、何時ですか")) print(agent.messages[0]["content"]) 出⼒ 今の時刻は22時37分です。 他にご⽤件はありますか。 [{'text': '今、何時ですか'}] © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. Agent はプラグインの処理をループの⼀部として動かす。 ContextInjector は、利⽤者の新しい問いのたびに その回の⼊⼒へ時刻を⾜す (trigger の既定 userTurn)。 会話の履歴 (最後の⾏) には残らない 18 -
3 Plugins と Skills で Agent を広げる Plugin クラスの形 plugin_class.py
の 8〜21 ⾏⽬ (import は A7) 24〜28 ⾏⽬ class DeskLog(Plugin): name = "desk-log" agent = Agent(model=model, system_prompt=PROMPT, tools=[track_order], plugins=[DeskLog()], callback_handler=None) def init_agent(self, agent): print("init_agent:", agent.tool_names) @hook def log(self, event: BeforeToolCallEvent): print("[LOG]", event.tool_use["name"]) 出⼒の 3〜4 ⾏⽬ @tool def hours(self) -> str: """お店の受付の時間を返す。""" return "9:00〜18:00" @hook は引数の型のイベントで © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. [LOG] track_order [LOG] hours 呼ばれ、@tool は道具になった 19 -
3 Plugins と Skills で Agent を広げる 付けたときに触る部品と、その順 plugin_class.py の出⼒の
1〜2 ⾏⽬ init_agent: ['track_order'] Agent: ['track_order', 'hours'] © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. init_agent の時点では、プラグインの道具はまだ 無い。道具は最後に⼊る 20 -
3 Plugins と Skills で Agent を広げる 指⽰を 1 つのプロンプトに詰めると
全部の指⽰を 1 つのプロンプトに system prompt 詰めると、トークンを⾷い、 指⽰が混ざり、保守しにくい。 Strands Agents の Skills (AgentSkills) は、名前と説明 だけを system prompt に⼊れ、 本⽂は要るときに読む。 この資料の 2 つのスキルは、 名前、説明、場所 (location) だけが⼊った © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 21 -
3 Plugins と Skills で Agent を広げる スキルが読まれる 3 段階
1 Discovery 2 Activation 3 Execution 名前と説明を XML で skills ツールで本⽂と 本⽂の⼿順に従う。 system prompt に⼊れる 資源の⼀覧を受け取る 資源は渡した道具で読む 出⼒の 2、4、6 ⾏⽬ skills_flow.py の出⼒の 9、12、13 ⾏⽬ (下 2 ⾏は XML) Tool #1: skills Tool #2: track_order Tool #3: skills activated: ['refund-policy'] <name>refund-policy</name> <description>返⾦の決まり。返⾦の問い合わせで使う</description> © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 22 -
3 Plugins と Skills で Agent を広げる スキルの渡し⽅ skills_sources.py の
4〜15 ⾏⽬ (import は A7) 出⼒ one = AgentSkills(skills="./skills/refund-policy") parent = AgentSkills(skills="./skills/") mixed = AgentSkills(skills=[ "./skills/refund-policy", Skill(name="greeting", description="あいさつの決まり", instructions="名前で呼んであいさつする"), ]) for p in [one, parent, mixed]: agent = Agent(model=model, plugins=[p]) names = p.get_available_skills(agent) print([s.name for s in names]) ['refund-policy'] ['gift-wrap', 'refund-policy'] ['greeting', 'refund-policy'] © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1 つのフォルダ、⼦をまとめて 読む親のフォルダ、Skill を 渡した。HTTPS の URL も 渡せる。パスのスキルは Agent に付けたときに読まれる 23 -
3 Plugins と Skills で Agent を広げる ファイルを読む道具は⾃分で渡す skills_read.py の
7〜12 ⾏⽬ (import は A7) root = Path("skills").resolve() # read は絶対パスを求める agent = Agent( model=model, system_prompt=PROMPT, tools=[track_order, read], plugins=[AgentSkills(skills=str(root))]) agent("開けたイヤホンの ORD-5521 は返⾦できますか") 出⼒の 2、4、6、7 ⾏⽬ Tool #1: skills Tool #2: read Tool #3: track_order 開けたイヤホンは壊れている時だけ返⾦できます。 © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. AgentSkills は読む道具も動かす道具も 持たない。例の file_editor は⾮推奨で、 read、edit、write に替わる。read は 絶対パスを求める 24 -
3 Plugins と Skills で Agent を広げる SKILL.md の frontmatter
skills/refund-policy/SKILL.md --name: refund-policy description: 返⾦の決まり。返⾦の問い合わせで使う allowed-tools: read --# 返⾦の決まり 1. 返⾦の前に、届いた⽇を確かめる 2. 届いてから 30 ⽇を過ぎた注⽂は、返⾦しない 3. 細かい条件は references/conditions.md を読む © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 項⽬ 必須 中⾝ name はい ⼩⽂字の英数字と ハイフン、1〜64 字 description はい system prompt に出る allowed-tools 空⽩で区切った 道具の名前 (今は強制しない) metadata ほか license、 compatibility 25 -
04 Interventions と Plugins before_tool_call 第 4 部 Interventions と
Steering で 判断を返す © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. Proceed() Guide(feedback=...) Deny(reason=...) 26 -
4 Interventions と Steering で判断を返す ハンドラーを書いて渡す intervene_basic.py の 8〜16 ⾏⽬
(import は A7) 出⼒ class RefundLimit(InterventionHandler): name = "refund-limit" Tool #1: process_refund 承認が必要で返⾦できません。 店⻑の確認をお願いします。 def before_tool_call(self, event): use = event.tool_use if use["name"] == "process_refund" \ and use["input"]["yen"] > 5000: return Deny(reason="店⻑の承認が要る") return Proceed() Agent(interventions= [RefundLimit()]) で渡した。 9,800 円の返⾦は⽌まった 上書きしないメソッドは Proceed() を返す © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 27 -
4 Interventions と Steering で判断を返す 返せる 5 つのアクション アクション 書き⽅
すること Proceed Proceed() そのまま続ける Deny Deny(reason=...) ⽌めて、残りのハンドラーを⾶ばす Guide Guide(feedback=...) 取り消して、⾔葉を添えてやり直させる Confirm Confirm(prompt=...) ⼈の承認を待つ Transform Transform(apply=fn) 中⾝を書き換えてから続ける © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 28 -
4 Interventions と Steering で判断を返す 登録の順に評価し、Deny で打ち切る Deny のとき a
Deny intervene_order.py の出⼒ b 評価しない Guide のとき c Guide d Guide 2 つの⾔葉が 1 つになってモデルへ 道具は動かない --- ['a', 'b'] 評価: a Deny 道具の結果: error DENIED: ⽌める --- ['c', 'd'] 評価: c Guide 評価: d Guide 道具の結果: error GUIDANCE: [c] ID を確かめて [d] 1 ⽂で答えて Guide では全員が⾛り、⾔葉は 1 つにまとまった © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 29 -
4 Interventions と Steering で判断を返す なぜ Hook で⽌めずに、型で返すか Hook で
event.cancel を Plugin A event.cancel 書くと、なぜ⽌めたのかが 枠組みに伝わらない。複数の プラグインが同じイベントを 書くと、後に書いたほうが黙って 勝つ。Interventions は Deny や Guide を返すので、Deny で Plugin B 残りを⾶ばし、Guide の⾔葉を まとめられる (29 枚⽬の出⼒) © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 30 -
4 Interventions と Steering で判断を返す 答えを集める 3 つのモード ask の値
答えの集め⽅ 向いている所 省く (既定) interrupt で⽌め、 再開で答える 状態を保存する stateless な デプロイ "stdio" 端末で y / n を打つ CLI のアプリ 関数を渡す 関数が問いの⽂を受け取り、 答えを返す Web の画⾯、Slack の bot HumanInTheLoop の ask で選ぶ。既定の形は、第 2 部の interrupt と同じ流れ。 stateless なら session manager と組む © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 31 -
4 Interventions と Steering で判断を返す ⻑いプロンプトに⼿順を全部書くと 30 を超える⼿順 30 を超える⼿順を
1 つの プロンプトに詰めると、 指⽰を無視したり、⼿順を 守らなかったりする。 Strands Agents の Steering は、要る 場⾯でだけ handler から⾔葉を 返す。Python の handler は Plugin で、plugins=[handler] で付ける © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 32 -
4 Interventions と Steering で判断を返す 規則を⾃然⽂で書く steering_tone.py の 12〜17 ⾏⽬
(import は A7) handler = LLMSteeringHandler(system_prompt=""" お客さんへのメールが丁寧で穏やかかを確かめる。 責める⾔い⽅や強い⾔い⽅なら、⾔い直させる。""") agent = Agent(model=model, system_prompt=PROMPT, tools=[send_email], plugins=[handler], callback_handler=None) LLMSteeringHandler( system_prompt=...) を plugins に渡す。 頼みは「強めの⾔い⽅で メールして」(18〜19 ⾏⽬) 出⼒の 1〜2 ⾏⽬と 7〜8 ⾏⽬ (メールの 1 ⾏⽬の先頭 20 字と、道具の結果) send_email 1 回⽬: 返品期限は既に過ぎています -> error Tool call cancelled send_email 4 回⽬: いつもご利⽤いただき誠にありがとうござい -> success [email protected] 1〜3 回⽬は取り消され、4 回⽬で送られた。同じコードを 5 回動かし、送らずに終わった回が 2 回あった © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 33 -
4 Interventions と Steering で判断を返す handler に材料を渡す provider provider が
Hook のイベントを⾒て steering context に書き、handler がそれを 読んで判断する。LLMSteeringHandler の既定の provider は LedgerProvider © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 34 -
まとめ まとめ 1 危ない呼び出しだけ聞くなら、HumanInTheLoop(classifier=True)。 必ず聞く道具は ! で否定し、誰も通せない線は Cedar を前に置く 2
Hook や道具の interrupt で⽌め、interruptResponse で再開する。 クライアントとサーバーに分けるなら session manager と組む 3 Plugin は Hook と道具を 1 つにまとめる。 Skills は名前と説明だけを先に⼊れ、本⽂は要るときに読む 4 Interventions は Deny や Guide を型で返す。 Steering は要る場⾯でだけ⾔葉を返す © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 35 -
まとめ 次に読む資料 05 Sessions と Memory Agent の状態、会話の保存と再開、Memory、Context management ©
2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 36 -
付録 A1 どの⾯にも出る model と PROMPT d04/base.py # 04 の共通:
モデル (東京の Bedrock) と指⽰の⽂ from agent import model # noqa: F401 PROMPT = """あなたはネットの家電のお店の問い合わせ窓⼝の係です。 記号の飾りを使わずに答える。答えは 2 ⽂まで。 1 ⽂は 20 字までにし、⽂ごとに改⾏する。 今⽇は 2026-11-10 です。""" agent.py の 19〜22 ⾏⽬ (01 で作った model) お店の道具は 2 つ。 track_order は 配送を⾒る (d04/shop.py)。 process_refund は 返⾦する (01 の tools.py) model = BedrockModel( model_id="global.anthropic.claude-sonnet-5", region_name="ap-northeast-1", # 東京 ) © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 37 -
付録 A2 Cedar の決まりと CedarAuthorization d04/cedar_first.py の 8〜21 ⾏⽬ (import
は A7) track_order は誰でも、 POLICIES = """ permit(principal, action == Action::"track_order", resource); permit(principal == User::"alice", action == Action::"process_refund", resource); """ process_refund は alice だけに許す。 principal_resolver が invocation_state の user_id から User を作る def who(state): return {"type": "User", "id": state["user_id"]} cedar = CedarAuthorization(policies=POLICIES, principal_resolver=who) © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 38 -
付録 A3 Cedar を前に置いて呼ぶ d04/cedar_first.py の 22〜30 ⾏⽬ 出⼒の 1、6、8、12
⾏⽬ for user in ["alice", "bob"]: print(f"--- {user}") agent = Agent( model=model, system_prompt=PROMPT, tools=[track_order, process_refund], interventions=[cedar, HumanInTheLoop( classifier=True, ask="stdio")]) agent("ORD-5521 を 9,800 円返⾦して", invocation_state={"user_id": user}) --- alice 返⾦処理が完了しました。 --- bob 返⾦処理ができませんでした。 alice は 4〜5 ⾏⽬で聞かれ、 y と答えた。bob は聞かれずに 拒否された。cedarpy (strands-agents[cedar]) を ⾜して動かした © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 39 -
付録 A4 interrupt で⽌めて再開する呼ぶ側 d04/interrupt_hook.py の 18〜20 ⾏⽬ def yes(i):
return {"interruptResponse": { "interruptId": i.id, "response": "y"}} 26〜33 ⾏⽬ result.interrupts ごとに interruptResponse を 作って agent(...) に 渡す。出⼒は 14 枚⽬ agent.add_hook(approve) result = agent("ORD-5521 を 9,800 円返⾦して") while result.stop_reason == "interrupt": for i in result.interrupts: print(result.stop_reason, i.name, i.reason) result = agent([yes(i) for i in result.interrupts]) print(result.stop_reason) print(result) © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 40 -
付録 A5 クライアントとサーバー: server() d04/session_split.py の 8〜16 ⾏⽬ (import は
A7) def server(prompt): # 呼ばれるたびに Agent を作る agent = Agent( model=model, system_prompt=PROMPT, tools=[track_order, process_refund], session_manager=FileSessionManager( session_id="desk-1", storage_dir="/tmp/desk"), callback_handler=None) agent.add_hook(approve) return agent(prompt) 呼ばれるたびに Agent を作る。同じ session_id の FileSessionManager から、 ⽌まった所を読んで続ける。approve は 14 枚⽬の Hook と同じ (d04/approval.py) © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 41 -
付録 A6 クライアントとサーバー: client() d04/session_split.py の 19〜28 ⾏⽬ def client(text):
result = server(text) while result.stop_reason == "interrupt": responses = [] for it in result.interrupts: print("聞く:", it.reason) responses.append({"interruptResponse": { "interruptId": it.id, "response": "y"}}) result = server(responses) print(result) 出⼒の 1〜2 ⾏⽬ 聞く: {'order_id': 'ORD-5488', 'yen': 4500} 返⾦処理が完了しました。 © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. client() は答えを server(responses) に渡す (31 ⾏⽬で呼んだ) 42 -
付録 A7 この資料のコードの import import 元 名前 strands Agent、AgentSkills、Skill、tool strands.hooks
BeforeToolCallEvent strands.interventions Deny、Guide、InterventionHandler、Proceed strands.plugins Plugin、hook strands.session FileSessionManager strands.types.tools ToolContext strands.vended_interventions.cedar CedarAuthorization strands.vended_interventions.hitl HumanInTheLoop strands.vended_plugins.context_injector ContextInjector strands.vended_plugins.steering LLMSteeringHandler strands.vended_tools read d04/*.py の from ... import の⾏から作った。例: from strands.plugins import Plugin, hook © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 43 -
付録 A8 この資料で動かしたコード ファイル ⾯ ファイル ⾯ hitl_min.py 6〜8 枚⽬
plugin_attach.py 18 枚⽬ base.py 7、37 枚⽬ plugin_class.py 19、20 枚⽬ shop.py 7、37 枚⽬ skills_flow.py 22 枚⽬ hitl_hard.py 10 枚⽬ skills_sources.py 23 枚⽬ cedar_first.py 11、38、39 枚⽬ skills_read.py 24 枚⽬ interrupt_hook.py 13、14、40 枚⽬ SKILL.md 25 枚⽬ interrupt_tool.py 15 枚⽬ intervene_basic.py 27 枚⽬ approval.py 16、41 枚⽬ intervene_order.py 29 枚⽬ session_split.py 16、41、42 枚⽬ steering_tone.py 33 枚⽬ © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 44 -
付録 出典: Strands Agents の公式ドキュメント 2026-11-10 に読んだ版 Approve before your
agent acts: 6〜11、35 枚⽬ strandsagents.com/docs/user-guide/sdk/agents/approve-before-acting/ Interrupts: 13〜16、35、40〜42 枚⽬ strandsagents.com/docs/user-guide/sdk/interrupts/ Plugins: 4、18、35 枚⽬ strandsagents.com/docs/user-guide/sdk/plugins/ Context Injector: 18 枚⽬ strandsagents.com/docs/user-guide/sdk/plugins/context-injector/ Build a custom plugin: 19、20 枚⽬ strandsagents.com/docs/user-guide/sdk/plugins/custom-plugins/ Skills: 21〜25、35 枚⽬ strandsagents.com/docs/user-guide/sdk/plugins/skills/ © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 45 -
付録 出典: Strands Agents の公式ドキュメント (続き) File editor: 24 枚⽬
strandsagents.com/docs/user-guide/sdk/tools/vended-tools/file-editor/ Interventions: 4、27〜30、35 枚⽬ strandsagents.com/docs/user-guide/sdk/agents/interventions/ Human in the loop: 9、10、31 枚⽬ strandsagents.com/docs/user-guide/sdk/agents/interventions/human-in-the-loop/ Cedar Authorization: 11、38、39 枚⽬ strandsagents.com/docs/user-guide/sdk/agents/interventions/cedar-authorization/ Steering: 32〜35 枚⽬ strandsagents.com/docs/user-guide/sdk/agents/interventions/steering/ 問い合わせ窓⼝のエージェントのコードと出⼒ (公開していない): 6〜8、10、11、13〜16、18〜20、22〜25、 27、29、33、37〜42 枚⽬ © 2026, Amazon Web Services, Inc. or its affiliates. All rights reserved. 46