クイックスタート¶
このガイドでは、開発環境のセットアップ、エージェントフレームワークの設定、DataRobotのチャットインターフェイスと対話するワークフローのデプロイなど、DataRobotの構築済みテンプレートを使用したエージェントワークフローの作成、デプロイ、テストについて説明します。
前提条件¶
Before proceeding, install the required components. このワークフローの実行中に問題が発生した場合は、トラブルシューティングのセクションを参照してください。
Installation process
Before starting, complete all installation and setup steps in agentic-install. Skipping this process can cause errors and prevent your agentic workflow from running correctly. Do not proceed until you have finished the installation guide.
Locate your DataRobot API key and endpoint¶
The section after this will require you to add your DataRobot API key and endpoint to your environment variables. Follow the steps below to locate them. For full details, see the DataRobot API keys documentation.
- Log in to your DataRobot account.
- Click the user icon in the top right of the UI and select API keys and tools.
- Copy your DataRobot API endpoint and DataRobot API key and paste them into a temporary file.
Continue with the next section to configure your environment variables.
環境変数の設定¶
Create an .env file in the root directory before running any commands. To do this, copy and rename the provided sample environment file (.env.template) and provide the necessary environment variables in the file.
cp .env.template .env
# Previously, .env.template was .env.sample
Edit the file with your preferred text editor. .envファイルを開き、必要な環境変数を設定します。 .envファイルには、少なくとも以下の変数が含まれている必要がありますが、完全な環境を構成するには、すべての変数を設定することをお勧めします。
nano .env # or vim .env, code .env, etc.
Insert the DataRobot API key and endpoint into your .env file. Leave other variables at their default values during setup.
DataRobot credentials in codespaces
DataRobotのCodespaceを使用している場合は、ファイルからDATAROBOT_API_TOKENおよびDATAROBOT_ENDPOINT環境変数を削除します。これらはCodespace環境にすでに存在しているためです。
# Your DataRobot API token.
# Refer to https://docs.datarobot.com/en/docs/api/api-quickstart/index.html#configure-your-environment for help.
DATAROBOT_API_TOKEN=
# The URL of your DataRobot instance API.
DATAROBOT_ENDPOINT=https://app.datarobot.com/api/v2
Pulumi Cloudにログインしていない場合は、PULUMI_CONFIG_PASSPHRASEを定義します。 パスフレーズには任意の文字列を指定できます。
# The Pulumi stack name to use for this project.
PULUMI_STACK_NAME=dev
# If empty, a blank passphrase will be used
PULUMI_CONFIG_PASSPHRASE=123
To define a DataRobot Use Case to link to the agent assets, provide a Use Case ID. If this field is empty, Pulumi creates a new Use Case.
# If empty, a new use case will be created
DATAROBOT_DEFAULT_USE_CASE=
必要に応じて、DATAROBOT_DEFAULT_EXECUTION_ENVIRONMENTを設定します。 デフォルトの設定では、最新の安定した実行環境が選択され、Pulumiを使用して最新のIDを解決することで、最新の環境が自動選択されます。
# If empty, a new execution environment will be created for each agent using the docker_context folder
DATAROBOT_DEFAULT_EXECUTION_ENVIRONMENT="[DataRobot] Python 3.11 GenAI Agents"
エージェントのワークフローを選択¶
必要な環境変数を定義したら、task startを使用してエージェントのクイックスタートを実行し、作成したいエージェントワークフローのタイプを選択します。
task start
すべてのタスクコマンドを表示する
task startを実行する前に、プロジェクトで使用可能なタスクを表示するには、以下のようにtaskコマンドを実行します。
❯ task
task: Available tasks for this project:
* default: ℹ️ Show all available tasks (run `task --list-all` to see hidden tasks)
* install: Install dependencies for all agent components and infra (aliases: req, install-all)
* start: ‼️ Quickstart for DataRobot Agent Templates ‼️
task startを実行してフレームワークを選択した後に、プロジェクトで使用可能なタスクを表示するには、以下のようにtaskコマンドを実行します。
❯ task
task: Available tasks for this project:
* default: ℹ️ Show all available tasks (run `task --list-all` to see hidden tasks)
* install: 🛠️ Install all dependencies for agent and infra
* agent:install: 🛠️ [agent_crewai] Install agent uv dependencies (aliases: agent:req)
* agent:add-dependency: 🛠️ [agent_crewai] Add provided packages as a new dependency to an agent
* agent:cli: 🖥️ [agent_crewai] Run the CLI with provided arguments
* agent:dev: 🔨 [agent_crewai] Run the development server
* agent:dev-stop: 🛑 [agent_crewai] Stop the development server
* agent:chainlit: 🛝 Run the Chainlit playground
* agent:create-docker-context: 🐳 [agent_crewai] Create the template for a local docker_context image
* agent:build-docker-context: 🐳 [agent_crewai] Build the Docker image
* infra:install: 🛠️ [infra] Install infra uv dependencies
* infra:build: 🔵 Deploy only playground testing resources with pulumi
* infra:deploy: 🟢 Deploy all resources with pulumi
* infra:refresh: ⚪️ Refresh and sync local pulumi state
* infra:destroy: 🔴 Teardown all deployed resources with pulumi
❯ task --list-all
task: Available tasks for this project:
* build:
* default: ℹ️ Show all available tasks (run `task --list-all` to see hidden tasks)
* deploy:
* destroy:
* install: 🛠️ Install all dependencies for agent and infra
* agent:add-dependency: 🛠️ [agent_crewai] Add provided packages as a new dependency to an agent
* agent:build-docker-context: 🐳 [agent_crewai] Build the Docker image
* agent:chainlit: 🛝 Run the Chainlit playground
* agent:cli: 🖥️ [agent_crewai] Run the CLI with provided arguments
* agent:create-docker-context: 🐳 [agent_crewai] Create the template for a local docker_context image
* agent:dev: 🔨 [agent_crewai] Run the development server
* agent:dev-stop: 🛑 [agent_crewai] Stop the development server
* agent:install: 🛠️ [agent_crewai] Install agent uv dependencies (aliases: agent:req)
* agent:lint:
* agent:lint-check:
* agent:test:
* agent:test-coverage:
* agent:update:
* infra:build: 🔵 Deploy only playground testing resources with pulumi
* infra:deploy: 🟢 Deploy all resources with pulumi
* infra:destroy: 🔴 Teardown all deployed resources with pulumi
* infra:info:
* infra:init:
* infra:install: 🛠️ [infra] Install infra uv dependencies
* infra:install-pulumi-plugin:
* infra:lint:
* infra:lint-check:
* infra:pulumi:
* infra:refresh: ⚪️ Refresh and sync local pulumi state
* infra:select:
* infra:select-env-stack:
* infra:test:
* infra:test-coverage:
また、使用可能なすべてのエージェントCLIコマンドを表示するには、task agent:cliを実行します。
テンプレートを選択するには、エージェントフレームワークを選択するプロンプトに答え、以下のオプションのいずれかを入力し、Enterを押します。
| オプション | ディレクトリ | フレームワーク | 説明 |
|---|---|---|---|
| 1 | agent_crewai |
CrewAI | ロールベースのマルチエージェントコラボレーションフレームワーク |
| 2 | agent_generic_base |
汎用 | あらゆるフレームワークの基本テンプレート |
| 3 | agent_langgraph |
LangGraph | 状態ベースのオーケストレーションフレームワーク |
| 4 | agent_llamaindex |
LlamaIndex | RAG中心のフレームワーク |
| 5 | agent_nat |
NeMo Agent Toolkit | NVIDIA NeMo Agent Toolkit framework |
どのテンプレートを選べばいいですか?
すべてのテンプレートでDataRobotのツールとDataRobot LLM Gatewayを使用できますが、理想的なシナリオはそれぞれ異なる場合があります。
CrewAI:CrewAIのテンプレートについて簡単に説明すると、「Who」に焦点を当てているということです。 役割分担とコラボレーションを必要とする問題の解決に最適で、創造的または分析的なタスクに共同で取り組む専門家からなるマルチエージェントチームの迅速なプロトタイプ化を得意としています。
LangGraph:LangGraphのテンプレートは「How」に焦点を当てており、プロセスと監査によって解決可能な問題に最適です。 細かな制御が必要な信頼性の高いシステムの構築に優れており、エラー処理や人的承認ループを備えた非常に堅牢なシステムを構築できます。 LangGraphのプロセス制御は、DataRobotの予測ツールを呼び出す前に人的承認が必要なワークフローや、データレジストリの操作に対して堅牢なエラー処理を構築するのに最適です。
LlamaIndex:LlamaIndexは「What」に焦点を当てており、データと専門知識を必要とする問題の解決に最適です。 ドキュメントを多用する特定の分野におけるエキスパートとして、強力なRAGベースのエージェントを構築することに優れています。 セマンティック検索にはDataRobotのベクターデータベース、ドキュメントの処理にはAryn DocParse、関連するデータセットの検出にはSearch Data Registryと組み合わせることができます。
Generic Base:Generic Baseテンプレートは、完全にカスタマイズ可能な最小限の基盤が必要な状況向けの、白紙の状態から始めるためのテンプレートです。 エージェントワークフローの開発や修正の経験がある場合、またはカスタムエージェントワークフローをゼロから構築する必要がある場合は、このテンプレートを選択します。 Generic Baseは、カスタムDataRobotエージェントツールの統合や、標準パターンに当てはまらないワークフローの構築において、最大限の柔軟性を提供します。
NAT (NVIDIA NeMo Agent Toolkit):NATのテンプレートは「ワークフロー」に焦点を当てており、宣言型のYAMLベースのエージェント設定を必要とする問題に最適です。
workflow.yamlファイルで定義されたマルチエージェントワークフローの構築に優れています。このため、設定駆動型の開発を好み、大幅なコード変更を行わずにエージェントの動作、LLMの設定、ツールの連携を定義したいチームに最適です。
次に、Y、Enterの順に押して、前提条件を導入し、選択したエージェントの環境を設定します。
Running these commands configures the environment for the selected template, removes all unnecessary files, and prepares the virtual environment (virtualenv or venv) to install the additional libraries required to run the selected agent template.
インストール済みの環境は、いつでも以下のコマンドを実行することで更新できます。
task install
エージェントワークフローのカスタマイズとテスト¶
Now you can customize the code of your agentic workflow in the {{ agent_name }}/custom_model folder. If you need to customize the execution environment with a custom Docker image, first create the docker context using task agent:create-docker-context, then modify the files in the {{ agent_name }}/docker_context directory.
エージェントにテストクエリーを送信するには、開発サーバーが稼働している必要があります。 手動で起動するか、自動起動オプションを使用します。
複数のテストを実行する場合は、開発サーバーを手動で起動します。 開発サーバーは継続的に実行され、ターミナルをブロックするため、1つのターミナルで起動します。
task agent:dev
このターミナルは起動したままにしておきます。 その後、別のターミナルでテストコマンドを実行します。
task agent:cli -- execute --user_prompt 'Hi, how are you?'
エージェントのワークフローが要求した場合、構造化クエリーをプロンプトとして送信することもできます。
task agent:cli -- execute --user_prompt '{"topic":"Generative AI"}'
単一のテスト用に開発サーバーを自動起動します。 START_DEV=1を使用して、開発サーバーを自動的に起動および停止します。
task agent:cli START_DEV=1 -- execute --user_prompt 'Hi, how are you?'
エージェントのワークフローが要求した場合、構造化クエリーをプロンプトとして送信することもできます。
task agent:cli START_DEV=1 -- execute --user_prompt '{"topic":"Generative AI"}'
出力結果をテキストファイルに書き出す
結果をコンソールではなくテキストファイルに出力するには、コマンドの最後に> output.txtを追加します。 たとえば、task agent:cli START_DEV=1 -- execute --user_prompt 'Hi, how are you?' > output.txtのように入力します。
エージェントワークフローのカスタムモデルの構築とテスト¶
テスト後、DataRobotでエージェントのワークフローを試すことができます。
task build
Pulumiは、作成するリソースを一覧表示します。 リソースを構築する準備ができたら、Enterを押して続行します。
Pulumiが実行環境の作成を完了するまで待ちます(約5分)。 作成が完了すると、PulumiはカスタムモデルIDと、エージェントワークフローのチャットインターフェイスのエンドポイントを報告します。
Agent Chat Completion Endpoint [agent_generic_base]: "https://app.datarobot.com/api/v2/genai/agents/fromCustomModel/683ed1fcd767c535b580bc1da/chat/"
Test this chat completion endpoint with the following command, replacing <CUSTOM_MODEL_ID> with the ID returned above (for example, 683ed1fcd767c535b580bc1da):
task agent:cli execute-custom-model --user_prompt '{"topic":"Generative AI"}' --custom_model_id <CUSTOM_MODEL_ID>
エクスペリメントモードでは、/chatインターフェイスを操作した際、変更を確認するためにカスタムモデルを再デプロイする必要はありません。 実行中のセッションでファイルの変更が同期されます。
実行環境の更新に関する注意事項
エージェントワークフローの実行環境を変更する場合、DataRobotがチャットリクエストの環境を再起動するまで待ちます。
エージェントのワークフローをデプロイ¶
エクスペリメントが終了したら、エージェントのワークフローをデプロイできます。
task deploy
Check that the agentic workflow works correctly by running the following command to receive an agentic workflow response:
task agent:cli -- execute-deployment --deployment_id %your_id% --user_prompt 'Hi, how are you?'
Make predictions with a deployed agentic workflow¶
After the agentic workflow is deployed, access real-time prediction snippets from the deployment's Predictions > Prediction API tab. For more information on deployment predictions, see the Prediction API snippets documentation.
Alternatively, you can modify the script below to make predictions with the deployed agentic workflow, replacing the placeholders for the API_KEY, DEPLOYMENT_ID, and CHAT_API_URL variables.
import sys
import logging
import time
import os
from openai import OpenAI
API_KEY = '<API_KEY>' # Your API Key
DEPLOYMENT_ID = '<DEPLYMENT_ID>' # The agentic workflow deployment ID
CHAT_API_URL = '<CHAT_API_URL>' # The chat API URL for the agentic workflow deployment
# For example, 'https://app.datarobot.com/api/v2/deployments/68824e9aa1946013exfc3415/'
logging.basicConfig(
level=logging.INFO,
stream=sys.stdout,
format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s %(message)s',
)
logger = logging.getLogger(__name__)
def main():
openai_client = OpenAI(
base_url=CHAT_API_URL,
api_key=API_KEY,
_strict_response_validation=False
)
prompt = "What would it take to colonize Mars?"
logging.info(f"Trying Simple prompt first: \"{prompt}\"")
completion = openai_client.chat.completions.create(
model="datarobot-deployed-llm",
messages=[
{"role": "system", "content": "Explain your thoughts using at least 100 words."},
{"role": "user", "content": prompt},
],
max_tokens=512, # omit if you want to use the model's default max
)
print(completion.choices[0].message.content)
return 0
if __name__ == '__main__':
sys.exit(main())
関連付けIDを指定し、カスタム指標を報告する¶
DataRobotにデプロイされたテキスト生成またはエージェントワークフローのカスタムモデルに対してチャットリクエストを行う場合、オプションで関連付けIDを指定できます。また、チャットリクエストのオプションのextra_bodyフィールドに特定のフィールドを設定することによって、デプロイに対して定義されたカスタム指標の値を報告できます。
フィールドdatarobot_association_idがextra_bodyにある場合、DataRobotでは、自動的に生成された値ではなく、その値が使われます。 フィールドdatarobot_metricsがextra_bodyにある場合、DataRobotでは、その中にあるすべての名前:値のペアのカスタム指標が報告されます。 各名前に一致するカスタム指標が、デプロイですでに定義されている必要があります。 報告された値が文字列である場合、カスタム指標は多クラス型であり、報告された値はいずれかのクラスと一致している必要があります。
関連付けIDの要件
extra_bodyが指定されているかどうかに関係なく、デプロイされたカスタムモデルには、DataRobotがチャットリクエストからカスタム指標を処理するために、関連付けID列が定義されている必要があります。 指標を処理するためには、カスタムモデルに対してモデレーションを設定する必要があります。
extra_body = {
# These values pass through to the LLM
"llm_id": "azure-gpt-6",
# If set here, replaces the auto-generated association ID
"datarobot_association_id": "my_association_id_0001",
# DataRobot captures these for custom metrics
"datarobot_metrics": {
"field1": 24,
"field2": "example"
}
}
completion = openai_client.chat.completions.create(
model="datarobot-deployed-llm",
messages=[
{"role": "system", "content": "Explain your thoughts using at least 100 words."},
{"role": "user", "content": prompt},
],
max_tokens=512,
extra_body=extra_body
)
print(completion.choices[0].message.content)
