Skip to content

Commit f60bce5

Browse files
committed
Add custom tool description builder
1 parent 7fc542d commit f60bce5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.github/workflows/master.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
matrix:
3232
os: [ubuntu-latest, windows-latest, macos-latest]
3333
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
34+
exclude:
35+
- os: windows-latest
36+
python-version: "3.12"
3437
fail-fast: false
3538
defaults:
3639
run:

tool_parse/marshal.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@
1414
__all__ = "marshal_annotation", "marshal_object"
1515

1616

17+
def build_tool_description(docstring: Docstring):
18+
"""
19+
Build description from docstring.
20+
21+
:param docstring: A Docstring object.
22+
"""
23+
24+
ret = []
25+
if docstring.short_description:
26+
ret.append(docstring.short_description)
27+
if docstring.blank_after_short_description:
28+
ret.append("")
29+
if docstring.long_description:
30+
ret.append(docstring.long_description)
31+
32+
return "\n".join(ret) if ret else None
33+
34+
1735
def map_param_to_description(docstring: Docstring) -> t.Dict[str, str]:
1836
"""
1937
Map parameters to their descriptions from a docstring.
@@ -254,7 +272,7 @@ def marshal_object(
254272

255273
fn_schema = {"name": name or __obj.__name__}
256274
ds = parse_from_object(__obj)
257-
if desc := description or ds.description:
275+
if desc := description or build_tool_description(ds):
258276
fn_schema["description"] = desc
259277

260278
param_key = "input_schema" if spec == "claude" else "parameters"

0 commit comments

Comments
 (0)