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:
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

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

Any
Additional instrumentation configuration (currently unused).

Example

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

Any
Additional uninstrumentation configuration (currently unused).

Example

instrumentation_dependencies()

Returns the package dependencies required for this instrumentor.

Returns

A collection of package dependency strings.