メタデータを使用したLLMプロバイダーの設定¶
LLMエージェントの重要な構成要素のひとつは、基盤となるLLMプロバイダーです。 DataRobotでは、ユーザーがエージェントワークフローのために、事実上あらゆるLLMバックエンドに接続できます。 LLM接続は、DataRobot LLM GatewayまたはDataRobotデプロイ(NIMデプロイを含む)を使用することで簡素化できます。 あるいは、OpenAI API標準をサポートする外部のLLMプロバイダーに接続することもできます。
DataRobot Agentic Starterのテンプレートには、エージェントLLMを定義するための複数の方法が用意されています。
- エージェントLLMとしてDataRobot LLM Gatewayを使用し、Gatewayで利用可能な任意のモデルを使用できます。
- デプロイIDを指定することで、DataRobot APIを使用して以前にデプロイされたカスタムモデルまたはNIMを使用するように接続します。
- 必要なAPI資格情報を提供することで、LLMプロバイダーのAPI(OpenAI、Anthropic、Geminiなど)に直接接続し、互換性のあるAPIをサポートするプロバイダーにアクセスできるようにします。
このドキュメントでは、環境変数とPulumi(インフラストラクチャレベルの設定)を使用したLLMプロバイダーの設定に焦点を当てています。 この方法により、エージェントコードを変更することなく、異なるLLMプロバイダー設定を切り替えることができます。 インフラストラクチャ設定ファイルはdatarobot_genaiパッケージのbuild_llm()ヘルパー関数を使用し、デプロイの検出、Gatewayの設定、および資格情報の管理を自動的に処理します。 これは、DataRobotの安全な資格情報システムを活用することで、デプロイと資格情報管理を簡素化します。
別の設定方法
きめ細かい制御のためにmyagent.pyファイルで直接LLMインスタンスを手動で作成したい場合は、コードを使用したLLMプロバイダーの設定を参照して、その方法の詳細を確認してください。
インフラストラクチャレベルのLLM設定¶
LLMプロバイダーは、環境変数とシンボリックリンクを使ってインフラストラクチャレベルで設定できます。 これにより、エージェントコードを変更することなく、異なるLLMプロバイダー設定を切り替えることができます。 どちらの方法もinfra/infra/llm.pyからinfra/configurations/llm/にある設定ファイルへのシンボリックリンクを作成します。 利用可能な設定オプションは以下のとおりです。
| 設定ファイル | 説明 |
|---|---|
gateway_direct.py |
LLM Gatewayとの直接連携。 |
deployed_llm.py |
DataRobotにデプロイされたLLM。 |
blueprint_with_external_llm.py |
外部LLM(Azure OpenAI、Amazon Bedrock、Google Vertex AI、Anthropic)によるLLMブループリント。 |
手動シンボリックリンク¶
シンボリックリンクを手動で作成し、アクティブな設定を明示的に制御し、すぐに確認できるようにします。 開発にはこの方法が推奨されます。
この方法を使うには、infra/infraフォルダーに移動し、選択した構成へのシンボリックリンクを作成します。
cd infra/infra
ln -sf ../configurations/llm/<chosen_configuration>.py
を利用可能な設定ファイル(たとえばgateway_direct.py、blueprint_with_llm_gateway.py`など)のどれかに置き換えてください。
シンボリックリンクを作成した後、infra/infra/llm.pyを編集してモデルのパラメーター(temperature、top_pなど)を調整したり、特定のモデルを選択することができます。
環境変数¶
環境変数を使って動的に構成を設定します。 Pulumiコマンドを実行すると、シンボリックリンクが自動的に作成されます。 この方法は、デプロイやさまざまな環境で推奨されます。
この方法を使うには、.envファイルで該当セクションのコメントを解除します。 .env.templateの以下の例は、各LLMプロバイダータイプの設定方法を示しています。 各構成には、追加の環境変数が必要な場合があります。
CodespacesでのDataRobotの資格情報
DataRobotのCodespaceを使用している場合は、ファイルからDATAROBOT_API_TOKENおよびDATAROBOT_ENDPOINT環境変数を削除します。これらはCodespace環境にすでに存在しているためです。
# Your DataRobot API token.
# Refer to https://docs.datarobot.com/en/docs/api/dev-learning/api-quickstart.html#configure-your-environment for help.
DATAROBOT_API_TOKEN=
# The URL of your DataRobot instance API.
DATAROBOT_ENDPOINT=https://app.datarobot.com/api/v2
# The Pulumi stack name to use for this project.
PULUMI_STACK=dev
# If empty, a blank passphrase will be used
PULUMI_CONFIG_PASSPHRASE=123
# Set to 1 to skip Pulumi update check and prevent issues with rate limiting
PULUMI_SKIP_UPDATE_CHECK=0
# If empty, a new use case will be created
DATAROBOT_DEFAULT_USE_CASE=
# 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"
# This is set to a specific version of `[DataRobot] Python 3.11 GenAI Agents` to preserve compatibility of the templates
DATAROBOT_DEFAULT_EXECUTION_ENVIRONMENT_VERSION_ID="6936d3af440bcb12397f4203"
# LLM Configuration:
# Agent templates support multiple flexible LLM options including:
# - LLM Gateway Direct (default)
# - LLM Blueprint with an External LLM
# - Already deployed LLM in DataRobot
#
# You can edit the LLM configuration by manually changing which configuration is
# active (recommended option).
# Simply run `ln -sf ../configurations/llm/<chosen_configuration>.py`
# from the `infra/infra` folder
#
# If you want to do it dynamically however, you can also set it as a configuration value with:
# INFRA_ENABLE_LLM=<chosen_configuration>
# from the list of options in the infra/configurations/llm folder
# Here are some examples of each of those configuration using the dynamic option described above:
# If you want to use the LLM gateway direct (default)
# INFRA_ENABLE_LLM=gateway_direct.py
# If you want to choose an existing LLM Deployment in DataRobot
# uncomment and configure these:
# LLM_DEPLOYMENT_ID=<your_deployment_id>
# INFRA_ENABLE_LLM=deployed_llm.py
# If you want to configure an LLM with an external LLM provider
# like Azure, Bedrock, Anthropic, or VertexAI (or all 4). Here we provide
# an Azure AI example, see:
# https://docs.datarobot.com/en/docs/gen-ai/playground-tools/deploy-llm.html
# for details on other providers and details:
# INFRA_ENABLE_LLM=blueprint_with_external_llm.py
# LLM_DEFAULT_MODEL="azure/gpt-4o"
# OPENAI_API_VERSION='2024-08-01-preview'
# OPENAI_API_BASE='https://<your_custom_endpoint>.openai.azure.com'
# OPENAI_API_DEPLOYMENT_ID='<your deployment_id>'
# OPENAI_API_KEY='<your_api_key>'
task infra:buildまたはtask infra:deployを実行すると、システムはINFRA_ENABLE_LLM`を読み込み、指定した設定ファイルへのシンボリックリンクを自動的に作成または更新し、DataRobotのセキュアな資格情報システムで資格情報を管理します。
LLMの設定オプション¶
| 設定ファイル | 説明 |
|---|---|
gateway_direct.py |
.envファイルで指定されていない場合は、デフォルトのオプションになります。 LLM Gatewayの直接統合により、DataRobot経由でプロキシされたLLMへの合理化されたアクセスを提供します。 クラウドとオンプレミスの両方で利用可能。 このファイルを選択する以外の追加設定は必要ありません。 LLM Gatewayオプションを使用する場合、エージェントはGatewayカタログで利用可能なすべてのモデルを動的に使用することができます。 エージェントまたはタスクごとに優先モデルを指定できるため、用途に応じて最適化できます(例:プランニングにはより高速なモデル、コンテンツ生成にはより高性能なモデル)。 |
deployed_llm.py |
以前にデプロイしたDataRobot LLMを使用します。 Requires LLM_DEPLOYMENT_ID (your deployment ID). |
blueprint_with_external_llm.py |
Azure、Bedrock、Anthropic、VertexAIなどの外部プロバイダーを使用してLLMを設定します。 LLM_DEFAULT_MODEL(例:"azure/gpt-4o")が必要です。 LLM Gatewayのオプションとは異なり、すべてのエージェントは、設定で指定された同じモデルを使用します。 単一の外部デプロイに接続しているため、LLM_DEFAULT_MODELがプライマリーモデルになります。 その他のプロバイダーの詳細については、DataRobotのドキュメントを参照してください。 |
デフォルトのモデルを編集する必要があるのはどのような場合ですか?
デフォルトのモデルの動作は、設定のタイプによって異なります。
- LLM Gatewayの設定(
gateway_direct.py):デフォルトのモデルは自動的に設定され、変更する必要はほとんどありません。 エージェントは、カタログから任意のモデルを動的に使用できます。 - デプロイされたモデル(
deployed_llm.py):デフォルトのモデルは、デプロイに合わせて自動的に設定されます。 手動による変更は不要です。 - 外部LLMの設定(
blueprint_with_external_llm.py):外部LLMのデプロイに合わせてdefault_modelを編集し、接続するための資格情報を追加します。 これは、すべてのエージェントが使用するモデルです。
DataRobot LLM Gatewayの設定¶
LLM Gatewayは、DataRobot経由でプロキシされたLLMにアクセスする合理的な方法を提供します。 このGatewayは、クラウドとオンプレミスの両方のユーザーが利用できます。
以下の方法で、アカウントで利用可能なモデルのリストを取得できます。
curl -X GET -H "Authorization: Bearer $DATAROBOT_API_TOKEN" "$DATAROBOT_ENDPOINT/genai/llmgw/catalog/" | jq '[.data[] | select(.isActive == true) | .model]'
from datarobot.models.genai import LLMGatewayCatalog
print("\n".join(LLMGatewayCatalog.get_available_models()))
LLM Gateway:複数のグラフノードおよびモデル選択¶
With the LLM gateway and the current Agentic Starter LangGraph layout, model selection works as follows:
- Default model source: Your infrastructure configuration and helpers such as
infra/configurations/llm/gateway_direct.pydetermine the default catalog model. - What reaches your graph: The chat model is the
llmargument tograph_factory(llm, tools, verbose). It is resolved byget_llmand related helpers in the DRUM/DRAgent adaptor path before your graph runs. - Changing the model: You can still adjust selection using gateway catalog settings, separate LLM deployments, or custom LLM construction in code. For the code-based approach, see Configure LLM providers with code.
The examples below use the same LangGraph primitives as the template (create_agent and make_system_prompt), but expressed inside graph_factory so they match how MCP tools are supplied via the tools parameter.
Same model for every node (default pattern). Both create_agent calls use the same llm, so they share one resolved model (typically your configured default):
from datarobot_genai.core.agents import make_system_prompt
from langchain.agents import create_agent
def graph_factory(llm, tools, verbose=False):
planner = create_agent(
llm,
tools=tools,
system_prompt=make_system_prompt(
"You are a content planner. Plan engaging and factually accurate content on {topic}."
),
name="planner_agent",
debug=verbose,
)
writer = create_agent(
llm,
tools=tools,
system_prompt=make_system_prompt(
"You are a content writer. Write insightful and factually accurate opinion piece about the topic: {topic}."
),
name="writer_agent",
debug=verbose,
)
...
ノードごとに異なるGatewayモデル(オプション)。 LLM Gatewayを使用する場合、明示的なmodel=文字列(APIのベースと資格情報はllm()と同じですが、モデルIDが異なります)でChatLiteLLMを構築することにより、各ノードを異なるカタログモデルに割り当てることができます。 GatewayのカタログIDを使用します(例:上記の例にあるLLMGatewayCatalog.get_available_models()が返す値)。
from datarobot_genai.core.agents import make_system_prompt
from langchain.agents import create_agent
from langchain_litellm.chat_models import ChatLiteLLM
def _llm_for_gateway_model(self, model: str) -> ChatLiteLLM:
"""Chat model for a specific LLM gateway catalog model."""
api_base = self.litellm_api_base(self.config.llm_deployment_id)
return ChatLiteLLM(
model=model,
api_base=api_base,
api_key=self.api_key,
timeout=self.timeout,
streaming=True,
max_retries=3,
)
@property
def agent_planner(self) -> Any:
return create_agent(
self._llm_for_gateway_model("datarobot/azure/gpt-5-mini-2025-08-07"),
tools=self.mcp_tools,
system_prompt=make_system_prompt(
"You are a content planner. Plan engaging and factually accurate content on {topic}."
),
name="planner_agent",
)
@property
def agent_writer(self) -> Any:
return create_agent(
self._llm_for_gateway_model("datarobot/azure/gpt-4o-2024-11-20"),
tools=self.mcp_tools,
system_prompt=make_system_prompt(
"You are a content writer. Write insightful and factually accurate opinion piece about the topic: {topic}."
),
name="writer_agent",
)
Factory-based LangGraph templates
The current Agentic Starter LangGraph template does not use MyAgent subclasses or self.mcp_tools. Implement the same pattern inside graph_factory(llm, tools, verbose): call a shared helper (for example, one that mirrors self._llm_for_gateway_model but takes configuration from your environment or from datarobot_genai.langgraph.llm) to build each ChatLiteLLM, pass tools=tools, and wire the returned create_agent nodes into your StateGraph.
モデル文字列を、アカウントおよびGateway Catalogで有効なIDに置き換えます。 Gatewayの代わりにデプロイ済みLLMまたは外部LLMのインフラストラクチャ設定を使用する場合、通常、すべてのノードが1つのデプロイまたは1つの外部モデルを共有します。以下のセクションを参照してください。
モデル文字列をオーバーライドせずにself.llm()を使用すると、Gateway設定(たとえば gateway_direct.py)のデフォルトモデルが適用されます。
default_model: str = "datarobot/azure/gpt-5-mini-2025-08-07" # Used when nodes call self.llm() and for fallbacks
DataRobotがホストするLLMデプロイ¶
エージェントのLLMプロバイダーとして、DataRobotがホストするLLMデプロイに簡単に接続できます。 DataRobotがホストするLLMは、モデレーション、ガードレール、および高度な監視へのアクセスを提供し、モデルの管理とガバナンスを支援します。 デプロイされたLLMを使用する場合、すべてのエージェントは同じデプロイを使用します。 構成には自動的に正しいモデル識別子が設定されるため、手動でのモデル構成は必要ありません。 LLMのデプロイを作成する方法は複数あります。
- DataRobotのプレイグラウンドから:DataRobotのプレイグラウンドからLLMをデプロイする
- Hugging Faceモデル:Hugging FaceモデルをLLMのデプロイとしてホスト
デプロイ後、デプロイIDをコピーして.envファイルに追加します。
LLM_DEPLOYMENT_ID=<your_deployment_id>
INFRA_ENABLE_LLM=deployed_llm.py
デフォルトのモデルは、デプロイに合わせて自動的に設定されます。 すべてのエージェントがこのデプロイを使用します。
LLM gateway flag for deployed LLMs
When you configure the agent with the DataRobot Deployed LLM option, USE_DATAROBOT_LLM_GATEWAY is automatically set to 0 so inference uses your deployment rather than the LLM gateway. You do not need to set this value manually for that option.
外部LLMの設定¶
Azure OpenAIやAmazon Bedrockなどの外部LLMで設定されている場合、ワークフロー内のすべてのエージェントは、設定で指定されたモデルを使用します。 LLM Gatewayとは異なり、この接続は単一の特定のモデルデプロイへのものです。
Azure OpenAIでは、Azure環境にOpenAIモデルをデプロイできます。 DataRobotは、blueprint_with_external_llm.pyの設定を使ってこれらのデプロイに接続できます。 .envファイルで、以下の環境変数のコメントを外し、値を指定します。
# If you want to configure an LLM with an external LLM provider
# like Azure, Bedrock, Anthropic, or VertexAI (or all 4). Here we provide
# an Azure AI example, see:
# https://docs.datarobot.com/en/docs/gen-ai/playground-tools/deploy-llm.html
# for details on other providers and details:
INFRA_ENABLE_LLM=blueprint_with_external_llm.py
LLM_DEFAULT_MODEL="azure/gpt-4o"
OPENAI_API_VERSION='2024-08-01-preview'
OPENAI_API_BASE='https://<your_custom_endpoint>.openai.azure.com'
OPENAI_API_DEPLOYMENT_ID='<your deployment_id>'
OPENAI_API_KEY='<your_api_key>'
LLM_DEFAULT_MODELは、Azureのデプロイと一致する必要があります。 たとえば、Azureにgpt-4oをデプロイした場合は、azure/gpt-4oを使用します。
資格情報管理
APIキーは、DataRobotの資格情報管理システムを通じて、APIトークンの資格情報タイプとして安全に管理されます。
Amazon Bedrockは、AWSを通じてさまざまなプロバイダーの基盤モデルにアクセスできます。 設定には、DataRobotを通じて安全に管理されたAWS認証情報を使用します。 .envファイルで、以下の環境変数を挿入して、値を指定します。
INFRA_ENABLE_LLM=blueprint_with_external_llm.py
AWS_ACCESS_KEY_ID='<your_access_key>'
AWS_SECRET_ACCESS_KEY='<your_secret_key>'
AWS_REGION_NAME='us-east-1'
続いて、infra/configurations/llm/blueprint_with_external_llm.pyを編集して、Bedrockモデルを指定します。
external_model_id: str = "bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0"
資格情報管理
AWSの認証情報はDataRobotの資格情報管理システムで管理されます。 このシステムは、アクセスキー、シークレットキー、およびオプションのセッショントークンを安全に保管します。
Google Vertex AIでは、Geminiを含むGoogleの基盤モデルにアクセスできます。 設定には、Google Cloudサービスのアカウント認証情報が使われます。 .envファイルで、以下の環境変数を挿入して、値を指定します。
INFRA_ENABLE_LLM=blueprint_with_external_llm.py
GOOGLE_SERVICE_ACCOUNT='<your_service_account_json>'
# or
GOOGLE_APPLICATION_CREDENTIALS='/path/to/service-account.json'
GOOGLE_REGION='us-west1'
続いて、infra/configurations/llm/blueprint_with_external_llm.pyを編集して、Vertex AIモデルを指定します。
external_model_id: str = "vertex_ai/gemini-2.5-pro"
資格情報管理
Google Cloud Platformの認証情報はDataRobotの資格情報管理システムで管理されます。 サービスアカウントのJSONコンテンツを直接指定するか(GOOGLE_SERVICE_ACCOUNT)、JSONファイルへのパスを指定します(GOOGLE_APPLICATION_CREDENTIALS)。
AnthropicのClaudeモデルは、APIから直接アクセスできます。 .envファイルで、以下の環境変数を挿入して、値を指定します。
INFRA_ENABLE_LLM=blueprint_with_external_llm.py
ANTHROPIC_API_KEY='<your_api_key>'
続いて、infra/configurations/llm/blueprint_with_external_llm.pyを編集します。
external_model_id: str = "anthropic/claude-3-5-sonnet-20241022"
資格情報管理
APIキーは、DataRobotの資格情報管理システムを通じて、APIトークンの資格情報タイプとして安全に管理されます。
その他のLLMプロバイダー¶
このテンプレートは、LiteLLMを通じて100以上のLLMプロバイダーをサポートしています。
- Cohere:
COHERE_API_KEYで設定 - Together AI:
TOGETHERAI_API_KEYで設定 - Hugging Face:適切なプロバイダー資格情報で設定
- Ollama:ローカルでホストされたモデルの場合
- OpenAI Direct:OpenAI APIへの直接アクセス
テンプレートの設定ファイルでネイティブにサポートされていないプロバイダーについては、エージェントコードを修正し、カスタムのdef llm()実装を持つ LLM gateway Direct 設定を使用することで、LiteLLM の直接統合を実装できます。
LiteLLMとDataRobot資格情報管理の直接統合¶
このアプローチでは、DataRobotの資格情報管理システムに資格情報を安全に格納しながら、LLMの初期化を完全に制御することができます。 以下の例では、LangGraphをCohereと直接統合して使用しています。
.envファイル内のLLM Gateway直接設定を選択します。
INFRA_ENABLE_LLM=gateway_direct.py
model-metadata.yaml(例:agent/agent/model-metadata.yaml)に資格情報を追加します。
runtimeParameterDefinitions:
- fieldName: COHERE_API_KEY
type: credential
- fieldName: COHERE_MODEL
type: string
defaultValue: "command-r-plus"
config.pyを更新して、資格情報を読み込みます(例:agent/agent/config.py)。
from pydantic import Field
class Config(BaseConfig):
# ... existing fields ...
cohere_api_key: str
cohere_model: str = "command-r-plus"
agent/agent/myagent.pyのllm()メソッドを置き換えます。
from langchain_openai import ChatOpenAI
def llm(
self,
preferred_model: str | None = None,
auto_model_override: bool = True,
) -> ChatOpenAI:
"""Returns a ChatOpenAI instance configured to use Cohere via LiteLLM.
Args:
preferred_model: The model to use. If None, uses COHERE_MODEL from config.
auto_model_override: Ignored for direct LiteLLM integration.
"""
return ChatOpenAI(
model=self.config.cohere_model, # Override the model with the configured one
api_key=self.config.cohere_api_key,
base_url="https://api.cohere.ai/v1", # Cohere's OpenAI-compatible endpoint
timeout=self.timeout,
)
次に、infra/configurations/llm/gateway_direct.pyにPulumiの資格情報管理を追加します。
...existing code
# Create the Cohere credential
cohere_credential = datarobot.ApiTokenCredential(
resource_name=f"{pulumi.get_project()} Cohere API Key Credential",
api_token=os.environ.get("COHERE_API_KEY"),
)
# Update the runtime parameters arrays
app_runtime_parameters = [
datarobot.ApplicationSourceRuntimeParameterValueArgs(
key="COHERE_API_KEY",
type="credential",
value=cohere_credential.id,
),
datarobot.ApplicationSourceRuntimeParameterValueArgs(
key="COHERE_MODEL",
type="string",
value=os.environ.get("COHERE_MODEL", "command-r-plus"),
),
]
custom_model_runtime_parameters = [
datarobot.CustomModelRuntimeParameterValueArgs(
key="COHERE_API_KEY",
type="credential",
value=cohere_credential.id,
),
datarobot.CustomModelRuntimeParameterValueArgs(
key="COHERE_MODEL",
type="string",
value=os.environ.get("COHERE_MODEL", "command-r-plus"),
),
]
最後に、.envファイルに環境変数を設定します。
INFRA_ENABLE_LLM=gateway_direct.py
COHERE_API_KEY='<your_api_key>'
COHERE_MODEL='command-r-plus'
このアプローチでは、DataRobotの安全な資格情報ストレージを使用しながら、LLMの初期化と資格情報管理を完全に制御できます。 資格情報はランタイムパラメーターとして管理され、アプリケーションコードにハードコードされることはありません。
設定の変更内容をデプロイする¶
LLMの設定を変更(.env変数の更新、設定ファイルの切り替え、設定パラメーターの変更)した後は、エージェントを実行する前に更新した設定をデプロイする必要があります。
task infra:deploy
このコマンドは、最新の設定でデプロイを更新し、エージェントが正しい資格情報で適切なLLMに接続するようにします。 このコマンドは、以下のタイミングで実行します。
- LLM設定の切り替え後
- 資格情報またはAPIキーの更新後
- モデルパラメーター(
temperature、top_pなど)の修正後 - 新しい設定を使ってローカルでエージェントを実行する前
LLMの高度な設定¶
.envファイルの設定に加えて、llm.py`設定ファイルを直接編集して、以下のような追加変更を行うことができます。
- Temperatureの設定(デプロイされたブループリントに適用されます)
- top_pの値(デプロイされたブループリントに適用されます)
- タイムアウトの設定(GPUベースのモデルに便利)
- その他のモデル固有のパラメーター