[X] I added a very descriptive title to this issue.
[X] I searched the LangChain documentation with the integrated search.
[X] I used the GitHub search to find a similar question and didn't find it.
[X] I am sure that this is a bug in LangChain rather than my code.
[X] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
from langchain_community.chat_models import ChatDatabricks
from langchain_community.tools.databricks import UCFunctionToolkit
def create_tool_calling_agent(
model: LanguageModelLike,
tools: Union[ToolExecutor, Sequence[BaseTool]],
agent_prompt: Optional[str] = None,
) -> CompiledGraph:
model = model.bind_tools(tools)
model_runnable = preprocessor | model
# Define the function that calls the model
def call_model(
state: AgentState,
config: RunnableConfig,
):
response = model_runnable.invoke(state, config)
return {"messages": [response]}
workflow = StateGraph(AgentState)
workflow.add_node("agent", RunnableLambda(call_model))
workflow.add_node("tools", ToolNode(tools))
workflow.set_entry_point("agent")
workflow.add_conditional_edges(
# First, we define the start node. We use agent.
# This means these are the edges taken after the agent node is called.
"agent",
# The mapping below will be used to determine which node to go to
{
# If tools, then we call the tool node.
"continue": "tools",
# END is a special node marking that the graph should finish.
"end": END,
},
)
# We now add a unconditional edge from tools to agent.
workflow.add_edge("tools", "agent")
return workflow.compile()
# Create the llm
llm = ChatDatabricks(endpoint="endpoint_id")
uc_functions = "function_names"
tools = (
UCFunctionToolkit(warehouse_id=config.get("warehouse_id"))
.include(*uc_functions)
.get_tools()
)
agent_with_raw_output = create_tool_calling_agent(llm, tools)
Error Message and Stack Trace (if applicable)
No response
Description
RunnableLambda uses the get_function_nonlocals in order to get the deps property.
get_function_nonlocalsusesinspect.getsource(func) to get the source code of the function in order to extract dependencies
However this call sometimes returns OS Error: Unable To get Source Code. This is causing the deps of RunnableLambda to be empty
In the event that inspect.getsource(func) fails can we still get the dependencies through the closure variables
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
No response
Description
get_function_nonlocals
in order to get thedeps
property.get_function_nonlocals
usesinspect.getsource(func)
to get the source code of the function in order to extract dependenciesOS Error: Unable To get Source Code
. This is causing the deps of RunnableLambda to be emptyinspect.getsource(func)
fails can we still get the dependencies through the closure variablesSystem Info