langgraph-prebuilt 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/PKG-INFO +1 -1
  2. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/langgraph/prebuilt/chat_agent_executor.py +14 -5
  3. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/pyproject.toml +1 -1
  4. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/test_react_agent.py +60 -0
  5. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/uv.lock +2 -2
  6. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/.gitignore +0 -0
  7. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/LICENSE +0 -0
  8. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/Makefile +0 -0
  9. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/README.md +0 -0
  10. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/langgraph/prebuilt/__init__.py +0 -0
  11. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/langgraph/prebuilt/interrupt.py +0 -0
  12. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/langgraph/prebuilt/py.typed +0 -0
  13. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/langgraph/prebuilt/tool_node.py +0 -0
  14. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/langgraph/prebuilt/tool_validator.py +0 -0
  15. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/__init__.py +0 -0
  16. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/__snapshots__/test_react_agent_graph.ambr +0 -0
  17. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/any_str.py +0 -0
  18. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/compose-postgres.yml +0 -0
  19. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/conftest.py +0 -0
  20. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/conftest_checkpointer.py +0 -0
  21. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/conftest_store.py +0 -0
  22. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/memory_assert.py +0 -0
  23. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/messages.py +0 -0
  24. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/model.py +0 -0
  25. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/test_react_agent_graph.py +0 -0
  26. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/test_tool_node.py +0 -0
  27. {langgraph_prebuilt-0.2.0 → langgraph_prebuilt-0.2.2}/tests/test_validation_node.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langgraph-prebuilt
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Library with high-level APIs for creating and executing LangGraph agents and tools.
5
5
  Project-URL: Repository, https://www.github.com/langchain-ai/langgraph
6
6
  License-Expression: MIT
