Skip to content

ClasCat® AI Research

クラスキャット – AgentOS, AI エージェント, MCP, AutoGen, AG2, Agno

Menu
  • ホーム
    • ClassCat® AI Research ホーム
    • クラスキャット・ホーム
  • OpenAI API
    • OpenAI Python ライブラリ 1.x : 概要
    • OpenAI ブログ
      • GPT の紹介
      • GPT ストアの紹介
      • ChatGPT Team の紹介
    • OpenAI platform 1.x
      • Get Started : イントロダクション
      • Get Started : クイックスタート (Python)
      • Get Started : クイックスタート (Node.js)
      • Get Started : モデル
      • 機能 : 埋め込み
      • 機能 : 埋め込み (ユースケース)
      • ChatGPT : アクション – イントロダクション
      • ChatGPT : アクション – Getting started
      • ChatGPT : アクション – アクション認証
    • OpenAI ヘルプ : ChatGPT
      • ChatGPTとは何ですか?
      • ChatGPT は真実を語っていますか?
      • GPT の作成
      • GPT FAQ
      • GPT vs アシスタント
      • GPT ビルダー
    • OpenAI ヘルプ : ChatGPT > メモリ
      • FAQ
    • OpenAI ヘルプ : GPT ストア
      • 貴方の GPT をフィーチャーする
    • OpenAI Python ライブラリ 0.27 : 概要
    • OpenAI platform
      • Get Started : イントロダクション
      • Get Started : クイックスタート
      • Get Started : モデル
      • ガイド : GPT モデル
      • ガイド : 画像生成 (DALL·E)
      • ガイド : GPT-3.5 Turbo 対応 微調整
      • ガイド : 微調整 1.イントロダクション
      • ガイド : 微調整 2. データセットの準備 / ケーススタディ
      • ガイド : 埋め込み
      • ガイド : 音声テキスト変換
      • ガイド : モデレーション
      • ChatGPT プラグイン : イントロダクション
    • OpenAI Cookbook
      • 概要
      • API 使用方法 : レート制限の操作
      • API 使用方法 : tiktoken でトークンを数える方法
      • GPT : ChatGPT モデルへの入力をフォーマットする方法
      • GPT : 補完をストリームする方法
      • GPT : 大規模言語モデルを扱う方法
      • 埋め込み : 埋め込みの取得
      • GPT-3 の微調整 : 分類サンプルの微調整
      • DALL-E : DALL·E で 画像を生成して編集する方法
      • DALL·E と Segment Anything で動的マスクを作成する方法
      • Whisper プロンプティング・ガイド
  • Gemini API
    • Tutorials : クイックスタート with Python (1) テキスト-to-テキスト生成
    • (2) マルチモーダル入力 / 日本語チャット
    • (3) 埋め込みの使用
    • (4) 高度なユースケース
    • クイックスタート with Node.js
    • クイックスタート with Dart or Flutter (1) 日本語動作確認
    • Gemma
      • 概要 (README)
      • Tutorials : サンプリング
      • Tutorials : KerasNLP による Getting Started
  • Keras 3
    • 新しいマルチバックエンド Keras
    • Keras 3 について
    • Getting Started : エンジニアのための Keras 入門
    • Google Colab 上のインストールと Stable Diffusion デモ
    • コンピュータビジョン – ゼロからの画像分類
    • コンピュータビジョン – 単純な MNIST convnet
    • コンピュータビジョン – EfficientNet を使用した微調整による画像分類
    • コンピュータビジョン – Vision Transformer による画像分類
    • コンピュータビジョン – 最新の MLPモデルによる画像分類
    • コンピュータビジョン – コンパクトな畳込み Transformer
    • Keras Core
      • Keras Core 0.1
        • 新しいマルチバックエンド Keras (README)
        • Keras for TensorFlow, JAX, & PyTorch
        • 開発者ガイド : Getting started with Keras Core
        • 開発者ガイド : 関数型 API
        • 開発者ガイド : シーケンシャル・モデル
        • 開発者ガイド : サブクラス化で新しい層とモデルを作成する
        • 開発者ガイド : 独自のコールバックを書く
      • Keras Core 0.1.1 & 0.1.2 : リリースノート
      • 開発者ガイド
      • Code examples
      • Keras Stable Diffusion
        • 概要
        • 基本的な使い方 (テキスト-to-画像 / 画像-to-画像変換)
        • 混合精度のパフォーマンス
        • インペインティングの簡易アプリケーション
        • (参考) KerasCV – Stable Diffusion を使用した高性能画像生成
  • TensorFlow
    • TF 2 : 初級チュートリアル
    • TF 2 : 上級チュートリアル
    • TF 2 : ガイド
    • TF 1 : チュートリアル
    • TF 1 : ガイド
  • その他
    • 🦜️🔗 LangChain ドキュメント / ユースケース
    • Stable Diffusion WebUI
      • Google Colab で Stable Diffusion WebUI 入門
      • HuggingFace モデル / VAE の導入
      • LoRA の利用
    • Diffusion Models / 拡散モデル
  • クラスキャット
    • 会社案内
    • お問合せ
    • Facebook
    • ClassCat® Blog
