Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions docs/supported-integrations/oci-generative-ai.mdx

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file makes no reference to the created codecs. I claim that in order for any middleware to function, it would require the Relay library itself to be aware of the created Codecs.

I believe this supports my other comment.

Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
title: "NeMo Relay OCI Generative AI Integration"
sidebar-title: "OCI Generative AI Integration Guide"
description: "Add NeMo Relay observability to LangChain agents backed by Oracle Cloud Infrastructure (OCI) Generative AI."
position: 6
---
{/* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0 */}


Use the `nemo_relay.integrations.langchain` package to add NeMo Relay
observability to LangChain agents that call
[Oracle Cloud Infrastructure (OCI) Generative AI](https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/)
through the [`langchain-oci`](https://pypi.org/project/langchain-oci/) provider.

OCI Generative AI serves managed on-demand models (Meta Llama, Cohere Command,
xAI Grok, Google Gemini, and OpenAI models) and dedicated AI cluster endpoints,
including imported open-weights models such as NVIDIA Nemotron. The same
integration path covers both.

## Setup

Install the LangChain integration extra together with the OCI provider extra in
your application environment.

<Tabs>
<Tab title="uv">
```bash
uv add "nemo-relay[langchain,langchain-oci]"
```
</Tab>

<Tab title="pip">
```bash
pip install "nemo-relay[langchain,langchain-oci]"
```
</Tab>

</Tabs>

The `langchain-oci` provider authenticates with the OCI SDK. All standard OCI
authentication types work: API key, session token, instance principal, and
resource principal. Configure a profile in `~/.oci/config` or run on an OCI
compute instance with an instance principal.

## Usage Example

```python
import asyncio

import nemo_relay
from langchain.agents import create_agent
from langchain_core.tools import tool
from langchain_oci import ChatOCIGenAI
from nemo_relay.integrations.langchain import NemoRelayCallbackHandler, NemoRelayMiddleware


@tool
def get_weather(location: str) -> str:
"""Get the current weather for a location."""
return f"The weather in {location} is sunny and 72 degrees."


model = ChatOCIGenAI(
model_id="meta.llama-3.3-70b-instruct",
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
compartment_id="<compartment-ocid>",
auth_type="API_KEY",
model_kwargs={"temperature": 0.0, "max_tokens": 512},
)

agent = create_agent(
model=model,
tools=[get_weather],
middleware=[NemoRelayMiddleware()],
system_prompt="Use tools when they are relevant. Keep the final answer brief.",
)

input_payload = {
"messages": [
{
"role": "user",
"content": "What is the weather in San Francisco?",
}
]
}

with nemo_relay.scope.scope("langchain-request", nemo_relay.ScopeType.Agent):
result = asyncio.run(
agent.ainvoke(input_payload, config={"callbacks": [NemoRelayCallbackHandler()]})
)

final_message = result["messages"][-1]
print(f"Final response: {final_message.content}")
```

## Dedicated AI Cluster Endpoints

To call a model hosted on an OCI dedicated AI cluster — including imported
open-weights models such as NVIDIA Nemotron — pass the endpoint OCID as the
model ID. Everything else, including the NeMo Relay integration, stays the
same:

```python
model = ChatOCIGenAI(
model_id="ocid1.generativeaiendpoint.oc1.<region>.<endpoint-id>",
service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
compartment_id="<compartment-ocid>",
auth_type="API_KEY",
provider="meta",
)
Comment on lines +99 to +111

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the relevant docs and implementation.
git ls-files 'docs/supported-integrations/oci-generative-ai.mdx' 'README.md' 'docs/**' 'src/**' 'libs/**' 'packages/**' 2>/dev/null | sed -n '1,200p'

printf '\n--- provider references ---\n'
rg -n 'provider\s*=' docs/supported-integrations/oci-generative-ai.mdx README.md docs src libs packages -g '!**/dist/**' -g '!**/build/**' || true

printf '\n--- ChatOCIGenAI references ---\n'
rg -n 'ChatOCIGenAI|langchain-oci|generic|meta|Nemotron|OCI dedicated AI cluster|generativeaiendpoint' docs src libs packages -g '!**/dist/**' -g '!**/build/**' || true

Repository: NVIDIA/NeMo-Relay

Length of output: 26238


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the most relevant file sections with line numbers.
wc -l docs/supported-integrations/oci-generative-ai.mdx
sed -n '80,130p' docs/supported-integrations/oci-generative-ai.mdx

Repository: NVIDIA/NeMo-Relay

Length of output: 1637


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Read the implementation around the provider argument.
git ls-files | rg 'oci|generativeai|ChatOCIGenAI|langchain-oci' || true

Repository: NVIDIA/NeMo-Relay

Length of output: 399


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '90,120p' docs/supported-integrations/oci-generative-ai.mdx

Repository: NVIDIA/NeMo-Relay

Length of output: 1177


🌐 Web query:

langchain-oci provider generic meta imported model Nemotron ChatOCIGenAI documentation

💡 Result:

To use an imported NVIDIA Nemotron model on Oracle Cloud Infrastructure (OCI) with LangChain, you should utilize the ChatOCIGenAI class provided by the langchain-oci package [1][2]. When using imported models (such as Nemotron 3 Super) hosted on a Dedicated AI Cluster (DAC) within the OCI Generative AI service, you configure the ChatOCIGenAI client by specifying the model's endpoint OCID and setting the provider argument to "generic" [2][3]. Implementation example: from langchain_oci import ChatOCIGenAI # Using an imported model on a Dedicated AI Cluster llm = ChatOCIGenAI( model_id="ocid1.generativeaiendpoint.oc1.us-chicago-1.example...", # Your endpoint OCID provider="generic", # Required for imported models service_endpoint="https://inference.generativeai.us-chicago-1.oci.oraclecloud.com", compartment_id="ocid1.compartment.oc1..example...", model_kwargs={"temperature": 0.7, "max_tokens": 500},) Key details for this setup: - Package: You must use the langchain-oci package [4]. The older OCI integrations in langchain-community are deprecated [4]. - Provider: The provider parameter must be set to "generic" for imported models to properly interface with the custom endpoints created via OCI's Model Import capability [2][3]. - Model ID: For imported models, the model_id parameter requires the full OCID of the Generative AI endpoint (beginning with ocid1.generativeaiendpoint), not just the model name [2][3]. - Infrastructure: OCI supports importing open-weights models like NVIDIA Nemotron through the OCI Generative AI Model Import feature, which allows these models to be deployed on Dedicated AI Clusters and accessed using standard OCI Generative AI APIs and LangChain wrappers [5][6].

Citations:


Use generic for imported OCI models like Nemotron. provider="meta" is for Meta Llama; this example should use generic or explicitly tell users to choose the provider that matches the imported model family.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/supported-integrations/oci-generative-ai.mdx` around lines 99 - 111,
Update the ChatOCIGenAI example to use provider="generic" for imported
open-weights models such as NVIDIA Nemotron, or explicitly instruct users to
select the provider matching their imported model family; do not leave
provider="meta", which is specific to Meta Llama.

Source: Path instructions

```

## Verify the Integration

The integration works correctly when:

- The agent run completes and prints a final response.
- The `langchain-request` scope contains the managed model call.
- Tool activity appears under the same request when the agent decides to use `get_weather`.

## Observability

Refer to [Observability](/configure-plugins/observability/about) for details on exporting NeMo Relay observability data to third-party systems.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ langchain-nvidia = [
"aiohttp>=3.14.1",
]

langchain-oci = [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the need to have this extra. There is no code that depends on the langchain-oci package

"nemo-relay[langchain]",
"langchain-oci>=0.2.4,<1.0.0",
]

[tool.maturin]
manifest-path = "crates/python/Cargo.toml"
python-source = "python"
Expand Down
16 changes: 16 additions & 0 deletions python/nemo_relay/providers/__init__.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These types of codecs should probably live in the Rust core so any language can leverage it natively. As written, this would only be compatible in Python (which is uneven support and harder to justify).

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Provider-specific request and response codecs for ``nemo_relay.llm``.

Modules in this package implement the ``nemo_relay.codecs.LlmCodec`` and
``nemo_relay.codecs.LlmResponseCodec`` protocols for LLM providers whose wire
formats are not covered by the built-in OpenAI and Anthropic codecs.
"""

from nemo_relay.providers.oci_genai import OCIGenAIChatCodec, OCIGenAIResponseCodec

__all__ = [
"OCIGenAIChatCodec",
"OCIGenAIResponseCodec",
]
Loading