forked from trpc-group/trpc-agent-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
78 lines (59 loc) · 1.76 KB
/
Copy pathtools.py
File metadata and controls
78 lines (59 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Tencent is pleased to support the open source community by making tRPC-Agent-Python available.
#
# Copyright (C) 2026 Tencent. All rights reserved.
#
# tRPC-Agent-Python is licensed under Apache-2.0.
""" Tools for the agent. """
import asyncio
from typing import List
from typing import Optional
from typing_extensions import override
from trpc_agent_sdk.context import InvocationContext
from trpc_agent_sdk.tools import BaseTool
from trpc_agent_sdk.tools import BaseToolSet
from trpc_agent_sdk.tools import FunctionTool
async def sports(name: str) -> str:
"""play sports
Args:
name: sport name
Returns:
sport name and time
"""
await asyncio.sleep(3)
return f"{name} takes 3s"
async def watch_tv(tv: str):
"""watch tv
Args:
tv: tv channel
Returns:
The content of the TV
"""
await asyncio.sleep(5)
return f"{tv} is broadcasting News Network"
async def listen_music(music: str):
"""Listening to music
Args:
music: music name
Returns:
The content of the music
"""
await asyncio.sleep(6)
return f"{music} is playing light music"
class HobbyToolSet(BaseToolSet):
"""Hobby Toolkit, mainly describing sports, watching TV and listening to music"""
def __init__(self):
super().__init__()
self.name = "hobby_toolset"
self.tools = []
@override
def initialize(self) -> None:
"""Initialize the Toolkit"""
super().initialize()
self.tools = [
FunctionTool(sports),
FunctionTool(watch_tv),
FunctionTool(listen_music),
]
@override
async def get_tools(self, invocation_context: Optional[InvocationContext] = None) -> List[BaseTool]:
return self.tools