meshagent-tools 0.25.1__py3-none-any.whl → 0.25.2__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.
@@ -36,6 +36,31 @@ async def test_decorated_tool_executes_with_toolkit():
36
36
  assert result.json == {"name": "alpha", "count": 2, "flag": True}
37
37
 
38
38
 
39
+ class Greeter:
40
+ def __init__(self, prefix: str) -> None:
41
+ self._prefix = prefix
42
+
43
+ @tool(name="greet")
44
+ def greet(self, *, name: str) -> str:
45
+ return f"{self._prefix}{name}"
46
+
47
+
48
+ @pytest.mark.asyncio
49
+ async def test_decorated_method_executes_with_toolkit():
50
+ greeter = Greeter("hello ")
51
+ toolkit = Toolkit(name="test", tools=[greeter.greet])
52
+ context = ToolContext(room=object(), caller=object())
53
+
54
+ result = await toolkit.execute(
55
+ context=context,
56
+ name="greet",
57
+ arguments={"name": "mesh"},
58
+ )
59
+
60
+ assert isinstance(result, JsonResponse)
61
+ assert result.json == "hello mesh"
62
+
63
+
39
64
  def test_decorator_schema_is_strict():
40
65
  schema = make_payload.input_schema
41
66
 
meshagent/tools/tool.py CHANGED
@@ -147,7 +147,16 @@ def tool(
147
147
  supports_context = False
148
148
  fields: dict[str, tuple[Any, Any]] = {}
149
149
 
150
- for param_name, param in signature.parameters.items():
150
+ parameters = list(signature.parameters.items())
151
+ bound_param_name = None
152
+ if parameters:
153
+ first_param_name, _first_param = parameters[0]
154
+ if first_param_name in ("self", "cls"):
155
+ bound_param_name = first_param_name
156
+
157
+ for param_name, param in parameters:
158
+ if bound_param_name == param_name:
159
+ continue
151
160
  annotation = hints.get(param_name, Any)
152
161
  if annotation is ToolContext:
153
162
  supports_context = True
@@ -167,7 +176,7 @@ def tool(
167
176
  )
168
177
 
169
178
  class FunctionTool(Tool):
170
- def __init__(self):
179
+ def __init__(self, bound_instance: Optional[object] = None):
171
180
  super().__init__(
172
181
  name=tool_name,
173
182
  title=tool_title,
@@ -178,6 +187,20 @@ def tool(
178
187
  supports_context=supports_context,
179
188
  )
180
189
  self.strict = True
190
+ self._bound_instance = bound_instance
191
+
192
+ def __get__(self, instance, owner):
193
+ if instance is None:
194
+ if bound_param_name == "cls" and owner is not None:
195
+ if self._bound_instance is owner:
196
+ return self
197
+ return FunctionTool(bound_instance=owner)
198
+ return self
199
+
200
+ if self._bound_instance is instance:
201
+ return self
202
+
203
+ return FunctionTool(bound_instance=instance)
181
204
 
182
205
  async def invoke(
183
206
  self,
@@ -188,10 +211,18 @@ def tool(
188
211
  data = InputModel.model_validate(arguments)
189
212
  parsed_args = {field: getattr(data, field) for field in fields}
190
213
 
214
+ bound_instance = self._bound_instance
215
+
191
216
  if supports_context:
192
- result = fn(context, **parsed_args)
217
+ if bound_instance is not None:
218
+ result = fn(bound_instance, context, **parsed_args)
219
+ else:
220
+ result = fn(context, **parsed_args)
193
221
  else:
194
- result = fn(**parsed_args)
222
+ if bound_instance is not None:
223
+ result = fn(bound_instance, **parsed_args)
224
+ else:
225
+ result = fn(**parsed_args)
195
226
 
196
227
  if inspect.isawaitable(result):
197
228
  result = await result
@@ -1 +1 @@
1
- __version__ = "0.25.1"
1
+ __version__ = "0.25.2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: meshagent-tools
3
- Version: 0.25.1
3
+ Version: 0.25.2
4
4
  Summary: Tools for Meshagent
5
5
  License-Expression: Apache-2.0
6
6
  Project-URL: Documentation, https://docs.meshagent.com
@@ -12,7 +12,7 @@ License-File: LICENSE
12
12
  Requires-Dist: pyjwt~=2.10
13
13
  Requires-Dist: pytest~=8.4
14
14
  Requires-Dist: pytest-asyncio~=0.26
15
- Requires-Dist: meshagent-api~=0.25.1
15
+ Requires-Dist: meshagent-api~=0.25.2
16
16
  Requires-Dist: html-to-markdown~=2.24.3
17
17
  Requires-Dist: aiohttp[speedups]~=3.13.0
18
18
  Requires-Dist: opentelemetry-distro~=0.54b1
@@ -12,14 +12,14 @@ meshagent/tools/pydantic.py,sha256=n-MD0gC-oRtHSTUDD5IV2dP-xIk-zjcDgHfgjqMgiqM,1
12
12
  meshagent/tools/script.py,sha256=eyQiufoc2ZkTUBTO58VQURnkkQA2lboED5s0-BvAvgM,11811
13
13
  meshagent/tools/storage.py,sha256=NVpi9CZKSZUh8PTxxCdJhJy7Gzmdp55-zo2yHYGod_E,23340
14
14
  meshagent/tools/strict_schema.py,sha256=IytdAANa6lsfrsg5FsJuqYrxH9D_fayl-Lc9EwgLJSM,6277
15
- meshagent/tools/tool.py,sha256=HgvlOlz2wMrmD5aaV49fRpnGyXJwnVcH9j4wKaaPbWo,5935
15
+ meshagent/tools/tool.py,sha256=eokq9Sh6aGao7w2PlExx1WJcfy4OovfMaQUluwsulnA,7221
16
16
  meshagent/tools/toolkit.py,sha256=iVcCvhwWqmahDow9FN-VRWGo9MEj669Vw7TAB7Mx9Ww,4066
17
17
  meshagent/tools/uuid.py,sha256=mzRwDmXy39U5lHhd9wqV4r-ZdS8jPfDTTs4UfW4KHJQ,1342
18
- meshagent/tools/version.py,sha256=ACu2Z3Q3TFgYpAno_eu9ssJ1QULjNXvjGvyqDSHrQ_o,23
18
+ meshagent/tools/version.py,sha256=NMzPG-AisbqV0qHNDcM-oIMtdXA6rLhjzeATPyNq6Nw,23
19
19
  meshagent/tools/web_toolkit.py,sha256=Seju8gpdUoPku7Yfar_s-cVOnlweFzKj-bFqrQVup8o,4603
20
- meshagent/tools/tests/tool_decorator_test.py,sha256=Fd4uvoefU8hpdSWaiYen15tqnlwoY092G6hjYafaMGE,1190
21
- meshagent_tools-0.25.1.dist-info/licenses/LICENSE,sha256=eTt0SPW-sVNdkZe9PS_S8WfCIyLjRXRl7sUBWdlteFg,10254
22
- meshagent_tools-0.25.1.dist-info/METADATA,sha256=I_DrA3zW7uRwNXwllW8OSipjUKQimC_BgOP4_8xoDBI,2930
23
- meshagent_tools-0.25.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
24
- meshagent_tools-0.25.1.dist-info/top_level.txt,sha256=GlcXnHtRP6m7zlG3Df04M35OsHtNXy_DY09oFwWrH74,10
25
- meshagent_tools-0.25.1.dist-info/RECORD,,
20
+ meshagent/tools/tests/tool_decorator_test.py,sha256=8o9JwhOU6rdbJJdyCYfT4B8m9JgmMSAkU8QTpo4OmGg,1826
21
+ meshagent_tools-0.25.2.dist-info/licenses/LICENSE,sha256=eTt0SPW-sVNdkZe9PS_S8WfCIyLjRXRl7sUBWdlteFg,10254
22
+ meshagent_tools-0.25.2.dist-info/METADATA,sha256=X2n1kOJ-WFqsT45x1EcKcDsY3PqCiZkKwW0Y2g-V3o8,2930
23
+ meshagent_tools-0.25.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
24
+ meshagent_tools-0.25.2.dist-info/top_level.txt,sha256=GlcXnHtRP6m7zlG3Df04M35OsHtNXy_DY09oFwWrH74,10
25
+ meshagent_tools-0.25.2.dist-info/RECORD,,