File size: 793 Bytes
b22167a
 
 
 
 
 
 
 
0a78ac3
b22167a
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# tools/string_tool.py
from langchain.tools import BaseTool

class StringTool(BaseTool):
    """
    Операции над строками: реверс текста по префиксу 'reverse:'.
    """
    name: str = "string_tool"
    description: str = "Apply string transformations: reverse text, case conversion, substring extraction, regex matching. Use for puzzles like reversed sentences, odd-even indexing, or any explicit string manipulation."

    def _run(self, text: str) -> str:
        if text.lower().startswith('reverse:'):
            s = text[len('reverse:'):].strip()
            return s[::-1]
        return f"Неизвестная операция: {text}"

    async def _arun(self, text: str) -> str:
        raise NotImplementedError("Async not supported.")