hyperpocket-langgraph 0.0.1__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.
@@ -1,17 +1,14 @@
1
1
  import copy
2
- from typing import List, Any
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
- from hyperpocket.server.server import PocketServerOperations
12
9
 
13
10
  try:
14
- from langchain_core.messages import AnyMessage, ToolMessage, AIMessage, RemoveMessage, SystemMessage
11
+ from langchain_core.messages import ToolMessage
15
12
  from langchain_core.tools import BaseTool, StructuredTool
16
13
  except ImportError:
17
14
  raise ImportError(
@@ -19,15 +16,13 @@ except ImportError:
19
16
  )
20
17
 
21
18
  try:
22
- from langgraph.constants import START, END
23
- from langgraph.graph import add_messages, StateGraph, MessagesState
24
- from langgraph.graph.state import CompiledStateGraph
19
+ from langgraph.graph import MessagesState
25
20
  except ImportError:
26
21
  raise ImportError(
27
22
  "You need to install langgraph to use pocket langgraph"
28
23
  )
29
24
 
30
- from hyperpocket import Pocket, PocketAuth
25
+ from hyperpocket import Pocket
31
26
  from hyperpocket.tool import Tool as PocketTool
32
27
 
33
28
 
@@ -36,20 +31,16 @@ class PocketLanggraphBaseState(MessagesState):
36
31
 
37
32
 
38
33
  class PocketLanggraph(Pocket):
39
- langgraph_tools: dict[str, BaseTool]
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()]
40
39
 
41
- def __init__(self,
42
- tools: List[ToolLike],
43
- auth: PocketAuth = None):
44
- super().__init__(tools, auth)
45
- self.langgraph_tools = {}
46
- for tool_name, tool_impl in self.tools.items():
47
- 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
48
43
 
49
- def get_tools(self):
50
- return [v for v in self.langgraph_tools.values()]
51
-
52
- def get_tool_node(self, should_interrupt: bool = False):
53
44
  async def _tool_node(state: PocketLanggraphBaseState, config: RunnableConfig) -> dict:
54
45
  thread_id = config.get("configurable", {}).get("thread_id", "default")
55
46
  last_message = state['messages'][-1]
@@ -66,12 +57,19 @@ class PocketLanggraph(Pocket):
66
57
  tool_call_id = _tool_call['id']
67
58
  tool_name = _tool_call['name']
68
59
  tool_args = _tool_call['args']
69
- body = tool_args.pop('body')
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
+
70
68
  if isinstance(body, BaseModel):
71
69
  body = body.model_dump()
72
70
 
73
71
  prepare = await self.prepare_in_subprocess(tool_name, body=body, thread_id=thread_id,
74
- profile=tool_args.get("profile", "default"))
72
+ profile=profile)
75
73
  need_prepare |= True if prepare else False
76
74
 
77
75
  if prepare is None:
@@ -101,13 +99,19 @@ class PocketLanggraph(Pocket):
101
99
  tool_call_id = _tool_call['id']
102
100
  tool_name = _tool_call['name']
103
101
  tool_args = _tool_call['args']
104
- body = tool_args.pop('body')
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
+
105
109
  if isinstance(body, BaseModel):
106
110
  body = body.model_dump()
107
111
 
108
112
  try:
109
113
  auth = await self.authenticate_in_subprocess(
110
- tool_name, body=body, thread_id=thread_id, profile=tool_args.get("profile", "default"))
114
+ tool_name, body=body, thread_id=thread_id, profile=profile)
111
115
  except Exception as e:
112
116
  pocket_logger.error(f"occur exception during authenticate. error : {e}")
