2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【OCI】Generative AI AgentsをPython(ADK)で動かすクイックスタート(最小手順)

2
Last updated at Posted at 2026-02-09

はじめに

OracleのAI Agentサービスとして、Oracle AI Agent Platform(OCI Generative AI Agents)があります。RAGを作成したり、オーケストレーションしたりできます。
ドキュメントやマニュアルを読み、技術的に正確な情報を把握することは重要ですが、まず触ってみることもかなり重要だと思います。

ひとまず触ってみたい、試してイメージを掴みたいときに、設定で躓くとやる気が無くなってしまいますよね。
環境を構築するのに時間がかかると、私の場合、すぐに飽きてしまうこともよくあります。
今回は、とにかく簡単に、すぐに、早くOracle AI Agent Platform(OCI Generative AI Agents)を試す方法をまとめてみました。

所要時間

1時間程度

ゴール

PythonでOracle AI Agent Platform(OCI Generative AI Agents)のクイックスタート・チュートリアルを実行すること

参考URL

注意

学習でもコンピュートやLLMで課金が発生する場合があるので請求状況を確認してください。

1. コンピュート・インスタンスの作成

まず、OCIでコンピュート・インスタンスを作成します。
こちらを参考にインスタンスを作成します。

ここで注意すべき点は、イメージの選択になります。
Oracle AI Agent Platformのチュートリアルを開始するにはpython3.10以上が必要となります。
最初からpython3.12がインストールされているOracle Linux 10の選択がおすすめです!

個人のプライベートOCIアカウントで試す方は適宜Always Freeのシェイプを選択します。
image.png
image.png

2. インスタンスのセットアップ

OCIのAPI認証の設定

こちらを参考に、秘密キー・ファイル(.pem)をダウンロードし、configファイルをローカルに作成します。

下記の内容で、userとfingerprintとtenancy、regionを埋めて、key_fileは下記の内容にします。

config
[DEFAULT]
user=<ocid1.user.xxx..xxx>
fingerprint=<xx:xx:xx:xx>
tenancy=<ocid1.tenancy.xxx..xxx>
region=region=ap-osaka-1
# (大阪リージョンの場合「ap-osaka-1」、シカゴリージョンの場合「us-chicago-1」など記載)
key_file=/home/opc/.oci/oci_api_key.pem
# (↑このファイル名はダウンロードした実際のpemのファイル名にしてください。)

configファイルの適用

先ほど作成したコンピュート・インスタンスにssh接続します。
VS Codeなどを使うとやりやすいと思います。
私はAntigravityを使いました。
ターミナルで下記を入力します。

cd ~
mkdir .oci
cd .oci
touch config

ここで作ったconfigファイルの中に、先ほどの内容をコピペします。
もしくはローカルで作成したしたconfigファイルをVS CodeやAntigravityでドラッグアンドドロップでインスタンスへ転送します。
また、ダウンロードした秘密キー・ファイル(.pem)をconfigと同じ階層(/home/opc/.oci/)に配置します。

3. Oracle AI Agent Platform(OCI Generative AI Agents)の作成

リージョンの選択

対応リージョンはこちらを確認してください。
今回はOsakaリージョンに設定をします。
image.png

エージェントの作成

アナリティクスとAI > 生成AIエージェント
を選択します。
image.png

エージェントの作成をクリックし、名前を付けます。
どんな名前でも問題ありませんが、今回は「OCI_GEN_AI_AGENT」としました。
image.png

image.png

ルーティングLLMタイプを「生成AIモデル」に設定し、生成AIモデルからお好みのLLMを選択します。
(実際には要件に応じてLLMを選択しますが、今回は学習目的なのでお好みのLLMを選んでも問題ありません。)
LLMの選択が完了したら「次」をクリックします。
image.png

image.png

ツールは何も作成せず、「次」をクリックします。
image.png

エージェント・エンドポイントの設定はデフォルトのまま「次」をクリックします。
image.png

内容を確認して、「エージェントの作成」をクリックして、エージェントを作成します。

image.png

作成したエージェントを確認します。
image.png

エンドポイントをクリックします。
image.png

赤枠のOCIDからエンドポイントのIDをコピーします。
後で使うので、取っておきます。
OCIDの例:ocid1.genaiagentendpoint.oc1.ap-osaka-1.abcdefghijklmnopqrstuvwxyz

image.png

