langgraph-prebuilt 0.1.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 LangChain, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.1
2
+ Name: langgraph-prebuilt
3
+ Version: 0.1.0
4
+ Summary: Library with high-level APIs for creating and executing LangGraph agents and tools.
5
+ Home-page: https://www.github.com/langchain-ai/langgraph
6
+ License: MIT
7
+ Requires-Python: >=3.9.0,<4.0.0
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Dist: langchain-core (>=0.2.43,<0.4.0,!=0.3.0,!=0.3.1,!=0.3.2,!=0.3.3,!=0.3.4,!=0.3.5,!=0.3.6,!=0.3.7,!=0.3.8,!=0.3.9,!=0.3.10,!=0.3.11,!=0.3.12,!=0.3.13,!=0.3.14,!=0.3.15,!=0.3.16,!=0.3.17,!=0.3.18,!=0.3.19,!=0.3.20,!=0.3.21,!=0.3.22)
15
+ Requires-Dist: langgraph (>=0.3,<0.4)
16
+ Requires-Dist: langgraph-checkpoint (>=2.0.10,<3.0.0)
17
+ Project-URL: Repository, https://www.github.com/langchain-ai/langgraph
18
+ Description-Content-Type: text/markdown
19
+
20
+ # LangGraph Prebuilt
21
+
22
+ This library defines high-level APIs for creating and executing LangGraph agents and tools.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install langgraph-prebuilt
28
+ ```
29
+
30
+ ## Agents
31
+
32
+ `langgraph-prebuilt` provides an [implementation](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.chat_agent_executor.create_react_agent) of a tool-calling [ReAct-style](https://langchain-ai.github.io/langgraph/concepts/agentic_concepts/#react-implementation) agent - `create_react_agent`:
33
+
34
+ ```bash
35
+ pip install langchain-anthropic
36
+ ```
37
+
38
+ ```python
39
+ from langchain_anthropic import ChatAnthropic
40
+ from langgraph.prebuilt import create_react_agent
41
+
42
+ # Define the tools for the agent to use
43
+ def search(query: str):
44
+ """Call to surf the web."""
45
+ # This is a placeholder, but don't tell the LLM that...
46
+ if "sf" in query.lower() or "san francisco" in query.lower():
47
+ return "It's 60 degrees and foggy."
48
+ return "It's 90 degrees and sunny."
49
+
50
+ tools = [search]
51
+ model = ChatAnthropic(model="claude-3-7-sonnet-latest")
52
+
53
+ app = create_react_agent(model, tools)
54
+ # run the agent
55
+ app.invoke(
56
+ {"messages": [{"role": "user", "content": "what is the weather in sf"}]},
57
+ )
58
+ ```
59
+
60
+ ## Tools
61
+
62
+ ### ToolNode
63
+
64
+ `langgraph-prebuilt` provides an [implementation](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.tool_node.ToolNode) of a node that executes tool calls - `ToolNode`:
65
+
66
+ ```python
67
+ from langgraph.prebuilt import ToolNode
68
+ from langchain_core.messages import AIMessage
69
+
70
+ def search(query: str):
71
+ """Call to surf the web."""
72
+ # This is a placeholder, but don't tell the LLM that...
73
+ if "sf" in query.lower() or "san francisco" in query.lower():
74
+ return "It's 60 degrees and foggy."
75
+ return "It's 90 degrees and sunny."
76
+
77
+ tool_node = ToolNode([search])
78
+ tool_calls = [{"name": "search", "args": {"query": "what is the weather in sf"}, "id": "1"}]
79
+ ai_message = AIMessage(content="", tool_calls=tool_calls)
80
+ # execute tool call
81
+ tool_node.invoke({"messages": [ai_message]})
82
+ ```
83
+
84
+ ### ValidationNode
85
+
86
+ `langgraph-prebuilt` provides an [implementation](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.tool_validator.ValidationNode) of a node that validates tool calls against a pydantic schema - `ValidationNode`:
87
+
88
+ ```python
89
+ from pydantic import BaseModel, field_validator
90
+ from langgraph.prebuilt import ValidationNode
91
+ from langchain_core.messages import AIMessage
92
+
93
+
94
+ class SelectNumber(BaseModel):
95
+ a: int
96
+
97
+ @field_validator("a")
98
+ def a_must_be_meaningful(cls, v):
99
+ if v != 37:
100
+ raise ValueError("Only 37 is allowed")
101
+ return v
102
+
103
+ validation_node = ValidationNode([SelectNumber])
104
+ validation_node.invoke({
105
+ "messages": [AIMessage("", tool_calls=[{"name": "SelectNumber", "args": {"a": 42}, "id": "1"}])]
106
+ })
107
+ ```
108
+
109
+ ## Agent Inbox
110
+
111
+ The library contains schemas for using the [Agent Inbox](https://github.com/langchain-ai/agent-inbox) with LangGraph agents. Learn more about how to use Agent Inbox [here](https://github.com/langchain-ai/agent-inbox#interrupts).
112
+
113
+ ```python
114
+ from langgraph.types import interrupt
115
+ from langgraph.prebuilt.interrupt import HumanInterrupt, HumanResponse
116
+
117
+ def my_graph_function():
118
+ # Extract the last tool call from the `messages` field in the state
119
+ tool_call = state["messages"][-1].tool_calls[0]
120
+ # Create an interrupt
121
+ request: HumanInterrupt = {
122
+ "action_request": {
123
+ "action": tool_call['name'],
124
+ "args": tool_call['args']
125
+ },
126
+ "config": {
127
+ "allow_ignore": True,
128
+ "allow_respond": True,
129
+ "allow_edit": False,
130
+ "allow_accept": False
131
+ },
132
+ "description": _generate_email_markdown(state) # Generate a detailed markdown description.
133
+ }
134
+ # Send the interrupt request inside a list, and extract the first response
135
+ response = interrupt([request])[0]
136
+ if response['type'] == "response":
137
+ # Do something with the response
138
+ ...
139
+ ```
@@ -0,0 +1,120 @@
1
+ # LangGraph Prebuilt
2
+
3
+ This library defines high-level APIs for creating and executing LangGraph agents and tools.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install langgraph-prebuilt
9
+ ```
10
+
11
+ ## Agents
12
+
13
+ `langgraph-prebuilt` provides an [implementation](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.chat_agent_executor.create_react_agent) of a tool-calling [ReAct-style](https://langchain-ai.github.io/langgraph/concepts/agentic_concepts/#react-implementation) agent - `create_react_agent`:
14
+
15
+ ```bash
16
+ pip install langchain-anthropic
17
+ ```
18
+
19
+ ```python
20
+ from langchain_anthropic import ChatAnthropic
21
+ from langgraph.prebuilt import create_react_agent
22
+
23
+ # Define the tools for the agent to use
24
+ def search(query: str):
25
+ """Call to surf the web."""
26
+ # This is a placeholder, but don't tell the LLM that...
27
+ if "sf" in query.lower() or "san francisco" in query.lower():
28
+ return "It's 60 degrees and foggy."
29
+ return "It's 90 degrees and sunny."
30
+
31
+ tools = [search]
32
+ model = ChatAnthropic(model="claude-3-7-sonnet-latest")
33
+
34
+ app = create_react_agent(model, tools)
35
+ # run the agent
36
+ app.invoke(
37
+ {"messages": [{"role": "user", "content": "what is the weather in sf"}]},
38
+ )
39
+ ```
40
+
41
+ ## Tools
42
+
43
+ ### ToolNode
44
+
45
+ `langgraph-prebuilt` provides an [implementation](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.tool_node.ToolNode) of a node that executes tool calls - `ToolNode`:
46
+
47
+ ```python
48
+ from langgraph.prebuilt import ToolNode
49
+ from langchain_core.messages import AIMessage
50
+
51
+ def search(query: str):
52
+ """Call to surf the web."""
53
+ # This is a placeholder, but don't tell the LLM that...
54
+ if "sf" in query.lower() or "san francisco" in query.lower():
55
+ return "It's 60 degrees and foggy."
56
+ return "It's 90 degrees and sunny."
57
+
58
+ tool_node = ToolNode([search])
59
+ tool_calls = [{"name": "search", "args": {"query": "what is the weather in sf"}, "id": "1"}]
60
+ ai_message = AIMessage(content="", tool_calls=tool_calls)
61
+ # execute tool call
62
+ tool_node.invoke({"messages": [ai_message]})
63
+ ```
64
+
65
+ ### ValidationNode
66
+
67
+ `langgraph-prebuilt` provides an [implementation](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.tool_validator.ValidationNode) of a node that validates tool calls against a pydantic schema - `ValidationNode`:
68
+
69
+ ```python
70
+ from pydantic import BaseModel, field_validator
71
+ from langgraph.prebuilt import ValidationNode
72
+ from langchain_core.messages import AIMessage
73
+
74
+
75
+ class SelectNumber(BaseModel):
76
+ a: int
77
+
78
+ @field_validator("a")
79
+ def a_must_be_meaningful(cls, v):
80
+ if v != 37:
81
+ raise ValueError("Only 37 is allowed")
82
+ return v
83
+
84
+ validation_node = ValidationNode([SelectNumber])
85
+ validation_node.invoke({
86
+ "messages": [AIMessage("", tool_calls=[{"name": "SelectNumber", "args": {"a": 42}, "id": "1"}])]
87
+ })
88
+ ```
89
+
90
+ ## Agent Inbox
91
+
92
+ The library contains schemas for using the [Agent Inbox](https://github.com/langchain-ai/agent-inbox) with LangGraph agents. Learn more about how to use Agent Inbox [here](https://github.com/langchain-ai/agent-inbox#interrupts).
93
+
94
+ ```python
95
+ from langgraph.types import interrupt
96
+ from langgraph.prebuilt.interrupt import HumanInterrupt, HumanResponse
97
+
98
+ def my_graph_function():
99
+ # Extract the last tool call from the `messages` field in the state
100
+ tool_call = state["messages"][-1].tool_calls[0]
101
+ # Create an interrupt
102
+ request: HumanInterrupt = {
103
+ "action_request": {
104
+ "action": tool_call['name'],
105
+ "args": tool_call['args']
106
+ },
107
+ "config": {
108
+ "allow_ignore": True,
109
+ "allow_respond": True,
110
+ "allow_edit": False,
111
+ "allow_accept": False
112
+ },
113
+ "description": _generate_email_markdown(state) # Generate a detailed markdown description.
114
+ }
115
+ # Send the interrupt request inside a list, and extract the first response
116
+ response = interrupt([request])[0]
117
+ if response['type'] == "response":
118
+ # Do something with the response
119
+ ...
120
+ ```
@@ -0,0 +1,19 @@
1
+ """langgraph.prebuilt exposes a higher-level API for creating and executing agents and tools."""
2
+
3
+ from langgraph.prebuilt.chat_agent_executor import create_react_agent
4
+ from langgraph.prebuilt.tool_node import (
5
+ InjectedState,
6
+ InjectedStore,
7
+ ToolNode,
8
+ tools_condition,
9
+ )
10
+ from langgraph.prebuilt.tool_validator import ValidationNode
11
+
12
+ __all__ = [
13
+ "create_react_agent",
14
+ "ToolNode",
15
+ "tools_condition",
16
+ "ValidationNode",
17
+ "InjectedState",
18
+ "InjectedStore",
19
+ ]