Skip to main content
LangChain V1 middleware that instruments create_agent calls with Fiddler tracing. This middleware produces a clean, flat trace hierarchy for agents built with langchain.agents.create_agent:
  • One root Agent span (opened in before_agent, closed in after_agent)
  • One LLM child span per model invocation (wrap_model_call / awrap_model_call)
  • One Tool child span per tool invocation (wrap_tool_call / awrap_tool_call)
All spans are written to Fiddler’s isolated OpenTelemetry context so they do not interfere with any global tracer that may be active in the application. Concurrent invocations (async) are fully isolated: Python’s ContextVar ensures each agent.ainvoke() task tracks its own root span independently. Usage:
from langchain.agents import create_agent
from fiddler_otel import FiddlerClient
from fiddler_langchain import FiddlerAgentMiddleware

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

agent = create_agent(
    model="openai:gpt-4o-mini",
    tools=[...],
    middleware=[FiddlerAgentMiddleware(client=client, agent_name="my_agent")],
)
agent.invoke({"messages": [...]})

Parameters

client
FiddlerClient
required
The FiddlerClient instance.
agent_name
str
default:"\"agent\""
Label applied to the root Agent span. Defaults to "agent".

before_agent()

Opens a root Agent span at the start of each agent invocation. If the current context already has a Fiddler span (e.g. we are being invoked as a sub-agent from a tool call), the new agent span is created as a child of that span so the full multi-agent flow appears in a single trace.

Returns

dict[str, Any] | None

after_agent()

Closes the root Agent span at the end of each agent invocation.

Returns

dict[str, Any] | None

wrap_model_call()

Wraps a synchronous model call with an LLM span.

Returns

ModelResponse

async awrap_model_call()

Wraps an asynchronous model call with an LLM span.

Returns

ModelResponse

wrap_tool_call()

Wraps a synchronous tool call with a Tool span.

Returns

Any

async awrap_tool_call()

Wraps an asynchronous tool call with a Tool span.

Returns

Any