113
117
  tool_messages.append(
@@ -133,79 +137,39 @@ class PocketLanggraph(Pocket):
133
137
 
134
138
  return _tool_node
135
139
 
136
- async def prepare_in_subprocess(self,
137
- tool_name: str,
138
- body: Any,
139
- thread_id: str = 'default',
140
- profile: str = 'default',
141
- *args, **kwargs):
142
- prepare = await self.server.call_in_subprocess(
143
- PocketServerOperations.PREPARE_AUTH,
144
- args,
145
- {
146
- 'tool_name': tool_name,
147
- 'body': body,
148
- 'thread_id': thread_id,
149
- 'profile': profile,
150
- **kwargs,
151
- },
152
- )
153
-
154
- return prepare
155
-
156
- async def authenticate_in_subprocess(self,
157
- tool_name: str,
158
- body: Any,
159
- thread_id: str = 'default',
160
- profile: str = 'default',
161
- *args, **kwargs):
162
- credentials = await self.server.call_in_subprocess(
163
- PocketServerOperations.AUTHENTICATE,
164
- args,
165
- {
166
- 'tool_name': tool_name,
167
- 'body': body,
168
- 'thread_id': thread_id,
169
- 'profile': profile,
170
- **kwargs,
171
- },
172
- )
173
-
174
- return credentials
175
-
176
- async def tool_call_in_subprocess(self,
177
- tool_name: str,
178
- body: Any,
179
- thread_id: str = 'default',
180
- profile: str = 'default',
181
- *args, **kwargs):
182
- result = await self.server.call_in_subprocess(
183
- PocketServerOperations.TOOL_CALL,
184
- args,
185
- {
186
- 'tool_name': tool_name,
187
- 'body': body,
188
- 'thread_id': thread_id,
189
- 'profile': profile,
190
- **kwargs,
191
- },
192
- )
193
-
194
- return result
195
-
196
140
  def _get_langgraph_tool(self, pocket_tool: PocketTool) -> BaseTool:
197
- def _invoke(body: Any, thread_id: str = 'default', profile: str = 'default', **kwargs) -> str:
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
+
198
151
  if isinstance(body, BaseModel):
199
152
  body = body.model_dump()
153
+
200
154
  result, interrupted = self.invoke_with_state(pocket_tool.name, body, thread_id, profile, **kwargs)
201
155
  say = result
202
156
  if interrupted:
203
157
  say = f'{say}\n\nThe tool execution interrupted. Please talk to me to resume.'
204
158
  return say
205
159
 
206
- async def _ainvoke(body: Any, thread_id: str = 'default', profile: str = 'default', **kwargs) -> str:
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
+
207
170
  if isinstance(body, BaseModel):
208
171
  body = body.model_dump()
172
+
209
173
  result, interrupted = await self.ainvoke_with_state(pocket_tool.name, body, thread_id, profile, **kwargs)
210
174
  say = result
211
175
  if interrupted:
@@ -216,6 +180,6 @@ class PocketLanggraph(Pocket):
216
180
  func=_invoke,
217
181
  coroutine=_ainvoke,
218
182
  name=pocket_tool.name,
219
- description=pocket_extended_tool_description(pocket_tool.description),
220
- 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),
221
185
  )
@@ -1,16 +1,10 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: hyperpocket-langgraph
3
- Version: 0.0.1
4
- Summary:
5
- Author: moon
6
- Author-email: moon@vessl.ai
7
- Requires-Python: >=3.11,<4.0
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.11
10
- Classifier: Programming Language :: Python :: 3.12
11
- Classifier: Programming Language :: Python :: 3.13
12
- Requires-Dist: hyperpocket (==0.0.3)
13
- Requires-Dist: langgraph (>=0.2.59,<0.3.0)
3
+ Version: 0.1.9
4
+ Author-email: Hyperpocket Team <hyperpocket@vessl.ai>
5
+ Requires-Python: >=3.10
6
+ Requires-Dist: hyperpocket>=0.0.3
7
+ Requires-Dist: langgraph>=0.2.59
14
8
  Description-Content-Type: text/markdown
15
9
 
16
10
  # Langgraph extensions
@@ -23,12 +17,13 @@ Description-Content-Type: text/markdown
23
17
  ## Get Pocket Subgraph
24
18
 
25
19
  ```python
26
- import hyperpocket as pk
27
- from pocket_langgraph import PocketLanggraph
20
+ from hyperpocket.tool import from_git
21
+
22
+ from hyperpocket_langgraph import PocketLanggraph
28
23
 
29
24
  pocket = PocketLanggraph(tools=[
30
- *pk.curated_tools.SLACK, # SLACK = [slack_get_message, slack_post_message, ..]
31
- *pk.curated_tools.LINEAR,
25
+ from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
26
+ from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
32
27
  "https://github.com/my-org/some-awesome-tool",
33
28
  ])
34
29
 
@@ -41,15 +36,14 @@ pocket_node = pocket.get_tool_node()
41
36
  ```python
42
37
  import os
43
38
 
39
+ from hyperpocket.tool import from_git
44
40
  from langchain_openai import ChatOpenAI
45
41
 
46
- import hyperpocket as pk
47
- from pocket_langgraph import PocketLanggraph
42
+ from hyperpocket_langgraph import PocketLanggraph
48
43
 
