hyperpocket-langgraph 0.0.1__tar.gz → 0.1.9__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- hyperpocket_langgraph-0.1.9/.gitignore +157 -0
- {hyperpocket_langgraph-0.0.1 → hyperpocket_langgraph-0.1.9}/PKG-INFO +29 -37
- {hyperpocket_langgraph-0.0.1 → hyperpocket_langgraph-0.1.9}/README.md +23 -24
- hyperpocket_langgraph-0.1.9/__init__.py +0 -0
- {hyperpocket_langgraph-0.0.1 → hyperpocket_langgraph-0.1.9}/hyperpocket_langgraph/pocket_langgraph.py +53 -89
- hyperpocket_langgraph-0.1.9/pyproject.toml +42 -0
- hyperpocket_langgraph-0.1.9/tests/__init__.py +0 -0
- hyperpocket_langgraph-0.1.9/tests/test_pocket_langgraph_no_profile.py +130 -0
- hyperpocket_langgraph-0.1.9/tests/test_pocket_langgraph_use_profile.py +130 -0
- hyperpocket_langgraph-0.1.9/uv.lock +1511 -0
- hyperpocket_langgraph-0.0.1/pyproject.toml +0 -19
- {hyperpocket_langgraph-0.0.1 → hyperpocket_langgraph-0.1.9}/hyperpocket_langgraph/__init__.py +0 -0
@@ -0,0 +1,157 @@
|
|
1
|
+
.vs/
|
2
|
+
.vscode/
|
3
|
+
.idea/
|
4
|
+
# Byte-compiled / optimized / DLL files
|
5
|
+
__pycache__/
|
6
|
+
*.py[cod]
|
7
|
+
*$py.class
|
8
|
+
|
9
|
+
# C extensions
|
10
|
+
*.so
|
11
|
+
|
12
|
+
# Distribution / packaging
|
13
|
+
.Python
|
14
|
+
build/
|
15
|
+
develop-eggs/
|
16
|
+
dist/
|
17
|
+
downloads/
|
18
|
+
eggs/
|
19
|
+
.eggs/
|
20
|
+
lib/
|
21
|
+
lib64/
|
22
|
+
parts/
|
23
|
+
sdist/
|
24
|
+
var/
|
25
|
+
wheels/
|
26
|
+
pip-wheel-metadata/
|
27
|
+
share/python-wheels/
|
28
|
+
*.egg-info/
|
29
|
+
.installed.cfg
|
30
|
+
*.egg
|
31
|
+
MANIFEST
|
32
|
+
|
33
|
+
# Google GitHub Actions credentials files created by:
|
34
|
+
# https://github.com/google-github-actions/auth
|
35
|
+
#
|
36
|
+
# That action recommends adding this gitignore to prevent accidentally committing keys.
|
37
|
+
gha-creds-*.json
|
38
|
+
|
39
|
+
# PyInstaller
|
40
|
+
# Usually these files are written by a python script from a template
|
41
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
42
|
+
*.manifest
|
43
|
+
*.spec
|
44
|
+
|
45
|
+
# Unit test / coverage reports
|
46
|
+
htmlcov/
|
47
|
+
.tox/
|
48
|
+
.nox/
|
49
|
+
.coverage
|
50
|
+
.coverage.*
|
51
|
+
.cache
|
52
|
+
nosetests.xml
|
53
|
+
coverage.xml
|
54
|
+
*.cover
|
55
|
+
*.py,cover
|
56
|
+
.hypothesis/
|
57
|
+
.pytest_cache/
|
58
|
+
|
59
|
+
# Translations
|
60
|
+
*.mo
|
61
|
+
*.pot
|
62
|
+
|
63
|
+
# Django stuff:
|
64
|
+
*.log
|
65
|
+
local_settings.py
|
66
|
+
db.sqlite3
|
67
|
+
db.sqlite3-journal
|
68
|
+
|
69
|
+
# Flask stuff:
|
70
|
+
instance/
|
71
|
+
.webassets-cache
|
72
|
+
|
73
|
+
# Scrapy stuff:
|
74
|
+
.scrapy
|
75
|
+
|
76
|
+
|
77
|
+
# Jupyter Notebook
|
78
|
+
.ipynb_checkpoints
|
79
|
+
notebooks/
|
80
|
+
|
81
|
+
# IPython
|
82
|
+
profile_default/
|
83
|
+
ipython_config.py
|
84
|
+
|
85
|
+
# pyenv
|
86
|
+
.python-version
|
87
|
+
|
88
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
89
|
+
__pypackages__/
|
90
|
+
|
91
|
+
# Celery stuff
|
92
|
+
celerybeat-schedule
|
93
|
+
celerybeat.pid
|
94
|
+
|
95
|
+
# SageMath parsed files
|
96
|
+
*.sage.py
|
97
|
+
|
98
|
+
# Environments
|
99
|
+
.env
|
100
|
+
.envrc
|
101
|
+
.venv*
|
102
|
+
venv*
|
103
|
+
env/
|
104
|
+
ENV/
|
105
|
+
env.bak/
|
106
|
+
|
107
|
+
# Spyder project settings
|
108
|
+
.spyderproject
|
109
|
+
.spyproject
|
110
|
+
|
111
|
+
# Rope project settings
|
112
|
+
.ropeproject
|
113
|
+
|
114
|
+
# mkdocs documentation
|
115
|
+
/site
|
116
|
+
|
117
|
+
# mypy
|
118
|
+
.mypy_cache/
|
119
|
+
.mypy_cache_test/
|
120
|
+
.dmypy.json
|
121
|
+
dmypy.json
|
122
|
+
|
123
|
+
# Pyre type checker
|
124
|
+
.pyre/
|
125
|
+
|
126
|
+
# macOS display setting files
|
127
|
+
.DS_Store
|
128
|
+
|
129
|
+
# Wandb directory
|
130
|
+
wandb/
|
131
|
+
|
132
|
+
# asdf tool versions
|
133
|
+
.tool-versions
|
134
|
+
/.ruff_cache/
|
135
|
+
|
136
|
+
*.pkl
|
137
|
+
*.bin
|
138
|
+
|
139
|
+
# integration test artifacts
|
140
|
+
data_map*
|
141
|
+
\[('_type', 'fake'), ('stop', None)]
|
142
|
+
|
143
|
+
# Replit files
|
144
|
+
*replit*
|
145
|
+
|
146
|
+
|
147
|
+
prof
|
148
|
+
virtualenv/
|
149
|
+
|
150
|
+
# Ignore dynaconf secret files
|
151
|
+
**/.secrets.toml
|
152
|
+
*.xml
|
153
|
+
*.iml
|
154
|
+
pocket.lock
|
155
|
+
.log/
|
156
|
+
.pocket/
|
157
|
+
_build/
|
@@ -1,16 +1,10 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: hyperpocket-langgraph
|
3
|
-
Version: 0.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Requires-
|
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
|
-
|
27
|
-
|
20
|
+
from hyperpocket.tool import from_git
|
21
|
+
|
22
|
+
from hyperpocket_langgraph import PocketLanggraph
|
28
23
|
|
29
24
|
pocket = PocketLanggraph(tools=[
|
30
|
-
|
31
|
-
|
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
|
-
|
47
|
-
from pocket_langgraph import PocketLanggraph
|
42
|
+
from hyperpocket_langgraph import PocketLanggraph
|
48
43
|
|
49
44
|
pocket = PocketLanggraph(tools=[
|
50
|
-
|
51
|
-
|
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
|
-
|
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
|
-
|
83
|
-
|
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
|
-
|
142
|
-
|
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
|
-
|
147
|
-
|
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
|
-
|
159
|
-
|
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
|
-
|
164
|
-
|
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
|
-
|
@@ -8,12 +8,13 @@
|
|
8
8
|
## Get Pocket Subgraph
|
9
9
|
|
10
10
|
```python
|
11
|
-
|
12
|
-
|
11
|
+
from hyperpocket.tool import from_git
|
12
|
+
|
13
|
+
from hyperpocket_langgraph import PocketLanggraph
|
13
14
|
|
14
15
|
pocket = PocketLanggraph(tools=[
|
15
|
-
|
16
|
-
|
16
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
|
17
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
|
17
18
|
"https://github.com/my-org/some-awesome-tool",
|
18
19
|
])
|
19
20
|
|
@@ -26,15 +27,14 @@ pocket_node = pocket.get_tool_node()
|
|
26
27
|
```python
|
27
28
|
import os
|
28
29
|
|
30
|
+
from hyperpocket.tool import from_git
|
29
31
|
from langchain_openai import ChatOpenAI
|
30
32
|
|
31
|
-
|
32
|
-
from pocket_langgraph import PocketLanggraph
|
33
|
+
from hyperpocket_langgraph import PocketLanggraph
|
33
34
|
|
34
35
|
pocket = PocketLanggraph(tools=[
|
35
|
-
|
36
|
-
|
37
|
-
"https://github.com/my-org/some-awesome-tool",
|
36
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
|
37
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
|
38
38
|
])
|
39
39
|
|
40
40
|
# get tools from pocket to bind llm
|
@@ -51,6 +51,7 @@ llm_with_tools = llm.bind_tools(tools)
|
|
51
51
|
import os
|
52
52
|
from typing import Annotated
|
53
53
|
|
54
|
+
from hyperpocket.tool import from_git
|
54
55
|
from langchain_core.runnables import RunnableConfig
|
55
56
|
from langchain_openai import ChatOpenAI
|
56
57
|
from langgraph.checkpoint.memory import MemorySaver
|
@@ -59,14 +60,12 @@ from langgraph.graph.message import add_messages
|
|
59
60
|
from langgraph.prebuilt import tools_condition
|
60
61
|
from typing_extensions import TypedDict
|
61
62
|
|
62
|
-
|
63
|
-
from pocket_langgraph import PocketLanggraph
|
63
|
+
from hyperpocket_langgraph import PocketLanggraph
|
64
64
|
|
65
65
|
# Define pocket tools
|
66
66
|
pocket = PocketLanggraph(tools=[
|
67
|
-
|
68
|
-
|
69
|
-
"https://github.com/my-org/some-awesome-tool",
|
67
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
|
68
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
|
70
69
|
])
|
71
70
|
|
72
71
|
# Get Pocket ToolNode
|
@@ -123,14 +122,14 @@ by setting the `should_interrupt` flag when calling `get_tool_node`
|
|
123
122
|
Perform authentication in a multi-turn way
|
124
123
|
|
125
124
|
```python
|
126
|
-
|
127
|
-
|
125
|
+
from hyperpocket.tool import from_git
|
126
|
+
|
127
|
+
from hyperpocket_langgraph import PocketLanggraph
|
128
128
|
|
129
129
|
# Define pocket tools
|
130
130
|
pocket = PocketLanggraph(tools=[
|
131
|
-
|
132
|
-
|
133
|
-
"https://github.com/my-org/some-awesome-tool",
|
131
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
|
132
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
|
134
133
|
])
|
135
134
|
|
136
135
|
# Get Pocket ToolNode
|
@@ -140,14 +139,14 @@ pocket_node = pocket.get_tool_node(should_interrupt=False) # multi turn
|
|
140
139
|
### Human-in-the-loop Auth
|
141
140
|
|
142
141
|
```python
|
143
|
-
|
144
|
-
|
142
|
+
from hyperpocket.tool import from_git
|
143
|
+
|
144
|
+
from hyperpocket_langgraph import PocketLanggraph
|
145
145
|
|
146
146
|
# Define pocket tools
|
147
147
|
pocket = PocketLanggraph(tools=[
|
148
|
-
|
149
|
-
|
150
|
-
"https://github.com/my-org/some-awesome-tool",
|
148
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/get-message"),
|
149
|
+
from_git("https://github.com/vessl-ai/hyperawesometools", "main", "managed-tools/slack/post-message"),
|
151
150
|
])
|
152
151
|
|
153
152
|
# Get Pocket ToolNode
|
File without changes
|
@@ -1,17 +1,14 @@
|
|
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
|
-
from hyperpocket.server.server import PocketServerOperations
|
12
9
|
|
13
10
|
try:
|
14
|
-
from langchain_core.messages import
|
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.
|
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
|
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
|
-
|
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
|
42
|
-
|
43
|
-
|
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
|
-
|
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=
|
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
|
-
|
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=
|
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(
|
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(
|
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=
|
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
|
)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
[project]
|
3
|
+
name = "hyperpocket-langgraph"
|
4
|
+
version = "0.1.9"
|
5
|
+
description = ""
|
6
|
+
authors = [{ name = "Hyperpocket Team", email = "hyperpocket@vessl.ai" }]
|
7
|
+
requires-python = ">=3.10"
|
8
|
+
readme = "README.md"
|
9
|
+
dependencies = ["langgraph>=0.2.59", "hyperpocket>=0.0.3"]
|
10
|
+
|
11
|
+
[tool.uv.sources]
|
12
|
+
hyperpocket = { path = "../../hyperpocket", editable = true }
|
13
|
+
|
14
|
+
[dependency-groups]
|
15
|
+
dev = [
|
16
|
+
"pytest>=8.3.4",
|
17
|
+
"ruff>=0.8.6",
|
18
|
+
]
|
19
|
+
test = [
|
20
|
+
"langchain-openai>=0.3.1",
|
21
|
+
]
|
22
|
+
|
23
|
+
[build-system]
|
24
|
+
requires = ["hatchling"]
|
25
|
+
build-backend = "hatchling.build"
|
26
|
+
|
27
|
+
[tool.ruff.lint]
|
28
|
+
select = [
|
29
|
+
"E", # pycodestyle errors,
|
30
|
+
"F", # pyflakes errors,
|
31
|
+
"I", # isort errors,
|
32
|
+
]
|
33
|
+
ignore = [
|
34
|
+
"E501", # line too long, handled by formatting
|
35
|
+
]
|
36
|
+
|
37
|
+
[tool.ruff]
|
38
|
+
line-length = 88
|
39
|
+
target-version = "py310"
|
40
|
+
|
41
|
+
[tool.ruff.lint.per-file-ignores]
|
42
|
+
"__init__.py" = ["F401"]
|
File without changes
|