Skip to Content

How do I see which agent version handled a request in a LangChain agent?

Rius shows the agent version on every trace in the Traces list and in the trace header, and you set it once per process with RIUS_MAIN_AGENT_VERSION. The LangChain integration records the steps of each run. The version you set rides along with all of them, so you add no span of your own to chain code. Open a trace to see which version handled that request.

How it works

The LangChain integration records the structure of a run. It hooks LangChain’s callback system and writes one span per step: chains as CHAIN spans, tool calls as TOOL spans, retrievers as RETRIEVER spans, and model calls as LLM spans with model, token usage and messages. Rius computes cost on the server. LangGraph nodes run through the same callbacks. Read the LangChain integration page for the full list.

The agent version is not one of those step spans. It is a resource attribute, rius.main_agent.version, that describes the process sending the trace. You set it with the RIUS_MAIN_AGENT_VERSION environment variable, which both SDKs read, or the main_agent_version argument of rius.init(), and every trace the process sends carries it. This is the version the Agents page compares.

The trace pages then show it:

  • The Traces list has a Version column that appears when traces carry a version. It shows the agent version, or the build when there is none.
  • The header of an open trace in the waterfall view shows the agent version, and the build when the trace carries one.
  • In Add filter, any span or resource attribute your agents send is available as a field, so you can filter on rius.main_agent.version. See Exploring traces for the filter builder.

Set it up

  1. Set the version in the environment of the process that runs your LangChain agent. Use whatever string identifies your release. You can also set RIUS_SERVICE_VERSION to put service.version on the same traces, and RIUS_AGENT_NAME to choose the name the agent is grouped under.
export RIUS_MAIN_AGENT_VERSION=1.4.0
  1. Install the LangChain instrumentation and call init() before you build your chains. The LangChain integration page covers the setup in full.
pip install "glassflow-rius[langchain]" langchain
import rius rius.init(api_key="ri_...", service_name="my-agent") # build and run your chains exactly as before
  1. Send a request through the agent, then open Traces in the console. The row for that run shows 1.4.0 in the Version column.
  2. Open the trace. The header shows the same version next to the duration, span count and cost, and the tree below shows your chains, tools and model calls nested as they ran.
  3. To find every request a given release handled, click Add filter, pick rius.main_agent.version as the Field, choose is, and pick or type the version. Filters combine with AND, so you can add a status or time range. The filters live in the URL, so a copied link opens the same list.
  4. When you ship a new release, change the value and restart the process. New traces carry the new version and old traces keep theirs.

If you run LangChain.js, set the same variable before the process starts and use the TypeScript setup on the LangChain integration page.

What you get

  • The version of the process that handled each trace, in the Version column and in the trace header.
  • A filter on version, so you can list only the traces from one release, or exclude a release you are rolling back.
  • The nested LangChain run under that version: chain, tool, retriever and model spans, with model, tokens and cost on the model calls.
  • Version comparison on the Agents page. Rius compares two versions of an agent on traces, failed rate, cost per trace, latency, time to first token (p50) and tokens per trace, and warns when either side has fewer than 20 traces.
  • Nothing to add inside your chains. The version is set once for the process, not per step.

For how this fits with the rest of your monitoring, see Monitor AI agents in production.

When something else fits

  • If you want to tell apart changes that do not change the process, such as a prompt edit you toggle at run time, give each variant its own value for the version in the process that serves it, because the version is set per process.
  • If you only need to know that a process is alive, rather than which release it runs, the Agents page and its heartbeat cover that without any version at all.

Still stuck? Get help

Last updated on