> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fiddler.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# FiddlerLangChainInstrumentor

> Auto-instrumentor for LangChain V1 agents.

Auto-instrumentor for LangChain V1 agents.

Monkey-patches `langchain.agents.create_agent` so that every agent
created after [`instrument()`](#instrument) is called receives a
[`FiddlerAgentMiddleware`](/sdk-api/langchain/fiddler-agent-middleware) 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`](/sdk-api/langchain/fiddler-agent-middleware) 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:

```python theme={null}
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

<ParamField path="client" type="FiddlerClient" required={true}>
  The FiddlerClient instance. **Required**.
</ParamField>

## 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`](/sdk-api/langchain/fiddler-agent-middleware) 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

<ParamField path="**kwargs" type="Any" required={false}>
  Additional instrumentation configuration (currently unused).
</ParamField>

### Example

```python theme={null}
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`](/sdk-api/langchain/fiddler-agent-middleware)
automatically injected.

Note: This does not affect agents that were already created while
instrumentation was active — those will retain their middleware.

### Parameters

<ParamField path="**kwargs" type="Any" required={false}>
  Additional uninstrumentation configuration (currently unused).
</ParamField>

### Example

```python theme={null}
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

<ResponseField type="Collection[str]">
  A collection of package dependency strings.
</ResponseField>
