hyperpocket-langgraph 0.1.8__py3-none-any.whl → 0.1.9__py3-none-any.whl
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.
- hyperpocket_langgraph/pocket_langgraph.py +51 -24
- {hyperpocket_langgraph-0.1.8.dist-info → hyperpocket_langgraph-0.1.9.dist-info}/METADATA +2 -2
- hyperpocket_langgraph-0.1.9.dist-info/RECORD +5 -0
- hyperpocket_langgraph-0.1.8.dist-info/RECORD +0 -5
- {hyperpocket_langgraph-0.1.8.dist-info → hyperpocket_langgraph-0.1.9.dist-info}/WHEEL +0 -0
@@ -1,13 +1,11 @@
|
|
1
1
|
import copy
|
2
|
-
from typing import
|
2
|
+
from typing import Optional
|
3
3
|
|
4
4
|
from langchain_core.runnables import RunnableConfig
|
5
5
|
from langgraph.errors import NodeInterrupt
|
6
6
|
from pydantic import BaseModel
|
7
7
|
|
8
8
|
from hyperpocket.config import pocket_logger
|
9
|
-
from hyperpocket.pocket_main import ToolLike
|
10
|
-
from hyperpocket.prompts import pocket_extended_tool_description
|
11
9
|
|
12
10
|
try:
|
13
11
|
from langchain_core.messages import ToolMessage
|
@@ -24,7 +22,7 @@ except ImportError:
|
|
24
22
|
"You need to install langgraph to use pocket langgraph"
|
25
23
|
)
|
26
24
|
|
27
|
-
from hyperpocket import Pocket
|
25
|
+
from hyperpocket import Pocket
|
28
26
|
from hyperpocket.tool import Tool as PocketTool
|
29
27
|
|
30
28
|
|
@@ -33,20 +31,16 @@ class PocketLanggraphBaseState(MessagesState):
|
|
33
31
|
|
34
32
|
|
35
33
|
class PocketLanggraph(Pocket):
|
36
|
-
|
34
|
+
def get_tools(self, use_profile: Optional[bool] = None):
|
35
|
+
if use_profile is not None:
|
36
|
+
self.use_profile = use_profile
|
37
|
+
return [self._get_langgraph_tool(tool_impl) for tool_impl in
|
38
|
+
self.core.tools.values()]
|
37
39
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
super().__init__(tools, auth)
|
42
|
-
self.langgraph_tools = {}
|
43
|
-
for tool_name, tool_impl in self.core.tools.items():
|
44
|
-
self.langgraph_tools[tool_name] = self._get_langgraph_tool(tool_impl)
|
40
|
+
def get_tool_node(self, should_interrupt: bool = False, use_profile: Optional[bool] = None):
|
41
|
+
if use_profile is not None:
|
42
|
+
self.use_profile = use_profile
|
45
43
|
|
46
|
-
def get_tools(self):
|
47
|
-
return [v for v in self.langgraph_tools.values()]
|
48
|
-
|
49
|
-
def get_tool_node(self, should_interrupt: bool = False):
|
50
44
|
async def _tool_node(state: PocketLanggraphBaseState, config: RunnableConfig) -> dict:
|
51
45
|
thread_id = config.get("configurable", {}).get("thread_id", "default")
|
52
46
|
last_message = state['messages'][-1]
|
@@ -63,12 +57,19 @@ class PocketLanggraph(Pocket):
|
|
63
57
|
tool_call_id = _tool_call['id']
|
64
58
|
tool_name = _tool_call['name']
|
65
59
|
tool_args = _tool_call['args']
|
66
|
-
|
60
|
+
|
61
|
+
if self.use_profile:
|
62
|
+
body = tool_args.pop("body")
|
63
|
+
profile = tool_args.pop("profile", "default")
|
64
|
+
else:
|
65
|
+
body = tool_args
|
66
|
+
profile = "default"
|
67
|
+
|
67
68
|
if isinstance(body, BaseModel):
|
68
69
|
body = body.model_dump()
|
69
70
|
|
70
71
|
prepare = await self.prepare_in_subprocess(tool_name, body=body, thread_id=thread_id,
|
71
|
-
profile=
|
72
|
+
profile=profile)
|
72
73
|
need_prepare |= True if prepare else False
|
73
74
|
|
74
75
|
if prepare is None:
|
@@ -98,13 +99,19 @@ class PocketLanggraph(Pocket):
|
|
98
99
|
tool_call_id = _tool_call['id']
|
99
100
|
tool_name = _tool_call['name']
|
100
101
|
tool_args = _tool_call['args']
|
101
|
-
|
102
|
+
if self.use_profile:
|
103
|
+
body = tool_args.pop("body")
|
104
|
+
profile = tool_args.pop("profile", "default")
|
105
|
+
else:
|
106
|
+
body = tool_args
|
107
|
+
profile = "default"
|
108
|
+
|
102
109
|
if isinstance(body, BaseModel):
|
103
110
|
body = body.model_dump()
|
104
111
|
|
105
112
|
try:
|
106
113
|
auth = await self.authenticate_in_subprocess(
|
107
|
-
tool_name, body=body, thread_id=thread_id, profile=
|
114
|
+
tool_name, body=body, thread_id=thread_id, profile=profile)
|
108
115
|
except Exception as e:
|
109
116
|
pocket_logger.error(f"occur exception during authenticate. error : {e}")
|
110
117
|
tool_messages.append(
|
@@ -131,18 +138,38 @@ class PocketLanggraph(Pocket):
|
|
131
138
|
return _tool_node
|
132
139
|
|
133
140
|
def _get_langgraph_tool(self, pocket_tool: PocketTool) -> BaseTool:
|
134
|
-
def _invoke(
|
141
|
+
def _invoke(**kwargs) -> str:
|
142
|
+
if self.use_profile:
|
143
|
+
body = kwargs["body"]
|
144
|
+
thread_id = kwargs.pop("thread_id", "default")
|
145
|
+
profile = kwargs.pop("profile", "default")
|
146
|
+
else:
|
147
|
+
body = kwargs
|
148
|
+
thread_id = "default"
|
149
|
+
profile = "default"
|
150
|
+
|
135
151
|
if isinstance(body, BaseModel):
|
136
152
|
body = body.model_dump()
|
153
|
+
|
137
154
|
result, interrupted = self.invoke_with_state(pocket_tool.name, body, thread_id, profile, **kwargs)
|
138
155
|
say = result
|
139
156
|
if interrupted:
|
140
157
|
say = f'{say}\n\nThe tool execution interrupted. Please talk to me to resume.'
|
141
158
|
return say
|
142
159
|
|
143
|
-
async def _ainvoke(
|
160
|
+
async def _ainvoke(**kwargs) -> str:
|
161
|
+
if self.use_profile:
|
162
|
+
body = kwargs["body"]
|
163
|
+
thread_id = kwargs.pop("thread_id", "default")
|
164
|
+
profile = kwargs.pop("profile", "default")
|
165
|
+
else:
|
166
|
+
body = kwargs
|
167
|
+
thread_id = "default"
|
168
|
+
profile = "default"
|
169
|
+
|
144
170
|
if isinstance(body, BaseModel):
|
145
171
|
body = body.model_dump()
|
172
|
+
|
146
173
|
result, interrupted = await self.ainvoke_with_state(pocket_tool.name, body, thread_id, profile, **kwargs)
|
147
174
|
say = result
|
148
175
|
if interrupted:
|
@@ -153,6 +180,6 @@ class PocketLanggraph(Pocket):
|
|
153
180
|
func=_invoke,
|
154
181
|
coroutine=_ainvoke,
|
155
182
|
name=pocket_tool.name,
|
156
|
-
description=
|
157
|
-
args_schema=pocket_tool.schema_model(),
|
183
|
+
description=pocket_tool.get_description(use_profile=self.use_profile),
|
184
|
+
args_schema=pocket_tool.schema_model(use_profile=self.use_profile),
|
158
185
|
)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: hyperpocket-langgraph
|
3
|
-
Version: 0.1.
|
4
|
-
Author-email:
|
3
|
+
Version: 0.1.9
|
4
|
+
Author-email: Hyperpocket Team <hyperpocket@vessl.ai>
|
5
5
|
Requires-Python: >=3.10
|
6
6
|
Requires-Dist: hyperpocket>=0.0.3
|
7
7
|
Requires-Dist: langgraph>=0.2.59
|
@@ -0,0 +1,5 @@
|
|
1
|
+
hyperpocket_langgraph/__init__.py,sha256=0Az6FKsAvohOk8G4kUE99g6kyWz-Nf7dUuCuN3_pViY,97
|
2
|
+
hyperpocket_langgraph/pocket_langgraph.py,sha256=y8GT64UrcriVr36gAf5NbTSFfnefl3NrcGnzFKqz6qY,7540
|
3
|
+
hyperpocket_langgraph-0.1.9.dist-info/METADATA,sha256=mYL-Xfo7WLAqXv6tGz4C0tr5-FrGFR076Wzvckhqzk0,5846
|
4
|
+
hyperpocket_langgraph-0.1.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
+
hyperpocket_langgraph-0.1.9.dist-info/RECORD,,
|
@@ -1,5 +0,0 @@
|
|
1
|
-
hyperpocket_langgraph/__init__.py,sha256=0Az6FKsAvohOk8G4kUE99g6kyWz-Nf7dUuCuN3_pViY,97
|
2
|
-
hyperpocket_langgraph/pocket_langgraph.py,sha256=6_KfStimtuvW7W7TzyUWN4WJ5veybDgJv_bGCAtxOt4,6852
|
3
|
-
hyperpocket_langgraph-0.1.8.dist-info/METADATA,sha256=umosqoSEHq85vwsT7JiLfCMxAasNxLsvLFinxQ_sjeI,5827
|
4
|
-
hyperpocket_langgraph-0.1.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
-
hyperpocket_langgraph-0.1.8.dist-info/RECORD,,
|
File without changes
|