Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

fix(langgraph): prevent wrapping of ToolNode objects (#991)

Luka Aladashvili270c6ece2b9b
diff --git a/sdk/python/src/openlit/instrumentation/langgraph/langgraph.py b/sdk/python/src/openlit/instrumentation/langgraph/langgraph.py
index c66a4f24..a1c17714 100644
--- a/sdk/python/src/openlit/instrumentation/langgraph/langgraph.py
+++ b/sdk/python/src/openlit/instrumentation/langgraph/langgraph.py
@@ -515,7 +515,13 @@ def wrap_add_node(
# Wrap the action function
node_name = str(node_key) if not isinstance(node_key, str) else node_key
- wrapped_action = create_wrapped_node(action, node_name)
+
+ # FIX: Check if action is a function/routine.
+ # If it is a class instance (like ToolNode), do NOT wrap it.
+ if inspect.isroutine(action):
+ wrapped_action = create_wrapped_node(action, node_name)
+ else:
+ wrapped_action = action
# Call original add_node with wrapped action
if args and len(args) > 1: