langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
94.95k stars 15.38k forks source link

RunnableLambda Deps not Extracted Properly #27970

Open aravind-segu opened 1 week ago

aravind-segu commented 1 week ago

Checked other resources

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

System Info

System Information
------------------
> OS:  Darwin
> OS Version:  Darwin Kernel Version 23.6.0: Thu Sep 12 23:36:12 PDT 2024; root:xnu-10063.141.1.701.1~1/RELEASE_ARM64_T6020
> Python Version:  3.10.14 (main, May  6 2024, 14:42:37) [Clang 14.0.6 ]

Package Information
-------------------
> langchain_core: 0.2.41
> langchain: 0.2.16
> langchain_community: 0.2.17
> langsmith: 0.1.135
> langchain_databricks: 0.1.0
> langchain_experimental: 0.0.65
> langchain_huggingface: 0.0.3
> langchain_openai: 0.1.25
> langchain_text_splitters: 0.2.4
> langgraph: 0.2.37

Optional packages not installed
-------------------------------
> langserve

Other Dependencies
------------------
> aiohttp: 3.10.10
> async-timeout: 4.0.3
> databricks-vectorsearch: 0.40
> dataclasses-json: 0.6.7
> httpx: 0.27.2
> huggingface-hub: 0.25.2
> jsonpatch: 1.33
> langgraph-checkpoint: 2.0.1
> langgraph-sdk: 0.1.33
> mlflow: 2.16.1.dev0
> numpy: 1.26.4
> openai: 1.51.2
> orjson: 3.10.7
> packaging: 24.1
> pydantic: 2.9.2
> PyYAML: 6.0.2
> requests: 2.32.3
> requests-toolbelt: 1.0.0
> scipy: 1.14.1
> sentence-transformers: 3.2.0
> SQLAlchemy: 2.0.35
> tenacity: 8.5.0
> tiktoken: 0.8.0
> tokenizers: 0.20.1
> transformers: 4.45.2
> typing-extensions: 4.12.2
Harsimran-19 commented 1 week ago

Can I work on this issue?