49
44
  pocket = PocketLanggraph(tools=[
50
- *pk.curated_tools.SLACK, # SLACK = [slack_get_message, slack_post_message, ..]
51
- *pk.curated_tools.LINEAR,
52
- "https://github.com/my-org/some-awesome-tool",
45
+ from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
46
+ from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
53
47
  ])
54
48
 
55
49
  # get tools from pocket to bind llm
@@ -66,6 +60,7 @@ llm_with_tools = llm.bind_tools(tools)
66
60
  import os
67
61
  from typing import Annotated
68
62
 
63
+ from hyperpocket.tool import from_git
69
64
  from langchain_core.runnables import RunnableConfig
70
65
  from langchain_openai import ChatOpenAI
71
66
  from langgraph.checkpoint.memory import MemorySaver
@@ -74,14 +69,12 @@ from langgraph.graph.message import add_messages
74
69
  from langgraph.prebuilt import tools_condition
75
70
  from typing_extensions import TypedDict
76
71
 
77
- import hyperpocket as pk
78
- from pocket_langgraph import PocketLanggraph
72
+ from hyperpocket_langgraph import PocketLanggraph
79
73
 
80
74
  # Define pocket tools
81
75
  pocket = PocketLanggraph(tools=[
82
- *pk.curated_tools.SLACK, # SLACK = [slack_get_message, slack_post_message, ..]
83
- *pk.curated_tools.LINEAR,
84
- "https://github.com/my-org/some-awesome-tool",
76
+ from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
77
+ from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
85
78
  ])
86
79
 
87
80
  # Get Pocket ToolNode
@@ -138,14 +131,14 @@ by setting the `should_interrupt` flag when calling `get_tool_node`
138
131
  Perform authentication in a multi-turn way
139
132
 
140
133
  ```python
141
- import hyperpocket as pk
142
- from pocket_langgraph import PocketLanggraph
134
+ from hyperpocket.tool import from_git
135
+
136
+ from hyperpocket_langgraph import PocketLanggraph
143
137
 
144
138
  # Define pocket tools
145
139
  pocket = PocketLanggraph(tools=[
146
- *pk.curated_tools.SLACK, # SLACK = [slack_get_message, slack_post_message, ..]
147
- *pk.curated_tools.LINEAR,
148
- "https://github.com/my-org/some-awesome-tool",
140
+ from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
141
+ from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
149
142
  ])
150
143
 
151
144
  # Get Pocket ToolNode
@@ -155,14 +148,14 @@ pocket_node = pocket.get_tool_node(should_interrupt=False) # multi turn
155
148
  ### Human-in-the-loop Auth
156
149
 
157
150
  ```python
158
- import hyperpocket as pk
159
- from pocket_langgraph import PocketLanggraph
151
+ from hyperpocket.tool import from_git
152
+
153
+ from hyperpocket_langgraph import PocketLanggraph
160
154
 
161
155
  # Define pocket tools
162
156
  pocket = PocketLanggraph(tools=[
163
- *pk.curated_tools.SLACK, # SLACK = [slack_get_message, slack_post_message, ..]
164
- *pk.curated_tools.LINEAR,
165
- "https://github.com/my-org/some-awesome-tool",
157
+ from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
158
+ from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
166
159
  ])
167
160
 
168
161
  # Get Pocket ToolNode
@@ -198,4 +191,3 @@ flow, there is a risk of incorrect decisions being made.
198
191
  Conversely, the human-in-the-loop approach eliminates this risk by always continuing the previous flow as it is,
199
192
  offering more predictable and controlled behavior for managing the auth flow.
200
193
 
201
-
@@ -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,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.1
2
+ Generator: hatchling 1.27.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,5 +0,0 @@
1
- hyperpocket_langgraph/__init__.py,sha256=0Az6FKsAvohOk8G4kUE99g6kyWz-Nf7dUuCuN3_pViY,97
2
- hyperpocket_langgraph/pocket_langgraph.py,sha256=SqXZDdqvOKX66f0rRI8Ol-rNkL66yIXLFlToyorMvMs,9176
3
- hyperpocket_langgraph-0.0.1.dist-info/METADATA,sha256=9zG8UMulVdv3cVcSMHiOXzauJov9Jldx44myu1PRQeg,5671
4
- hyperpocket_langgraph-0.0.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
5
- hyperpocket_langgraph-0.0.1.dist-info/RECORD,,