Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lambda durable functionsでHuman in the Loopを楽に…楽に……

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Avatar for Har1101 Har1101
October 21, 2026

Lambda durable functionsでHuman in the Loopを楽に…楽に……

2026/10/21 (水) JAWS-UG東京 2026秋 〜AWSライトニングトークNight〜 での登壇資料です

Avatar for Har1101

Har1101

October 21, 2026

More Decks by Har1101

Other Decks in Programming

Transcript

  1. Who am I ? 福地 開 (ふくち はるき) @har1101mony 所属:AIネイティブファクトリー株式会社

    業務:自分でもよくわからない 実績:AWS Community Builders 2年目 (AI Engineering) 2026 Japan All AWS Certifications Engineers 趣味:筋トレ、クラフトビール 近況:1級小型船舶操縦士免許取得 次はワインエキスパート取ります
  2. Lambda durable functionsとは? ◆durable = 耐久性のある • 中断可能かつ信頼性が高くて最長1年間実行できる、 マルチステップアプリケーションやAIワークフローを構築できるもの •

    サーバーレスでありながらステートフルみたいな動かし方ができるもの • step:処理の区切り。完了結果を保存し、再実行時はスキップ • wait:待機中はコンピュートが止まり課金なし • callback:外部の承認・応答を待って処理を再開
  3. Lambda durable functionsとは? ◆durable = 耐久性のある • 中断可能かつ信頼性が高くて最長1年間実行できる、 マルチステップアプリケーションやAIワークフローを構築できるもの •

    サーバーレスでありながらステートフルみたいな動かし方ができるもの • step:処理の区切り。完了結果を保存し、再実行時はスキップ • wait:待機中はコンピュートが止まり課金なし • callback:外部の承認・応答を待って処理を再開 ◆実質ヒソカのバンジーガム • Lambda durable functionsは ガム (ステートフルコンピューティングの長時間実行・ステート管理)と ゴム (Lambda Event Functionsの高速起動・環境分離)、 両方の性質を併せ持つ…♡ ※ちなみにLambda durable functionsは d と f 小文字です durable functions警察が来るのでご注意を()
  4. 書き方はめちゃ簡単 ◆エージェントとツールを定義してデコレーターをつけるだけ • これだけでエージェントが動くだけでなく、LLM推論・toolUseなどがすべて stepとして自動で区切られる →すなわちエージェントの挙動が1つずつstepとして保持される形 from typing import Any

    from aws_durable_execution_sdk_python import DurableContext, durable_execution from pydantic_ai import Agent from pydantic_ai_harness.aws_lambda import AWSLambdaDurability, durable_agent_handler agent = Agent( "bedrock:us.amazon.nova-pro-v1:0", name="support", capabilities=[AWSLambdaDurability()], ) @agent.tool_plain def get_order_status(order_id: str) -> str: """注文IDから配送状況を返す""" return f"注文 {order_id}: 配送中(明日の午前中に到着予定)" @durable_execution @durable_agent_handler async def handler(event: dict[str, Any], context: DurableContext) -> str: result = await agent.run(str(event["prompt"])) return result.output
  5. minamo ◆TS×Lambda durable functions×AIエージェントなOSS • 短く書ける • stepごとにエージェントの挙動が保存される • Human

    in the Loopを簡単に書けるようにする • できるだけ依存を少なくする(理想はHonoみたいな感じ)
  6. minamo ◆TS×Lambda durable functions×AIエージェントなOSS • 短く書ける • stepごとにエージェントの挙動が保存される • Human

    in the Loopを簡単に書けるようにする • できるだけ依存を少なくする(理想はHonoみたいな感じ) • 最近小型船舶免許を取った際に、船は車よりかなり色んなstepを踏みながら 準備・出航・操縦・帰港する必要があるのだと学んだ • Ex: 事前調査・出航前点検・ロープワーク・安全確認・海上での決まりごと・ トラシュー・着岸手順・メンテナンス… • Vibe運転ダメ絶対
  7. minamo ◆TS×Lambda durable functions×AIエージェントなOSS • 短く書ける • stepごとにエージェントの挙動が保存される • Human

    in the Loopを簡単に書けるようにする • できるだけ依存を少なくする(理想はHonoみたいな感じ) • 最近小型船舶免許を取った際に、船は車よりかなり色んなstepを踏みながら 準備・出航・操縦・帰港する必要があるのだと学んだ • Ex: 事前調査・出航前点検・ロープワーク・安全確認・海上での決まりごと・ トラシュー・着岸手順・メンテナンス… • Vibe運転ダメ絶対 • つまり船はdurable functionsだということに気が付き、そこから発想を得た ←彼は今適当なことを喋っています
  8. minamo ◆書き方はこんな感じ(toolの書き方が長い) import { agent, RetryableError, tool } from "@minamojs/minamo";

    import { bedrock } from "@minamojs/bedrock"; import { handle } from "@minamojs/lambda-df"; import { z } from "zod"; const support = agent({ name: "support", model: bedrock("us.anthropic.claude-haiku-4-5-20251001-v1:0"), instructions: "あなたはオンラインショップのカスタマーサポート担当です。", tools: { get_weather: tool({ description: "再配達の計画に使う、都市の天気予報を取得する。", input: z.object({ city: z.string() }), run: async ({ city }) => { const response = await weather.forecast(city); if (response.status === 503) throw new RetryableError("天気APIが一時的に使えません"); // 自動でリトライ return response.body; // それ以外の例外はエラー結果としてモデルに返る }, }), issue_refund: tool({ description: "人間が承認したあとに、注文を返金する。", input: z.object({ orderId: z.string(), amountYen: z.number().positive() }), approval: { when: ({ amountYen }) => amountYen >= 10_000, timeout: { hours: 1 } }, // 1万円以上は承認が必要 run: async (input, { idempotencyKey }) => payments.refund({ ...input, idempotencyKey }), }), }, }); export const handler = handle(support, { prompt: (event: { prompt: string }) => event.prompt, onHumanRequest: request => slack.notify(request.summary), // 承認依頼を通知(トークンはサーバー側に残す) });
  9. サンプルアプリ アーキテクチャ • フロント:CloudFront, S3 • バック:API Gateway, Lambda, DynamoDB

    • エージェント: Lambda durable functions, Bedrock • 画面更新:AppSync Events • 承認待ち:durable functions が保持 ※認証はCognito(図は省略) ※一部簡略化しています
  10. まとめ ◆Lambda durable functions面白い • サーバーレスだけど、サーバーレスゆえの制約をあの手この手で解消できる • エージェントと組み合わせて良い感じにHITL/HIOLを実現していきたい ◆小型船舶免許を取ろう •

    えーあいにはできないことをやろう • 船の運転面白いよ!小型ジェットだけなら多分2日とかで取れます • 真冬の船上LT会を震えて待て(予定は一切未定です)