@@ -240,7 +240,7 @@ def _validate_chat_history(
240
240
 
241
241
  def create_react_agent(
242
242
  model: Union[str, LanguageModelLike],
243
- tools: Union[Sequence[Union[BaseTool, Callable]], ToolNode],
243
+ tools: Union[Sequence[Union[BaseTool, Callable, dict[str, Any]]], ToolNode],
244
244
  *,
245
245
  prompt: Optional[Prompt] = None,
246
246
  response_format: Optional[
@@ -420,12 +420,13 @@ def create_react_agent(
420
420
  else AgentState
421
421
  )
422
422
 
423
+ llm_builtin_tools: list[dict] = []
423
424
  if isinstance(tools, ToolNode):
424
425
  tool_classes = list(tools.tools_by_name.values())
425
426
  tool_node = tools
426
427
  else:
427
- tool_node = ToolNode(tools)
428
- # get the tool functions wrapped in a tool class from the ToolNode
428
+ llm_builtin_tools = [t for t in tools if isinstance(t, dict)]
429
+ tool_node = ToolNode([t for t in tools if not isinstance(t, dict)])
429
430
  tool_classes = list(tool_node.tools_by_name.values())
430
431
 
431
432
  if isinstance(model, str):
@@ -442,8 +443,12 @@ def create_react_agent(
442
443
 
443
444
  tool_calling_enabled = len(tool_classes) > 0
444
445
 
445
- if _should_bind_tools(model, tool_classes) and tool_calling_enabled:
446
- model = cast(BaseChatModel, model).bind_tools(tool_classes)
446
+ if (
447
+ _should_bind_tools(model, tool_classes)
448
+ and len(tool_classes) > 0
449
+ or (len(llm_builtin_tools) > 0)
450
+ ):
451
+ model = cast(BaseChatModel, model).bind_tools(tool_classes + llm_builtin_tools) # type: ignore[operator]
447
452
 
448
453
  model_runnable = _get_prompt_runnable(prompt) | model
449
454
 
@@ -722,6 +727,10 @@ def create_react_agent(
722
727
  ]
723
728
 
724
729
  if pending_tool_calls:
730
+ pending_tool_calls = [
731
+ tool_node.inject_tool_args(call, state, store) # type: ignore[arg-type]
732
+ for call in pending_tool_calls
733
+ ]
725
734
  return [Send("tools", [tool_call]) for tool_call in pending_tool_calls]
726
735
  elif isinstance(messages[-1], ToolMessage):
727
736
  return entrypoint
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "langgraph-prebuilt"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  description = "Library with high-level APIs for creating and executing LangGraph agents and tools."
9
9
  authors = []
10
10
  requires-python = ">=3.9"
@@ -1540,3 +1540,63 @@ def test_post_model_hook_with_structured_output() -> None:
1540
1540
  }
1541
1541
  },
1542
1542
  ]
1543
+
1544
+
1545
+ @pytest.mark.parametrize(
1546
+ "state_schema", [AgentStateExtraKey, AgentStateExtraKeyPydantic]
1547
+ )
1548
+ def test_create_react_agent_inject_vars_with_post_model_hook(
1549
+ state_schema: StateSchemaType,
1550
+ ) -> None:
1551
+ store = InMemoryStore()
1552
+ namespace = ("test",)
1553
+ store.put(namespace, "test_key", {"bar": 3})
1554
+
1555
+ if issubclass(state_schema, AgentStatePydantic):
1556
+
1557
+ def tool1(
1558
+ some_val: int,
1559
+ state: Annotated[AgentStateExtraKeyPydantic, InjectedState],
1560
+ store: Annotated[BaseStore, InjectedStore()],
1561
+ ) -> str:
1562
+ """Tool 1 docstring."""
1563
+ store_val = store.get(namespace, "test_key").value["bar"]
1564
+ return some_val + state.foo + store_val
1565
+ else:
1566
+
1567
+ def tool1(
1568
+ some_val: int,
1569
+ state: Annotated[dict, InjectedState],
1570
+ store: Annotated[BaseStore, InjectedStore()],
1571
+ ) -> str:
1572
+ """Tool 1 docstring."""
1573
+ store_val = store.get(namespace, "test_key").value["bar"]
1574
+ return some_val + state["foo"] + store_val
1575
+
1576
+ tool_call = {
1577
+ "name": "tool1",
1578
+ "args": {"some_val": 1},
1579
+ "id": "some 0",
1580
+ "type": "tool_call",
1581
+ }
1582
+
1583
+ def post_model_hook(state: dict) -> None:
1584
+ return
1585
+
1586
+ model = FakeToolCallingModel(tool_calls=[[tool_call], []])
1587
+ agent = create_react_agent(
1588
+ model,
1589
+ [tool1],
1590
+ state_schema=state_schema,
1591
+ store=store,
1592
+ post_model_hook=post_model_hook,
1593
+ )
1594
+ input_message = HumanMessage("hi")
1595
+ result = agent.invoke({"messages": [input_message], "foo": 2})
1596
+ assert result["messages"] == [
1597
+ input_message,
1598
+ AIMessage(content="hi", tool_calls=[tool_call], id="0"),
1599
+ _AnyIdToolMessage(content="6", name="tool1", tool_call_id="some 0"),
1600
+ AIMessage("hi-hi-6", id="1"),
1601
+ ]
1602
+ assert result["foo"] == 2
@@ -320,7 +320,7 @@ wheels = [
320
320
 
321
321
  [[package]]
322
322
  name = "langgraph"
323
- version = "0.4.5"
323
+ version = "0.4.7"
324
324
  source = { editable = "../langgraph" }
325
325
  dependencies = [
326
326
  { name = "langchain-core" },
@@ -461,7 +461,7 @@ dev = [
461
461
 
462
462
  [[package]]
463
463
  name = "langgraph-prebuilt"
464
- version = "0.2.0"
464
+ version = "0.2.2"
465
465
  source = { editable = "." }
466
466
  dependencies = [
467
467
  { name = "langchain-core" },