Skip to content

Commit 9240394

Browse files
jsonbaileyclaude
andcommitted
fix: Resolve mypy lint errors
- Use isinstance(gen, ChatGeneration) to type-narrow in callback handler - Declare model as Any to accommodate Runnable return type from bind_tools - Fix bind_kwargs type annotation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3110be6 commit 9240394

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

packages/ai-providers/server-ai-langchain/src/ldai_langchain/langgraph_agent_graph_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ def handle_traversal(node: AgentGraphNode, ctx: dict) -> None:
141141
handoff_fns.append(_make_handoff_tool(edge.target_config, description))
142142

143143
all_tools = tool_fns + handoff_fns
144+
model: Any
144145
if lc_model and all_tools:
145146
# When handoff tools are present, disable parallel tool calls so the LLM
146147
# picks exactly one destination rather than routing to multiple children.
147-
bind_kwargs = {'parallel_tool_calls': False} if handoff_fns else {}
148+
bind_kwargs: Dict[str, Any] = {'parallel_tool_calls': False} if handoff_fns else {}
148149
model = lc_model.bind_tools(all_tools, **bind_kwargs)
149150
else:
150151
model = lc_model

packages/ai-providers/server-ai-langchain/src/ldai_langchain/langgraph_callback_handler.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from uuid import UUID
44

55
from langchain_core.callbacks import BaseCallbackHandler
6-
from langchain_core.outputs import LLMResult
6+
from langchain_core.outputs import ChatGeneration, LLMResult
77
from ldai.agent_graph import AgentGraphDefinition
88
from ldai.tracker import TokenUsage
99

@@ -140,9 +140,12 @@ def on_llm_end(
140140
return
141141

142142
try:
143-
message = response.generations[0][0].message
144-
except (IndexError, AttributeError, TypeError):
143+
gen = response.generations[0][0]
144+
except (IndexError, TypeError):
145145
return
146+
if not isinstance(gen, ChatGeneration):
147+
return
148+
message = gen.message
146149
usage = get_ai_usage_from_response(message)
147150
if usage is None:
148151
return
@@ -215,4 +218,3 @@ def flush(self, graph: AgentGraphDefinition, graph_tracker: Any) -> None:
215218

216219
for tool_key in self._node_tool_calls.get(node_key, []):
217220
config_tracker.track_tool_call(tool_key, graph_key=gk)
218-

0 commit comments

Comments
 (0)