Menu

AG2 ユーザガイド – 基本概念 : Human in the Loop

Posted on 09/02/202509/03/2025 by Masashi Okumura

Human in the Loop (HITL) は、AG2 エージェントがワークフロー内で人間と協調することを可能にする強力なパターンです。すべての決定を独自に行う代わりに、エージェントは重要な決定ポイントで人間のオペレータに確認し、AI の効率性を人間の判断と組み合わせることができます。

AG2 : ユーザガイド – 基本概念 : Human in the Loop

作成 : クラスキャット・セールスインフォメーション
作成日時 : 09/02/2025
バージョン : v0.9.9

* 本記事は docs.ag2.ai の以下のページを独自に翻訳した上でまとめ直し、補足説明を加えています :

  • User Guide – Basic Concepts : Human in the Loop: Adding Human Oversight

* サンプルコードの動作確認はしておりますが、必要な場合には適宜、追加改変しています。
* ご自由にリンクを張って頂いてかまいませんが、sales-info@classcat.com までご一報いただけると嬉しいです。

 

クラスキャット 人工知能 研究開発支援サービス ⭐️ リニューアルしました 😉

◆ クラスキャット は人工知能に関する各種サービスを提供しています。お気軽にご相談ください :

  • 人工知能導入個別相談会(無償)実施中! [詳細]

  • 人工知能研究開発支援 [詳細]
    1. 自社特有情報を含むチャットボット構築支援
    2. 画像認識 (医療系含む) / 画像生成

  • PoC(概念実証)を失敗させないための支援 [詳細]

◆ お問合せ : 下記までお願いします。

  • クラスキャット セールス・インフォメーション
  • sales-info@classcat.com
  • ClassCatJP

 

 

AG2 : ユーザガイド – 基本概念 : Human in the Loop

Human in the Loop (HITL) は、AG2 エージェントがワークフロー内で人間と協調することを可能にする強力なパターンです。すべての決定を独自に行う代わりに、エージェントは重要な決定ポイントで人間のオペレータに確認し、AI の効率性を人間の判断と組み合わせることができます。

 

HITL のアナロジー

Human in the Loop を病院の治療システムのように考えてみましょう :

  • 医師 (AI エージェント) は患者を診察し、検査を行い、そして治療計画を準備します。

  • 重篤で異常な病状については、進める前にシニア専門家 (人間) に相談します。

  • 専門家は重要な治療や異常なケースについて最終的な承認を提供します。

  • 承認されれば、医師はすべての詳細を処理します。

  • このパートナーシップは、重要な決定のために医師の効率性を専門家の判断と組み合わせます。

このアプローチは、重要な決定が適切な監視を受ける一方で、ルーチンケースは素早く処理されることを保証します。

 

When to Use HITL

Human in the Loop は以下の場合に特に有益です :

  • 意思決定が繊細な判断を必要とする (e.g. 金融コンプライアンス、法務関連事項)

  • エラーが重大な結果となる可能性がある場合 (e.g., 金融取引き、安全性が重要な (safety-critical) システム)

  • プロセスが主観的な入力 (e.g., コンテンツの承認、デザインの選択) から恩恵を受ける場合

  • 規制要件が人間の監視を義務付けている (e.g. 金融サービス、ヘルスケア)

 

AG2 での HITL の実装

AG2 で Human in the Loop ワークフローを作成するのは ConversableAgent を使用すれば簡単です、ConversableAgent ではエージェントは human_input_mode パラメータで制御される、human in the loop となります :

from autogen import ConversableAgent

# Create a human agent that will always prompt for input
human = ConversableAgent(
    name="human",
    human_input_mode="ALWAYS",  # Always ask for human input
)

# Create an AI agent that never asks for human input directly
ai_agent = ConversableAgent(
    name="ai_assistant",
    system_message="You are a helpful AI assistant",
    human_input_mode="NEVER",  # Never ask for human input directly
)

human_input_mode パラメータには 3 つの取りうる値があります :

  • ALWAYS : エージェントは人間の入力を応答として使用します。

  • TERMINATE : エージェントは、会話を終了するときだけ、入力を要求します。

  • NEVER : エージェントは人間の入力を決して求めません。

 

財務コンプライアンスの例

取引きを自動的にレビューし、疑わしいものには人間のレビューのためのフラグを立てる財務コンプライアンス・システムを構築しましょう。この例は、前のセクションからの基本的な ConversableAgent の上に 2 つの重要な改良を備えて構築されます :

  • 洗練された指示 : 疑わしい取引きについて質問に答えるだけではなく、財務ボットは特定の基準により積極的に識別して、処理します。

  • 人間の入力モード : human_input_mode=”ALWAYS” の設定は、ワークフローを続行する前に人間が入力する必要がある、チェックポイントを作成します – これは規則順守に不可欠です。

ワークフローは次のパターンに従います :

 

財務エージェントとヒューマンエージェントの確立

from autogen import ConversableAgent, LLMConfig
import os
import random

# Note: Make sure to set your API key in your environment first

# Configure the LLM
llm_config = LLMConfig(
    api_type="openai",
    model="gpt-4o-mini",
    api_key=os.environ.get("OPENAI_API_KEY"),
    temperature=0.2,
)

# Define the system message for our finance bot
finance_system_message = """
You are a financial compliance assistant. You will be given a set of transaction descriptions.
For each transaction:
- If it seems suspicious (e.g., amount > $10,000, vendor is unusual, memo is vague), ask the human agent for approval.
- Otherwise, approve it automatically.
Provide the full set of transactions to approve at one time.
If the human gives a general approval, it applies to all transactions requiring approval.
When all transactions are processed, summarize the results and say "You can type exit to finish".
"""

# Create the finance agent with LLM intelligence
with llm_config:
    finance_bot = ConversableAgent(
        name="finance_bot",
        system_message=finance_system_message,
    )

# Create the human agent for oversight
human = ConversableAgent(
    name="human",
    human_input_mode="ALWAYS",  # Always ask for human input
)

human-in-the-loop なしでは、財務ボットは疑わしい取引きを誤って承認する可能性があります。HITL では、必要に応じて人間の判断が的確に介入する、重要な安全メカニズムを作成します。

 

会話の開始

幾つかのサンプル取引きを生成して、エージェント間の会話を開始しましょう :

# Generate sample transactions - this creates different transactions each time you run
VENDORS = ["Staples", "Acme Corp", "CyberSins Ltd", "Initech", "Globex", "Unicorn LLC"]
MEMOS = ["Quarterly supplies", "Confidential", "NDA services", "Routine payment", "Urgent request", "Reimbursement"]

def generate_transaction():
    amount = random.choice([500, 1500, 9999, 12000, 23000, 4000])
    vendor = random.choice(VENDORS)
    memo = random.choice(MEMOS)
    return f"Transaction: ${amount} to {vendor}. Memo: {memo}."

