0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

IBM watsonx OrchestrateにCrewAIで作った外部エージェントを連携する方法

Last updated at Posted at 2025-07-17

はじめに

CrewAIを使ったエージェントをIBM watsonx Orchestrateに連携させる手順を紹介します。2025年6月時点の新しいAgentic な watsonx Orchestrateを前提としています。

前提条件

CrewAI を用いたエージェント

まず、利用するCrewAI を用いたエージェントについて簡単に解説します

main.py

構成要素:

  • FastAPI: 高性能なPython Web APIフレームワーク
  • エンドポイント: /v1/agents(エージェントの発見)、/v1/chat(チャット)
  • CrewAI: AI Agentフレームワーク
  • エージェント: 3つの専門エージェント(Researcher/Analyst/Writer)による協調処理

処理フロー:

  1. ユーザークエリ受信
  2. 3つのTaskを順次実行(research→analysis→writing)
  3. 各エージェントの実行状況をストリーミング

auth.py

IBM Cloud IAM認証を用いてAPI keyからアクセストークンを取得するヘルパークラス

CrewAI エージェント環境準備

リポジトリをクローンして環境変数を設定します:

git clone https://github.com/optimisuke/hello-ibm-agent-connect
cd hello-ibm-agent-connect
cp .env.sample .env
# .envファイルにAPIキー等を設定

CrewAI ローカル動作確認

Python環境での実行

pip install --no-cache-dir -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port 8080

動作確認

http://localhost:8080/docs にアクセスしてOpenAPI画面から動作確認できます。

リクエストボディの例:

{
  "model": "crewai-team",
  "messages": [{ "role": "user", "content": "Explain LLMs" }]
}

2025-06-03-23-31-35.png

※ gitにあるコードだとmodelパラメータは特に使用されないため、任意の値で構いません。

Docker環境での実行

docker build -t external_agent .
docker run --rm -p 8080:8080 \
  -e WATSONX_PROJECT_ID=xxx \
  -e WATSONX_API_KEY=xxx \
  -e MODEL=watsonx/mistralai/mistral-medium-2505 \
  -e WATSONX_URL=https://us-south.ml.cloud.ibm.com \
  external_agent

CrewAI デプロイ手順

1. コンテナのビルドとプッシュ

Container Registry × Code Engineを想定した手順:

# Apple Silicon環境からIntel環境へのデプロイを想定
docker build -t external_agent . --platform linux/amd64
docker tag external_agent us.icr.io/cc-xxx-cr/external_agent:latest
docker login -u iamapikey -p xxx us.icr.io
docker push us.icr.io/cc-xxx-cr/external_agent:latest

2. Code Engineでのデプロイ

  1. Container Registryのイメージを取得できるようにシークレットを設定
  2. アプリケーションを作成
  3. 環境変数等を設定

デプロイ後、発行されたURLに/docsをつけてOpenAPI画面で動作確認できます。

IBM watsonx Orchestrateとの連携設定

watsonx Orchestrateでの設定手順:

  1. URLに/v1/chatを追加して設定
  2. 必要な認証情報を設定
  3. エージェントの設定を完了

以下は設定画面のキャプチャです:

2025-06-03-23-25-53.png
2025-06-03-23-27-29.png
2025-06-03-23-26-22.png

2025-06-03-23-25-44.png
2025-06-03-23-23-17.png

実装のポイント

ファイル構成

モデル選択

  • MODEL=watsonx/meta-llama/llama-3-2-1b-instruct: 小さいモデル(高速)
  • MODEL=watsonx/mistralai/mistral-medium-2505: より精度の高いモデル(時間がかかる)

CrewAIは複数回LLMを呼び出すため、大きいモデルを使用するとwatsonx Orchestrateからの呼び出し時にタイムアウトする可能性があります。用途に応じて適切なモデルを選択してください。

参考リンク

注意事項

以下の情報は古いwatsonx Orchestrate用のため、現在は使用できません:

最新の情報はIBM Agent Connectを参照してください。

まとめ

新しいwatsonx OrchestrateでCrewAIを使った外部エージェントの構築を紹介しました。他のフレームワークで作ったエージェントも連携できるので、そのうち試してみたいと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?