Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

langgraph: fix issue w/ type annotations in tools_condition #2502

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions libs/langgraph/langgraph/prebuilt/tool_node.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from __future__ import annotations

import asyncio

Check notice on line 1 in libs/langgraph/langgraph/prebuilt/tool_node.py

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

......................................... fanout_to_subgraph_10x: Mean +- std dev: 62.4 ms +- 1.9 ms ......................................... fanout_to_subgraph_10x_sync: Mean +- std dev: 52.8 ms +- 1.2 ms ......................................... WARNING: the benchmark result may be unstable * the standard deviation (11.1 ms) is 11% of the mean (97.2 ms) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 97.2 ms +- 11.1 ms ......................................... fanout_to_subgraph_10x_checkpoint_sync: Mean +- std dev: 96.0 ms +- 1.4 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 673 ms +- 38 ms ......................................... fanout_to_subgraph_100x_sync: Mean +- std dev: 513 ms +- 8 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 1.06 sec +- 0.05 sec ......................................... fanout_to_subgraph_100x_checkpoint_sync: Mean +- std dev: 952 ms +- 25 ms ......................................... react_agent_10x: Mean +- std dev: 32.1 ms +- 1.0 ms ......................................... react_agent_10x_sync: Mean +- std dev: 23.1 ms +- 0.6 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 49.9 ms +- 1.9 ms ......................................... react_agent_10x_checkpoint_sync: Mean +- std dev: 38.2 ms +- 1.2 ms ......................................... react_agent_100x: Mean +- std dev: 358 ms +- 12 ms ......................................... react_agent_100x_sync: Mean +- std dev: 281 ms +- 8 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 1.01 sec +- 0.02 sec ......................................... react_agent_100x_checkpoint_sync: Mean +- std dev: 896 ms +- 20 ms ......................................... wide_state_25x300: Mean +- std dev: 24.6 ms +- 0.5 ms ......................................... wide_state_25x300_sync: Mean +- std dev: 15.7 ms +- 0.2 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 283 ms +- 5 ms ......................................... wide_state_25x300_checkpoint_sync: Mean +- std dev: 270 ms +- 4 ms ......................................... wide_state_15x600: Mean +- std dev: 28.3 ms +- 0.5 ms ......................................... wide_state_15x600_sync: Mean +- std dev: 18.2 ms +- 0.2 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 487 ms +- 6 ms ......................................... wide_state_15x600_checkpoint_sync: Mean +- std dev: 467 ms +- 5 ms ......................................... wide_state_9x1200: Mean +- std dev: 28.5 ms +- 0.5 ms ......................................... wide_state_9x1200_sync: Mean +- std dev: 18.1 ms +- 0.3 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 316 ms +- 3 ms ......................................... wide_state_9x1200_checkpoint_sync: Mean +- std dev: 301 ms +- 6 ms

Check notice on line 1 in libs/langgraph/langgraph/prebuilt/tool_node.py

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+-----------------------------------------+---------+------------------------+ | Benchmark | main | changes | +=========================================+=========+========================+ | wide_state_15x600 | 28.2 ms | 28.3 ms: 1.01x slower | +-----------------------------------------+---------+------------------------+ | wide_state_9x1200 | 28.3 ms | 28.5 ms: 1.01x slower | +-----------------------------------------+---------+------------------------+ | wide_state_9x1200_checkpoint_sync | 298 ms | 301 ms: 1.01x slower | +-----------------------------------------+---------+------------------------+ | wide_state_15x600_checkpoint | 481 ms | 487 ms: 1.01x slower | +-----------------------------------------+---------+------------------------+ | wide_state_9x1200_checkpoint | 312 ms | 316 ms: 1.01x slower | +-----------------------------------------+---------+------------------------+ | wide_state_25x300_checkpoint_sync | 266 ms | 270 ms: 1.01x slower | +-----------------------------------------+---------+------------------------+ | wide_state_9x1200_sync | 17.8 ms | 18.1 ms: 1.02x slower | +-----------------------------------------+---------+------------------------+ | wide_state_25x300_sync | 15.4 ms | 15.7 ms: 1.02x slower | +-----------------------------------------+---------+------------------------+ | wide_state_25x300 | 24.1 ms | 24.6 ms: 1.02x slower | +-----------------------------------------+---------+------------------------+ | wide_state_25x300_checkpoint | 278 ms | 283 ms: 1.02x slower | +-----------------------------------------+---------+------------------------+ | wide_state_15x600_sync | 17.8 ms | 18.2 ms: 1.02x slower | +-----------------------------------------+---------+------------------------+ | fanout_to_subgraph_10x | 61.2 ms | 62.4 ms: 1.02x slower | +-----------------------------------------+---------+------------------------+ | fanout_to_subgraph_10x_checkpoint_sync | 94.0 ms | 96.0 ms: 1.02x slower | +-----------------------------------------+---------+------------------------+ | fanout_to_subgraph_100x_sync | 500 ms | 513 ms: 1.03x slower | +-----------------------------------------+---------+------------------------+ | fanout_to_subgraph_10x_sync | 51.3 ms | 52.8 ms: 1.03x slower | +-----------------------------------------+---------+------------------------+ | fanout_to_subgraph_100x_checkpoint_sync | 925 ms | 952 ms: 1.03x slower | +-----------------------------------------+---------+------------------------+ | react_agent_10x_sync | 22.5 ms | 23.1 ms: 1.03x slower | +-----------------------------------------+---------+------------------------+ | react_agent_100x_sync | 271 ms | 281 ms: 1.04x slower | +-----------------------------------------+---------+------------------------+ | react_agent_10x | 30.9 ms | 32.1 ms: 1.04x slower | +-----------------------------------------+---------+------------------------+ | react_agent_10x_checkpoint_sync | 36.7 ms | 38.2 ms: 1.04x slower | +-----------------------------------------+---------+------------------------+ | react_agent_100x | 342 ms | 358 ms: 1.05x slower | +-----------------------------------------+---------+------------------------+ | fanout_to_subgraph_10x_checkpoint | 91.9 ms | 97.2 ms: 1.06x slower | +-----------------------------------------+---------+------------------------+ | react_agent_10x_checkpoint | 46.9 ms | 49.9 ms: 1.07x slower | +-----------------------------------------+---------+------------------------+ | react_agent_100x_checkpoint_sync | 841 ms | 896 ms: 1.07x slower | +-----------------------------------------+---------+------------------------+ | react_agent_100x_checkpoint | 941 ms | 1.01 sec: 1.0
import inspect
import json
from copy import copy
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Expand Down Expand Up @@ -35,15 +32,13 @@
from langchain_core.tools import BaseTool, InjectedToolArg
from langchain_core.tools import tool as create_tool
from langchain_core.tools.base import get_all_basemodel_annotations
from pydantic import BaseModel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we expect from pydantic.v1 import BaseModel to work?

from typing_extensions import Annotated, get_args, get_origin

from langgraph.errors import GraphInterrupt
from langgraph.store.base import BaseStore
from langgraph.utils.runnable import RunnableCallable

if TYPE_CHECKING:
from pydantic import BaseModel

INVALID_TOOL_NAME_ERROR_TEMPLATE = (
"Error: {requested_tool} is not a valid tool, try one of [{available_tools}]."
)
Expand Down
Loading