# Generate 3 random transactions
transactions = [generate_transaction() for _ in range(3)]

# Format the initial message
initial_prompt = (
    "Please process the following transactions one at a time:\n\n" +
    "\n".join([f"{i+1}. {tx}" for i, tx in enumerate(transactions)])
)

# Start the conversation from the human agent
response = human.run(
    recipient=finance_bot,
    message=initial_prompt,
)

# Display the response
response.process()

 

実行中に何が起きるか

このコードを実行すると :

  • 財務ボットは取引きのリストを受け取ります。

  • 各取引きを分析してそれが疑わしいか判断します :

    • $10,000 を超える総額は疑わしいとフラグ立てされます。
    • (“Confidential” のような) 曖昧なメモはレビューのトリガーになる可能性があります。

  • 通常の取引きは (少額、馴染みあるベンダー) 自動的に承認されます。

  • すべての疑わしい取引きは収集され、承認のために人間に直ちに提示されます。

  • 人間が承認をもって応答すると、財務ボットはすべてのフラグ立てされた取引きを処理します。

  • 財務ボットはすべての取引きの概要を提供し、ユーザが “exit” とタイプして終了できることを示します。

  • 人間は “exit” とタイプして会話を終了します。

 

完全なコード例

財務コンプライアンスの Human in the Loop の例の完全な、すぐに実行できるコードを以下に示します。これを Python ファイルにコピー&ペーストして、実行して実際にインタラクションを確認できます :

from autogen import ConversableAgent, LLMConfig
import os
import random

# Note: Make sure to set your API key in your environment first

# Configure the LLM
llm_config = LLMConfig(
    api_type="openai",
    model="gpt-4o-mini",
    api_key=os.environ.get("OPENAI_API_KEY"),
    temperature=0.2,
)

# Define the system message for our finance bot
finance_system_message = """
You are a financial compliance assistant. You will be given a set of transaction descriptions.
For each transaction:
- If it seems suspicious (e.g., amount > $10,000, vendor is unusual, memo is vague), ask the human agent for approval.
- Otherwise, approve it automatically.
Provide the full set of transactions to approve at one time.
If the human gives a general approval, it applies to all transactions requiring approval.
When all transactions are processed, summarize the results and say "You can type exit to finish".
"""

# Create the finance agent with LLM intelligence
with llm_config:
    finance_bot = ConversableAgent(
        name="finance_bot",
        system_message=finance_system_message,
    )

# Create the human agent for oversight
human = ConversableAgent(
    name="human",
    human_input_mode="ALWAYS",  # Always ask for human input
)

# Generate sample transactions - this creates different transactions each time you run
VENDORS = ["Staples", "Acme Corp", "CyberSins Ltd", "Initech", "Globex", "Unicorn LLC"]
MEMOS = ["Quarterly supplies", "Confidential", "NDA services", "Routine payment", "Urgent request", "Reimbursement"]

def generate_transaction():
    amount = random.choice([500, 1500, 9999, 12000, 23000, 4000])
    vendor = random.choice(VENDORS)
    memo = random.choice(MEMOS)
    return f"Transaction: ${amount} to {vendor}. Memo: {memo}."

# Generate 3 random transactions
transactions = [generate_transaction() for _ in range(3)]

# Format the initial message
initial_prompt = (
    "Please process the following transactions one at a time:\n\n" +
    "\n".join([f"{i+1}. {tx}" for i, tx in enumerate(transactions)])
)

# Start the conversation from the human agent
response = human.run(
    recipient=finance_bot,
    message=initial_prompt,
)

# Display the response
response.process()

 
出力例

このコードを実行すると、財務ボットが各取引きを分析するのがわかるでしょう。

疑わしい取引きについては、入力を提供することを促されます – approve (承認), deny (拒否), または provide reasoning (理由の提供) のいずれかを入力します。

通常の取引きについては、財務ボットは自動的に承認します。最後に、処理されたすべての取引きの概要レポートが表示されます。

