shrewd-agent / tools /sort_words_alphabetically.py
Pycrolis
feat(tool): add `sort_words_alphabetically` tool for sorting and joining word lists
83001c2
raw
history blame contribute delete
734 Bytes
from typing import List
from langchain_core.tools import tool
from loguru import logger
@tool("sort_words_alphabetically_tool", parse_docstring=True)
def sort_words_alphabetically(words: List[str]) -> str:
"""Sort a list of words alphabetically and join them with commas.
Args:
words (List[str]): List of strings to be sorted
Returns:
str: A string containing all sorted words joined with commas
"""
logger.info(f"use sort_words_alphabetically with param: {words}")
sorted_words = sorted(words)
result = ", ".join(sorted_words)
return result
if __name__ == "__main__":
print(sort_words_alphabetically.invoke({"words": ["broccoli", "celery", "sweet potatoes", "lettuce"]}))