4. OCI ADKのセットアップ

OCI ADKとは?

OCIエージェント開発キット(ADK)は、OCI生成AIエージェント・サービス上でのエージェント・アプリケーションの構築を簡素化するクライアント側ライブラリです。
要約すると、ADKはOCI Generative AI Agentsを簡単に操作できるツールだと思います。
詳しくはこちらのドキュメントをご確認ください。

ADKのインストール

まず、Pythonの仮想環境を作成します。
作成したコンピュート・インスタンスのターミナルで下記を実行します。

mkdir oci-genAI-project
cd oci-genAI-project

python -m venv genAI-env
source genAI-env/bin/activate

作成した仮想環境内で下記を実行してADKをインストールします。

pip install "oci[adk]"

5. プログラムの実行

pythonコードの作成

quickstart.pyを作成し、下記をコピペします。
こちらのコードを使います。日本語にしたものを用意したので、quickstart.pyを作成して下のコードをコピペします。

quickstart.py
from typing import Dict
from oci.addons.adk import Agent, AgentClient, tool

# @tool を使用して、この Python 関数が「関数ツール」であることを示します。
# """ を付けて、関数および引数(パラメータ)の説明を記載します。
@tool
def get_weather(location: str) -> Dict[str, str]:
    """
    指定された場所の天気を取得します。

    Args:
      location(str): 天気を問い合わせる対象の場所
    """
    return {"location": location, "temperature": -3, "unit": ""}


def main():
    # 認証情報とリージョンの設定を指定して、エージェントクライアントを作成します。
    # auth_type は、使用したい認証方式に合わせて置き換えてください。
    # .oci/configに認証情報がある場合には、auth_type="api_key"で自動的に認証情報が読み込まれます。
    # regionはGenerative AI Agentsを作成したリージョンを指定します。
    client = AgentClient(
        auth_type="api_key",
        profile="DEFAULT",
        region="ap-osaka-1",
    )

    # クライアント、指示(instructions)、ツールを指定してローカルのエージェントオブジェクトを作成します。
    # 併せてエージェントのエンドポイントIDも必要です。
    agent = Agent(
        client=client,
        agent_endpoint_id="#3. でメモしたエンドポイントのOCIDをコピペします。例:ocid1.genaiagentendpoint.oc1.ap-osaka-1.abcdefghijklmnopqrstuvwxyz",
        instructions="あなたはツールを使って天気の問い合わせを行います。",
        tools=[get_weather]
    )

    # ローカルの指示(instructions)とツールをリモートのエージェントリソースに同期します。
    # setup() を呼び出す必要があるのは、指示やツールを変更したときだけです。
    agent.setup()

    # エージェントを実行します。このメソッドは Web アプリや Slack ボットなどに組み込むこともできます。
    # ユーザーのリクエストを処理したいときに run() を呼び出します。
    input = "東京は寒いですか?"
    response = agent.run(input)

    # Print the response
    response.pretty_print()

if __name__ == "__main__":
    main()

下記で実行してみます。

python quickstart.py
実行結果の全文はこちら
(myenv) [opc@instance-20260205-1828 oci_agent]$ python quickstart.py 
[02/05/26 09:50:33]  INFO     Checking integrity of agent details...                                                                             
                     INFO     Checking synchronization of local and remote agent settings...                                                     
                     INFO     Checking synchronization of local and remote function tools...                                                     
╭─ Local and remote function tools found ─╮
│ Local function tools (1):               │
│ ['get_weather']                         │
│                                         │
│ Remote function tools (1):              │
│ ['get_weather']                         │
╰─────────────────────────────────────────╯
[02/05/26 09:50:34]  INFO     Checking synchronization of local and remote RAG tools...                                                          
                     INFO     Checking synchronization of local and remote SQL tools...                                                          
