Skip to main content
Auto-instrumentor for LangChain V1 agents. Monkey-patches langchain.agents.create_agent so that every agent created after instrument() is called receives a FiddlerAgentMiddleware automatically. Callers no longer need to pass middleware=[FiddlerAgentMiddleware(...)] to each create_agent call. When a call to create_agent includes a name argument (e.g. name='flight_assistant'), that name is used for the agent in traces. Otherwise, no agent name is set (empty string), so the agent is not labeled in the UI. If a call to create_agent already includes a FiddlerAgentMiddleware instance in its middleware list, the instrumentor skips injection for that call so existing manual configurations are preserved. Note: Instrumentation persists for the lifetime of the application unless explicitly removed by calling uninstrument(). Calling instrument() multiple times is safe — it will not create duplicate middleware. Usage:
import langchain.agents

from fiddler_otel import FiddlerClient
from fiddler_langchain import FiddlerLangChainInstrumentor

client = FiddlerClient(api_key="...", application_id="...", url="...")

instrumentor = FiddlerLangChainInstrumentor(client=client)
instrumentor.instrument()

# Use the module attribute (not a `from ... import` alias) so the call goes
# through the patched version at run-time:
agent = langchain.agents.create_agent(model=..., tools=[...])
agent.invoke({"messages": [...]})

# Remove instrumentation when done:
instrumentor.uninstrument()
Note: instrument() patches the langchain.agents module attribute. If you prefer from langchain.agents import create_agent, call instrument() before that import so the local name is bound to the patched wrapper.

Parameters

client
FiddlerClient
required
The FiddlerClient instance. Required.

Raises

RuntimeError – If the FiddlerClient tracer cannot be initialized.

instrument()

Enable automatic instrumentation of LangChain V1 agents. Activates the instrumentor by patching langchain.agents.create_agent to automatically inject FiddlerAgentMiddleware into all agent instances created afterwards. This method is idempotent — calling it multiple times has the same effect as calling it once. After activation, all newly created agents will automatically include Fiddler’s middleware.

Parameters

**kwargs
Any
Additional instrumentation configuration (currently unused).

Example

import langchain.agents

from fiddler_otel import FiddlerClient
from fiddler_langchain import FiddlerLangChainInstrumentor

client = FiddlerClient(api_key="...", application_id="...", url="...")
instrumentor = FiddlerLangChainInstrumentor(client=client)
instrumentor.instrument()

# Use module attribute so the patched version is called:
agent = langchain.agents.create_agent(model=model, tools=[...])

# Check if instrumentation is active
if instrumentor.is_instrumented_by_opentelemetry:
    print("Instrumentation is active")

uninstrument()

Disable automatic instrumentation and restore original behavior. Deactivates the instrumentor by restoring the original langchain.agents.create_agent function. Agents created after calling this method will no longer have FiddlerAgentMiddleware automatically injected. Note: This does not affect agents that were already created while instrumentation was active — those will retain their middleware.

Parameters

**kwargs
Any
Additional uninstrumentation configuration (currently unused).

Example

instrumentor = FiddlerLangChainInstrumentor(client=client)
instrumentor.instrument()

# Create some agents (automatically instrumented)
agent1 = create_agent(model=model, tools=[...])

# Deactivate instrumentation
instrumentor.uninstrument()

# New agents won't be instrumented
agent2 = create_agent(model=model, tools=[...])

# agent1 still has the middleware, agent2 does not

instrumentation_dependencies()

Returns the package dependencies required for this instrumentor.

Returns

A collection of package dependency strings.