@@ -122,7 +122,6 @@ def sphinx_style_docstring(foo: int, /) -> str: # pragma: no cover
122
122
"""Sphinx style docstring.
123
123
124
124
:param foo: The foo thing.
125
- :return: The result.
126
125
"""
127
126
return str (foo )
128
127
@@ -187,6 +186,152 @@ def test_docstring_numpy(docstring_format: Literal['numpy', 'auto']):
187
186
)
188
187
189
188
189
+ def test_google_style_with_returns ():
190
+ agent = Agent (FunctionModel (get_json_schema ))
191
+
192
+ def my_tool (x : int ) -> str : # pragma: no cover
193
+ """A function that does something.
194
+
195
+ Args:
196
+ x: The input value.
197
+
198
+ Returns:
199
+ str: The result as a string.
200
+ """
201
+ return str (x )
202
+
203
+ agent .tool_plain (my_tool )
204
+ result = agent .run_sync ('Hello' )
205
+ json_schema = json .loads (result .data )
206
+ assert json_schema == snapshot (
207
+ {
208
+ 'name' : 'my_tool' ,
209
+ 'description' : """\
210
+ <summary>A function that does something.</summary>
211
+ <returns>
212
+ <type>str</type>
213
+ <description>The result as a string.</description>
214
+ </returns>\
215
+ """ ,
216
+ 'parameters_json_schema' : {
217
+ 'additionalProperties' : False ,
218
+ 'properties' : {'x' : {'description' : 'The input value.' , 'type' : 'integer' }},
219
+ 'required' : ['x' ],
220
+ 'type' : 'object' ,
221
+ },
222
+ 'outer_typed_dict_key' : None ,
223
+ }
224
+ )
225
+
226
+
227
+ def test_sphinx_style_with_returns ():
228
+ agent = Agent (FunctionModel (get_json_schema ))
229
+
230
+ def my_tool (x : int ) -> str : # pragma: no cover
231
+ """A sphinx function with returns.
232
+
233
+ :param x: The input value.
234
+ :rtype: str
235
+ :return: The result as a string with type.
236
+ """
237
+ return str (x )
238
+
239
+ agent .tool_plain (docstring_format = 'sphinx' )(my_tool )
240
+ result = agent .run_sync ('Hello' )
241
+ json_schema = json .loads (result .data )
242
+ assert json_schema == snapshot (
243
+ {
244
+ 'name' : 'my_tool' ,
245
+ 'description' : """\
246
+ <summary>A sphinx function with returns.</summary>
247
+ <returns>
248
+ <type>str</type>
249
+ <description>The result as a string with type.</description>
250
+ </returns>\
251
+ """ ,
252
+ 'parameters_json_schema' : {
253
+ 'additionalProperties' : False ,
254
+ 'properties' : {'x' : {'description' : 'The input value.' , 'type' : 'integer' }},
255
+ 'required' : ['x' ],
256
+ 'type' : 'object' ,
257
+ },
258
+ 'outer_typed_dict_key' : None ,
259
+ }
260
+ )
261
+
262
+
263
+ def test_numpy_style_with_returns ():
264
+ agent = Agent (FunctionModel (get_json_schema ))
265
+
266
+ def my_tool (x : int ) -> str : # pragma: no cover
267
+ """A numpy function with returns.
268
+
269
+ Parameters
270
+ ----------
271
+ x : int
272
+ The input value.
273
+
274
+ Returns
275
+ -------
276
+ str
277
+ The result as a string with type.
278
+ """
279
+ return str (x )
280
+
281
+ agent .tool_plain (docstring_format = 'numpy' )(my_tool )
282
+ result = agent .run_sync ('Hello' )
283
+ json_schema = json .loads (result .data )
284
+ assert json_schema == snapshot (
285
+ {
286
+ 'name' : 'my_tool' ,
287
+ 'description' : """\
288
+ <summary>A numpy function with returns.</summary>
289
+ <returns>
290
+ <type>str</type>
291
+ <description>The result as a string with type.</description>
292
+ </returns>\
293
+ """ ,
294
+ 'parameters_json_schema' : {
295
+ 'additionalProperties' : False ,
296
+ 'properties' : {'x' : {'description' : 'The input value.' , 'type' : 'integer' }},
297
+ 'required' : ['x' ],
298
+ 'type' : 'object' ,
299
+ },
300
+ 'outer_typed_dict_key' : None ,
301
+ }
302
+ )
303
+
304
+
305
+ def only_returns_type () -> str : # pragma: no cover
306
+ """
307
+
308
+ Returns:
309
+ str: The result as a string.
310
+ """
311
+ return 'foo'
312
+
313
+
314
+ def test_only_returns_type ():
315
+ agent = Agent (FunctionModel (get_json_schema ))
316
+ agent .tool_plain (only_returns_type )
317
+
318
+ result = agent .run_sync ('Hello' )
319
+ json_schema = json .loads (result .data )
320
+ assert json_schema == snapshot (
321
+ {
322
+ 'name' : 'only_returns_type' ,
323
+ 'description' : """\
324
+ <returns>
325
+ <type>str</type>
326
+ <description>The result as a string.</description>
327
+ </returns>\
328
+ """ ,
329
+ 'parameters_json_schema' : {'additionalProperties' : False , 'properties' : {}, 'type' : 'object' },
330
+ 'outer_typed_dict_key' : None ,
331
+ }
332
+ )
333
+
334
+
190
335
def unknown_docstring (** kwargs : int ) -> str : # pragma: no cover
191
336
"""Unknown style docstring."""
192
337
return str (kwargs )
@@ -572,11 +717,7 @@ def ctx_tool(ctx: RunContext[int], x: int) -> int:
572
717
573
718
574
719
async def tool_without_return_annotation_in_docstring () -> str : # pragma: no cover
575
- """A tool that documents what it returns but doesn't have a return annotation in the docstring.
576
-
577
- Returns:
578
- A value.
579
- """
720
+ """A tool that documents what it returns but doesn't have a return annotation in the docstring."""
580
721
581
722
return ''
582
723
@@ -591,8 +732,7 @@ def test_suppress_griffe_logging(caplog: LogCaptureFixture):
591
732
json_schema = json .loads (result .data )
592
733
assert json_schema == snapshot (
593
734
{
594
- 'description' : "A tool that documents what it returns but doesn't have a "
595
- 'return annotation in the docstring.' ,
735
+ 'description' : "A tool that documents what it returns but doesn't have a return annotation in the docstring." ,
596
736
'name' : 'tool_without_return_annotation_in_docstring' ,
597
737
'outer_typed_dict_key' : None ,
598
738
'parameters_json_schema' : {'additionalProperties' : False , 'properties' : {}, 'type' : 'object' },
0 commit comments