╭─ Local and remote SQL tools found ─╮
│ Local SQL tools (0):               │
│ []                                 │
│                                    │
│ Remote SQL tools (0):              │
│ []                                 │
╰────────────────────────────────────╯
╭──────────────────────────────── Chat request to remote agent: None ─────────────────────────────────╮
│ (Local --> Remote)                                                                                  │
│                                                                                                     │
│ user message:                                                                                       │
│ 東京は寒いですか?                                                                                  │
│                                                                                                     │
│ performed actions by client:                                                                        │
│ []                                                                                                  │
│                                                                                                     │
│ session id:                                                                                         │
│ ocid1.genaiagentsession.oc1.ap-osaka-1.amaaaaaa7mjirbaad3qgs3scokegnasfwzfzq6t7pyshq3nqvj7a5oabcija │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭────────────────── Chat response from remote agent ──────────────────╮
│ (Local <-- Remote)                                                  │
│                                                                     │
│ agent message:                                                      │
│ null                                                                │
│                                                                     │
│ required actions for client to take:                                │
│ [                                                                   │
│     {                                                               │
│         "action_id": "7fece03f-b4c4-4079-94d7-54ab7219cced",        │
│         "required_action_type": "FUNCTION_CALLING_REQUIRED_ACTION", │
│         "function_call": {                                          │
│             "name": "get_weather",                                  │
│             "arguments": "{\"location\": \"\u6771\u4eac\"}"         │
│         }                                                           │
│     }                                                               │
│ ]                                                                   │
│                                                                     │
│ guardrail result:                                                   │
│ None                                                                │
│                                                                     │
│                                                                     │
╰─────────────────────────────────────────────────────────────────────╯
╭─ Function call requested by agent and mapped local handler function ─╮
│ Agent function tool name:                                            │
│ get_weather                                                          │
│                                                                      │
│ Agent function tool call arguments:                                  │
│ {'location': '東京'}                                                 │
│                                                                      │
│ Mapped local handler function name:                                  │
│ get_weather                                                          │
╰──────────────────────────────────────────────────────────────────────╯
╭─────── Obtained local function execution result ────────╮
│ {'location': '東京', 'temperature': -3, 'unit': '度)'} │
╰─────────────────────────────────────────────────────────╯
╭───────────────────────────────────────────────────── Chat request to remote agent: None ──────────────────────────────────────────────────────╮
│ (Local --> Remote)                                                                                                                            │
│                                                                                                                                               │
│ user message:                                                                                                                                 │
│ null                                                                                                                                          │
│                                                                                                                                               │
│ performed actions by client:                                                                                                                  │
│ [{'action_id': '7fece03f-b4c4-4079-94d7-54ab7219cced', 'performed_action_type': 'FUNCTION_CALLING_PERFORMED_ACTION', 'function_call_output':  │
│ '{"location": "\\u6771\\u4eac", "temperature": -3, "unit": "\\u5ea6\\uff09"}'}]                                                               │
│                                                                                                                                               │
│ session id:                                                                                                                                   │
│ ocid1.genaiagentsession.oc1.ap-osaka-1.amaaaaaa7mjirbaad3qgs3scokegnasfwzfzq6t7pyshq3nqvj7a5oabcija                                           │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭───────────────────────── Chat response from remote agent ─────────────────────────╮
│ (Local <-- Remote)                                                                │
│                                                                                   │
│ agent message:                                                                    │
│ {                                                                                 │
│     "role": "AGENT",                                                              │
│     "content": {                                                                  │
│         "text": "\u6771\u4eac\u306e\u6c17\u6e29\u306f-3\u5ea6\u3067\u3059\u3002", │
│         "citations": null,                                                        │
│         "paragraph_citations": null                                               │
│     },                                                                            │
│     "time_created": "2026-02-05T09:50:37.353000+00:00"                            │
│ }                                                                                 │
│                                                                                   │
│ required actions for client to take:                                              │
│ null                                                                              │
│                                                                                   │
│ guardrail result:                                                                 │
│ None                                                                              │
│                                                                                   │
│                                                                                   │
╰───────────────────────────────────────────────────────────────────────────────────╯
╭── Agent run response ──╮
│ agent text message:    │
│ 東京の気温は-3度です。   │
╰────────────────────────╯
結果
╭── Agent run response ──╮
│ agent text message:    │
│ 東京の気温は-3度です。   │
╰────────────────────────╯

image.png

結果が出ました。

まとめ

Oracle AI Agent Platform(OCI Generative AI Agents)のチュートリアルにあるクイックスタートをなるべく簡単に、すぐに試す方法をまとめました。
これで、とりあえず動かしたい場合やイメージを掴みたい場合に、気軽に短時間でOracle AI Agent Platform(OCI Generative AI Agents)を試すことができます。

これだけだと感動は少ないかもしれませんが、次回、複数のツールを使ったオーケストレーションについて書いてみたいと思います。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?