Skip to content

AIエージェントのPoC設計書を追加 - #6476

Merged
TinyKitten merged 23 commits into
devfrom
docs/ai-agent-design
Jul 29, 2026
Merged

TinyKitten merged 23 commits into
devfrom
docs/ai-agent-design

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

概要

Issue #6474 の成果物として、親 Issue #6473 の要件定義に基づく AI エージェントの PoC 設計書を追加します。曖昧な目的地の要望から実在する駅を最大 5 件提案し、既存の行き先決定フローに接続する機能の全体設計です。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • docs/spec/ai-agent/architecture.md を新規追加
    • 全体アーキテクチャ(LLM 呼び出しを BFF trainlcd-worker の新設 POST /agent/chat に集約し、Cloudflare AI Gateway 経由で GPT / Claude を呼ぶ)と 1 ターンの処理シーケンスを Mermaid 図で記載(AIエージェントの開発 #6473 実装備考の Mermaid 活用に対応)
    • 駅の実在性保証: tool use による stationsByName 実在確認 + サーバ側でツール結果と突合して幻覚提案を破棄する二段構え(MUST 要件対応)
    • トピック外プロンプトの謝絶: 本体 LLM 手前に Workers AI の軽量トピックゲートを配置しトークン浪費を防止(MUST 要件対応)
    • モデル選定: AIエージェントの開発 #6473 非機能要件に従い GPT / Claude を評価セットで吟味する手順と Claude 候補(claude-opus-5 / claude-haiku-4-5)のコスト試算を記載
    • 技術選定: エージェントフレームワークの検討(Vercel AI SDK 推奨・採用条件とフォールバック方針つき)に加え、BFF / アプリ両側の採用・不採用ライブラリ候補一覧を記載(新規依存は BFF の ai・@ai-sdk/*・zod・langsmith のみ、アプリ側はゼロ)
    • LangSmith によるエージェント妥当性検証(トレーシング・評価 Dataset / Experiment・回帰検証、dev 環境限定のトレース送信)を記載
    • クライアント設計(新規 DestinationAgentScreen、既存 RouteSearchScreen 選択ロジックの共有フック化、remoteConfig キルスイッチ)、レート制限、テスト戦略、段階的リリース計画、未決事項を整理
  • docs/README.md のドキュメント一覧に設計書へのリンクを追記

テスト

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

省略: コード本体(src/ 等)に変更がないため。ドキュメントに対しては markdownlint-cli2(0 件)と Mermaid 図のレンダリング検証(mermaid-cli)を実施済み。

関連Issue

Closes #6474
Refs #6473

スクリーンショット(任意)

Summary by CodeRabbit

  • ドキュメント
    • ドキュメント一覧に「AIエージェント設計書」へのリンクを追加しました。
    • 自然言語による目的地提案機能の設計、画面遷移、エラー処理、セキュリティ、段階的リリース計画などをまとめた設計書を新規追加しました。

@TinyKitten TinyKitten self-assigned this Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

自然言語の曖昧な目的地入力から実在駅を最大5件提案し、既存フローへ接続するAIエージェントPoCの設計書を追加した。API、検証、アプリ連携、運用、テスト、リリース方針を定義し、READMEからリンクした。

Changes

行き先相談AIエージェント

Layer / File(s) Summary
要件とAPIアーキテクチャ
docs/spec/ai-agent/design.md, docs/README.md
AIエージェントの要件、システム構成、POST /agent/chat の入出力、ステートレスな会話方式を定義し、READMEに設計書へのリンクを追加した。
処理と提案検証
docs/spec/ai-agent/design.md
認証、入力検証、トピックゲート、LLMのtool use、駅候補の突合、応答制御、プロンプトキャッシュ、レート制限、再試行、コストおよびプライバシー方針を定義した。
アプリ連携とリリース計画
docs/spec/ai-agent/design.md
チャットUI、既存の行き先決定フローとの接続、多言語・エラー処理、将来拡張、テスト、段階リリースおよび未決事項を整理した。

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • 6473: 自然言語による目的地入力、StationAPI検証、最大5件の駅提案、off-topic拒絶の要件を設計書で具体化している。
  • 6477: 設計書内で、AIエージェント画面、導線、提案カードから既存フローへの接続方針を定義している。

Poem

ぴょんと設計書、駅を探す
ふわっと目的地、5つに絞る
本物の駅だけ、そっと確認
アプリの道へ、耳を立て
うさぎも安心、月明かり crescent

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #6474 の成果物である設計書Markdownと関連するMermaid資料の追加が確認でき、要件に合致しています。
Out of Scope Changes check ✅ Passed 変更は設計書追加とREADMEリンク更新に限られ、Issue #6474 の範囲外の内容は見当たりません。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed PRの主変更であるAIエージェントPoC設計書の追加を簡潔に表しています。
Description check ✅ Passed 概要、変更内容、テスト、関連Issueが揃っており、テンプレート要件をほぼ満たしています。
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/ai-agent-design

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/spec/ai-agent/destination-agent.md`:
- Around line 214-218:
本文・シーケンス図・テスト条件・コスト試算で、ツール呼び出し上限の定義を統一してください。1イテレーション1回なら最大3回として記載を修正し、最大5回を維持する場合は並列呼び出しを明示して図と各関連説明を更新してください。
- Around line 417-420: Define and document timeout, cancellation, and retry
behavior for the BFF’s outbound LLM API and sapi-bff calls in the
destination-agent specification, rather than covering only the client-side
30-second timeout. Specify server-side deadlines and cancellation propagation,
and state how retries must avoid duplicating timed-out requests and costs.
- Around line 470-482: 「セキュリティ・プライバシー」節に、採用する LLM
プロバイダーごとの会話データ保持期間・処理リージョン・削除方法を追記し、契約条件とユーザー同意・プライバシー審査を実装開始前の必須条件として明記してください。既存の自社バックエンドでの非永続化方針と併記し、プロバイダー側の保持設定を確認・適用する責任も定義してください。
- Around line 297-300: 駅グループ ID
のフィールド名を、ツール結果とレスポンススキーマで統一してください。`stationsByName` の軽量 JSON では正式名称として
`stationGroupId` など一つの名称を採用し、`StationFields` の `groupId`
から変換する明示的なマッピングを仕様に追加してください。駅検索結果とレスポンススキーマの両方で同じ名称を使用し、再取得キーとの不一致を防いでください。
- Around line 270-295:
ツール定義節を、共通の論理スキーマとプロバイダ別アダプターに分離して記述してください。`search_stations_by_name`
の共通入力契約を定義したうえで、Anthropic の `input_schema` と OpenAI の `parameters`
など各形式への変換方針を明記し、GPT 候補にも同じスキーマを適用できる実装手順を追加してください。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a10bcc7f-0c39-401f-b8be-6f738f54b8bf

📥 Commits

Reviewing files that changed from the base of the PR and between 2f89efa and f28214e.

📒 Files selected for processing (2)
  • docs/README.md
  • docs/spec/ai-agent/destination-agent.md

Comment thread docs/spec/ai-agent/destination-agent.md Resolved
Comment thread docs/spec/ai-agent/architecture.md Resolved
Comment thread docs/spec/ai-agent/destination-agent.md Resolved
Comment thread docs/spec/ai-agent/architecture.md Resolved
Comment thread docs/spec/ai-agent/design.md Resolved
@TinyKitten

Copy link
Copy Markdown
Member Author

Fixes Applied Successfully

Fixed 1 file based on 5 CodeRabbit feedback item(s).

Files modified:

  • docs/spec/ai-agent/destination-agent.md

Commit: efbf9f2f5

対応内容:

  • ツール呼び出し上限を「並列呼び出し可・最大3イテレーション・合計最大5回」に統一(シーケンス図・コスト試算にも反映)
  • ツール定義をプロバイダ非依存の論理契約 + プロバイダ別アダプター(Anthropic input_schema / OpenAI parameters)に分離
  • 駅グループIDのフィールド名を stationGroupId に統一し StationFields.groupId からの改名マッピングを明記
  • BFF側のタイムアウト・キャンセル・再試行方針(全体25秒 / LLM 15秒 / sapi-bff 5秒、LLMは再試行なし)を新設
  • LLMプロバイダ側のデータ保持方針(保持期間・リージョン・削除・同意要件の確認)を実装開始前の必須条件として追記

The latest autofix changes are on the docs/ai-agent-design branch.

@TinyKitten TinyKitten changed the title AIエージェント(行き先相談)のPoC設計書を追加 AIエージェントのPoC設計書を追加 Jul 29, 2026
TinyKitten and others added 7 commits July 29, 2026 10:27
@TinyKitten TinyKitten mentioned this pull request Jul 29, 2026
TinyKitten and others added 10 commits July 29, 2026 13:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/spec/ai-agent/architecture.md (1)

461-480: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

会話リクエストのAI Gatewayキャッシュを既定で有効にしないでください。

本書は会話本文を既定で永続化しない方針ですが、AI Gatewayのキャッシュはリクエストに対する応答を保存します。動的な会話では cf-aig-skip-cache: true を付けるか、Gateway側でキャッシュを無効化し、静的なFAQなど安全な対象だけを明示的にキャッシュしてください。 (developers.cloudflare.com)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/spec/ai-agent/architecture.md` around lines 461 - 480, Clarify the
Cloudflare AI Gateway guidance in the architecture document so conversation
requests do not use caching by default. Specify applying cf-aig-skip-cache: true
or disabling caching at the Gateway, and limit any enabled caching to explicitly
approved safe content such as static FAQs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/spec/ai-agent/architecture.md`:
- Around line 516-529: コスト試算の補足を、通常ケースと最大ケースに分けて更新してください。通常ケースは本体LLM
2回、最大ケースは最大3イテレーションに基づく呼び出し回数と費用で再計算し、AI
Gatewayのログ上限はアカウント全体で10万件であること、既存ログがある場合は月約6万件でも収まる保証がないことを明記してください。
- Around line 646-648: Update the AI Gateway logging policy section in
architecture.md to explicitly require cf-aig-collect-log-payload: false or an
equivalent Gateway-side setting before stating that prompt and response bodies
are disabled by default. Distinguish this prerequisite from the metadata-only
policy and add a test that verifies payload logging is disabled.

---

Outside diff comments:
In `@docs/spec/ai-agent/architecture.md`:
- Around line 461-480: Clarify the Cloudflare AI Gateway guidance in the
architecture document so conversation requests do not use caching by default.
Specify applying cf-aig-skip-cache: true or disabling caching at the Gateway,
and limit any enabled caching to explicitly approved safe content such as static
FAQs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ed756e6-9af6-4bd2-b9e3-4551fc62f1d8

📥 Commits

Reviewing files that changed from the base of the PR and between 2fedf17 and d3d611d.

📒 Files selected for processing (2)
  • docs/README.md
  • docs/spec/ai-agent/architecture.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/README.md

Comment thread docs/spec/ai-agent/architecture.md Resolved
Comment thread docs/spec/ai-agent/architecture.md Resolved
@TinyKitten

Copy link
Copy Markdown
Member Author

Fixes Applied Successfully

Fixed 1 file based on 2 CodeRabbit feedback item(s).

Files modified:

  • docs/spec/ai-agent/architecture.md

Commit: bbce3d136

対応内容:

  • コスト試算を通常ケース(LLM 2回)と最大ケース(ループ上限時の LLM 4回、約2倍のコスト)に分離。AI Gateway のログ保存枠が無料プランではアカウント全体 10 万件/月で保証されないこと、Workers Paid のゲートウェイあたり 1,000 万件を前提とすることを明記
  • AI Gateway は既定で本文ペイロードも保存されるため、cf-aig-collect-log-payload: false の付与(または Gateway 側設定での無効化)を前提条件として明記し、結合テストで無効化の適用を確認する項目を追加

The latest autofix changes are on the docs/ai-agent-design branch.

@TinyKitten
TinyKitten merged commit dd755a5 into dev Jul 29, 2026
3 checks passed
@TinyKitten
TinyKitten deleted the docs/ai-agent-design branch July 29, 2026 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AI PoC] エージェント設計

1 participant