Skip to content

Commit 1d6ca57

Browse files
fix: langchain on_chain_start with_kwargs name and serialised is none
1 parent 12ad78c commit 1d6ca57

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/galileo/handlers/langchain/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def on_chain_start(
262262
) -> Any:
263263
"""Langchain callback when a chain starts."""
264264
node_type = "chain"
265-
node_name = self._get_node_name(node_type, serialized)
265+
node_name = self._get_node_name(node_type, serialized) if serialized else kwargs.get("name", "Chain")
266266

267267
# If the `name` is `LangGraph` or `Agent`, set the node type to `agent`.
268268
if node_name in ["LangGraph", "Agent"]:

tests/test_langchain.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,46 @@ def test_on_chain_start_end(self, callback: GalileoCallback, galileo_logger: Gal
126126
assert traces[0].spans[0].input == '{"query": "test question"}'
127127
assert traces[0].spans[0].output == '{"result": "test answer"}'
128128

129+
def test_on_chain_start_with_kwargs_serialised_none(self, callback: GalileoCallback, galileo_logger: GalileoLogger):
130+
run_id = uuid.uuid4()
131+
132+
# Start chain
133+
callback.on_chain_start(
134+
serialized=None,
135+
inputs={
136+
"messages": [
137+
HumanMessage(
138+
content="What does Lilian Weng say about the types of agent memory?",
139+
additional_kwargs={},
140+
response_metadata={},
141+
)
142+
]
143+
},
144+
run_id=run_id,
145+
name="LangGraph",
146+
)
147+
148+
assert str(run_id) in callback._nodes
149+
assert callback._nodes[str(run_id)].node_type == "agent"
150+
assert (
151+
callback._nodes[str(run_id)].span_params["input"]
152+
== '{"messages": [{"content": "What does Lilian Weng say about the types of agent memory?"}]}'
153+
)
154+
155+
# End chain
156+
callback.on_chain_end(outputs='{"result": "test answer"}', run_id=run_id)
157+
158+
traces = galileo_logger.traces
159+
assert len(traces) == 1
160+
assert len(traces[0].spans) == 1
161+
assert traces[0].spans[0].name == "Agent"
162+
assert traces[0].spans[0].type == "workflow"
163+
assert (
164+
traces[0].spans[0].input
165+
== '{"messages": [{"content": "What does Lilian Weng say about the types of agent memory?"}]}'
166+
)
167+
assert traces[0].spans[0].output == '{"result": "test answer"}'
168+
129169
def test_on_agent_chain(self, callback: GalileoCallback, galileo_logger: GalileoLogger):
130170
"""Test agent chain handling"""
131171
run_id = uuid.uuid4()

0 commit comments

Comments
 (0)