LangChain Quick Start
Goal
Run one LangChain agent and write its model and tool lifecycle to a local Agent Trajectory Observability Format (ATOF) file.
Use the event relationships to follow model and tool work through a run and check where the expected activity occurred.
Prerequisites
Before you start, make sure you have:
- Python 3.11 or newer
uv- Inference access: an NVIDIA API key for this example, or credentials for your own provider
Install
Create a project and install the NeMo Relay version for these docs with the
LangChain and NVIDIA model provider extras.
For an existing uv project, run only the uv add command from its directory.
Set your NVIDIA API key for the current shell:
Unix shell
Windows PowerShell
Relay does not impose a model choice. This copyable example selects the public
nvidia/nemotron-3.5-lightning-30b-a3b
model through the NVIDIA provider. To use another model or provider, replace
the example’s model argument and configure that provider’s credentials.
The NVIDIA provider reads NVIDIA_API_KEY. In the LangChain string, the first nvidia:
selects the provider; the remaining nvidia/... value is the model ID.
Configure
plugins.toml enables Relay’s observability component and writes its events
to logs/events.jsonl. In your own project, use the same plugin configuration
with the integration code below; the marker task and success checks are only
the quick start’s validation example.
Save the following configuration as plugins.toml in your project directory:
ATOF output can contain sensitive prompts, responses, tool arguments, and tool
results. Protect logs/events.jsonl even when full payload export is disabled.
Run
The example creates a LangChain agent with one marker tool. The
require_marker_tool middleware makes this test request a tool result before
its final answer; it is test scaffolding rather than required Relay setup.
NemoRelayMiddleware observes model and tool execution, and
NemoRelayCallbackHandler records the framework lifecycle. Plugin activation
loads plugins.toml, the outer scope groups the request, and flushing finishes
writing queued events before verification.
In your own agent, keep the Relay middleware, callback, activation, scope, and flush lifecycle. Replace the marker tool and prompt with your application work; the assertions after invocation and event-file checks belong to this example.
Save this file as quickstart.py beside plugins.toml:
Run it from the project directory:
Verify
The program checks the tool result, final assistant response, and paired ATOF agent, tool, and LLM records. A successful run prints these markers in order:
The model can use different wording around the response marker. These checks validate a live provider call; they do not make the model deterministic.
Inspect the Recorded Activity
Print one completed model call from the event file:
category and name identify the recorded work. The same uuid pairs its
start and end records; parent_uuid connects it to its enclosing scope.
timestamp records when this event occurred. For model calls, category_profile
and metadata can include the model identity and completion status, depending
on the integration. These fields let you follow a call through the run without
requiring full prompt or response capture.
For More Details
For more details, refer to: