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 に OpenAPI でツールを登録

Last updated at Posted at 2025-07-14

はじめに

IBM watsonx Orchestrate は、様々な外部APIをツールとして統合できる強力なAI Agentプラットフォームです。この記事では、News API を OpenAPI を用いて watsonx Orchestrate に登録し、ニュース取得機能を追加する方法を説明します。

準備するもの

  • IBM watsonx Orchestrate のアカウント
  • News API のアカウントとAPIキー(newsapi.orgで取得)
  • News API の OpenAPI(YAML形式)

News API について

News API は、世界中のニュースソースから記事を取得できるRESTful APIです。Bearer token による認証も利用でき、リクエストヘッダーにAPIキーを含めることで認証を行います。

認証方法:

Authorization: Bearer YOUR_API_KEY

ステップ1: OpenAPI仕様書の準備

まず、News API 用の OpenAPI YAML ファイルを準備します。以下のような構成になります:

openapi: 3.0.3
info:
  title: News API
  description: ニュース記事検索API
  version: 1.0.0
servers:
  - url: https://newsapi.org/v2

security:
  - BearerAuth: []

paths:
  /everything:
    get:
      summary: ニュース記事を検索
      parameters:
        - name: q
          in: query
          required: true
          schema:
            type: string
            example: "Agent"
        - name: language
          in: query
          schema:
            type: string
            example: "jp"
        - name: from
          in: query
          schema:
            type: string
            format: date
            example: "2025-07-07"
        - name: to
          in: query
          schema:
            type: string
            format: date
            example: "2025-07-07"
      responses:
        '200':
          description: 検索成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NewsResponse'

components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

  schemas:
    NewsResponse:
      type: object
      properties:
        status:
          type: string
          example: "ok"
        totalResults:
          type: integer
          example: 12
        articles:
          type: array
          items:
            $ref: '#/components/schemas/Article'

    Article:
      type: object
      properties:
        source:
          type: object
          properties:
            id:
              type: string
              nullable: true
            name:
              type: string
              example: "Prtimes.jp"
        author:
          type: string
          nullable: true
          example: "ホゲ ホゲータ"
        title:
          type: string
          example: "Hoge、Hogeサービス提供開始"
        description:
          type: string
          example: "HogeHogeHoge-ta"
        url:
          type: string
          format: uri
        urlToImage:
          type: string
          format: uri
          nullable: true
        publishedAt:
          type: string
          format: date-time
          example: "2025-07-07T05:40:03Z"
        content:
          type: string
          nullable: true

ステップ2: watsonx Orchestrate への登録

2.1 接続設定(Connection)

  1. watsonx Orchestrate の Manage の Connections に移動
  2. 「Add new connection」をクリックし名前をつける
  3. 認証タイプとして「Bearer Token」を選択(他の認証方式も選択できますが、今回はBearer tokenを使用)
  4. News API で取得したAPIキーを入力
  5. 「Connect」をクリックして正常に接続することを確認

image.png

image.png

image.png

2.2 ツールのインポート

  1. 「Tools」セクションから「Add tool」を選択
  2. 準備したOpenAPI YAMLファイルをアップロード
  3. APIの詳細を設定

image.png
image.png
image.png
image.png
image.png

ステップ3: Agentの構築と動作テスト

3.1 Agentの構築

  1. Agentの構築画面にアクセス
  2. 「Behavior」セクションに以下を記載:
    記事やニュースについて聞かれたら ニュース記事を検索 を使って返してください。
    結果はgithub markdown の表形式で出力してください。
    

3.2 動作確認

チャットで以下のように質問

2025-07-07 から 2025-07-08 までの英語のAgentの記事

結果はキャプチャの通り、以下のように表形式で返されます

image.png

以下のようにツール(API)のレスポンス詳細も確認できます。

image.png

まとめ

IBM watsonx Orchestrate に News API を登録することで、ニュース取得機能を簡単に統合できます。OpenAPI仕様書を準備し、Bearer token認証を設定することで、外部APIを効果的に活用できるツールが完成します。

この方法は他のREST APIにも応用できるため、様々な外部サービスとの連携が可能になります。

参考リンク

補足

API Key を選択した場合、API Keyの場所を指定できました。
image.png

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?