Skip to content

Commit 96847b9

Browse files
jsonbaileyclaude
andcommitted
fix(langchain): wrap tools with StructuredTool before bind_tools
Raw Python callables passed to bind_tools() lack the schema metadata required to generate a valid OpenAI tools[].function spec, causing a 400 "Missing required parameter: 'tools[0].function'" error. Wrapping each callable with StructuredTool.from_function(name=config_key) also ensures the model response carries the config key as the tool name, fixing a separate bug where function.__name__ was being tracked instead of the LaunchDarkly config key. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 56ce0fd commit 96847b9

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ async def run(self, input: Any) -> AgentGraphResult:
5353
start_ns = time.perf_counter_ns()
5454
try:
5555
from langchain_core.messages import AnyMessage, HumanMessage
56+
from langchain_core.tools import StructuredTool
5657
from langgraph.graph import END, START, StateGraph
5758
from typing_extensions import TypedDict
5859

@@ -74,11 +75,18 @@ def handle_traversal(node: AgentGraphNode, ctx: dict) -> None:
7475
if node_config.model:
7576
lc_model = create_langchain_model(node_config)
7677
tool_defs = node_config.model.get_parameter('tools') or []
77-
tool_fns = [
78-
tools_ref[t.get('name', '')]
79-
for t in tool_defs
80-
if t.get('name', '') in tools_ref
81-
]
78+
tool_fns = []
79+
for t in tool_defs:
80+
config_key = t.get('name', '')
81+
if config_key not in tools_ref:
82+
continue
83+
tool_fns.append(
84+
StructuredTool.from_function(
85+
func=tools_ref[config_key],
86+
name=config_key,
87+
description=t.get('description', ''),
88+
)
89+
)
8290
model = lc_model.bind_tools(tool_fns) if tool_fns else lc_model
8391

8492
def invoke(state: WorkflowState) -> WorkflowState:

0 commit comments

Comments
 (0)