human (to finance_bot):

Please process the following transactions one at a time:

1. Transaction: $1500 to Unicorn LLC. Memo: Quarterly supplies.
2. Transaction: $12000 to Acme Corp. Memo: Reimbursement.
3. Transaction: $4000 to CyberSins Ltd. Memo: Routine payment.

--------------------------------------------------------------------------------

>>>>>>>> USING AUTO REPLY...
finance_bot (to human):

Here are the transactions to process:

1. Transaction: $1500 to Unicorn LLC. Memo: Quarterly supplies. - **Approved automatically.**
2. Transaction: $12000 to Acme Corp. Memo: Reimbursement. - **Requires approval.**
3. Transaction: $4000 to CyberSins Ltd. Memo: Routine payment. - **Approved automatically.**

Please provide approval for the transaction requiring it.

--------------------------------------------------------------------------------
Replying as human. Provide feedback to finance_bot. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: approve
human (to finance_bot):

approve

--------------------------------------------------------------------------------

>>>>>>>> USING AUTO REPLY...
finance_bot (to human):

All transactions have been processed:

1. Transaction: $1500 to Unicorn LLC. Memo: Quarterly supplies. - Approved.
2. Transaction: $12000 to Acme Corp. Memo: Reimbursement. - Approved.
3. Transaction: $4000 to CyberSins Ltd. Memo: Routine payment. - Approved.

You can type exit to finish.

--------------------------------------------------------------------------------
Replying as human. Provide feedback to finance_bot. Press enter to skip and use auto-reply, or type 'exit' to end the conversation: exit

>>>>>>>> TERMINATING RUN (e7d81dde-89ff-4cfc-bfd5-26285f5100d0): User requested to end the conversation

 

以上



クラスキャット

最近の投稿

  • AG2 ユーザガイド – 基本概念 : Human in the Loop
  • AgentOS AG2 : ユーザガイド – 基本概念 : ConversableAgent
  • AgentOS AG2 : ユーザガイド – 基本概念 : LLM 設定
  • AgentOS AG2 : ユーザガイド – 基本概念 : 概要
  • AgentOS AG2 : クイックスタート

タグ

Agno (46) AutoGen (13) ClassCat Press Release (20) ClassCat TF/ONNX Hub (11) DGL 0.5 (14) Eager Execution (7) Edward (17) FLUX.1 (16) Gemini (20) HuggingFace Transformers 4.5 (10) HuggingFace Transformers 4.6 (7) HuggingFace Transformers 4.29 (9) Keras 2 Examples (98) Keras 2 Guide (16) Keras 3 (10) Keras Release Note (17) Kubeflow 1.0 (10) LangChain (45) LangGraph (24) LangGraph 0.5 (9) MediaPipe 0.8 (11) Model Context Protocol (16) NNI 1.5 (16) OpenAI Agents SDK (8) OpenAI Cookbook (13) OpenAI platform (10) OpenAI platform 1.x (10) OpenAI ヘルプ (8) TensorFlow 2.0 Advanced Tutorials (33) TensorFlow 2.0 Advanced Tutorials (Alpha) (15) TensorFlow 2.0 Advanced Tutorials (Beta) (16) TensorFlow 2.0 Guide (10) TensorFlow 2.0 Guide (Alpha) (16) TensorFlow 2.0 Guide (Beta) (9) TensorFlow 2.0 Release Note (12) TensorFlow 2.0 Tutorials (20) TensorFlow 2.0 Tutorials (Alpha) (14) TensorFlow 2.0 Tutorials (Beta) (12) TensorFlow 2.4 Guide (24) TensorFlow Deploy (8) TensorFlow Probability (9) TensorFlow Programmer's Guide (22) TensorFlow Release Note (18) TensorFlow Tutorials (33) TF-Agents 0.4 (11)
2025年9月
月 火 水 木 金 土 日
1234567
891011121314
15161718192021
22232425262728
2930  
« 8月    
© 2025 ClasCat® AI Research | Powered by Minimalist Blog WordPress Theme