T7yrttrd commited on
Commit
3660ade
·
verified ·
1 Parent(s): e73985a

Create tools_def.py

Browse files
Files changed (1) hide show
  1. tools_def.py +200 -0
tools_def.py ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ TAVILY_TOOL = {
2
+ "type": "function",
3
+ "function": {
4
+ "name": "tavily_search",
5
+ "description": "Search the live web for real-time information, documentation, news, or current facts.",
6
+ "parameters": {
7
+ "type": "object",
8
+ "properties": {
9
+ "query": {
10
+ "type": "string",
11
+ "description": "The search query."
12
+ },
13
+ "max_results": {
14
+ "type": "integer",
15
+ "description": "Number of search results to retrieve (default: 8, max: 15).",
16
+ "default": 8
17
+ }
18
+ },
19
+ "required": ["query"]
20
+ }
21
+ }
22
+ }
23
+
24
+ GMAIL_TOOL = {
25
+ "type": "function",
26
+ "function": {
27
+ "name": "gmail_api_request",
28
+ "description": "Execute direct REST API calls to Google Gmail API (Base: https://gmail.googleapis.com).",
29
+ "parameters": {
30
+ "type": "object",
31
+ "properties": {
32
+ "method": {
33
+ "type": "string",
34
+ "enum": ["GET", "POST", "PUT", "PATCH", "DELETE"],
35
+ "description": "HTTP method."
36
+ },
37
+ "endpoint": {
38
+ "type": "string",
39
+ "description": "REST API endpoint path starting with leading slash (e.g., '/gmail/v1/users/me/messages', '/gmail/v1/users/me/drafts', '/gmail/v1/users/me/labels')."
40
+ },
41
+ "params": {
42
+ "type": "object",
43
+ "description": "Optional URL query parameters (e.g., {'q': 'is:unread', 'maxResults': 10})."
44
+ },
45
+ "body": {
46
+ "type": "object",
47
+ "description": "Optional JSON request body for POST/PUT/PATCH requests."
48
+ }
49
+ },
50
+ "required": ["method", "endpoint"]
51
+ }
52
+ }
53
+ }
54
+
55
+ CALENDAR_TOOL = {
56
+ "type": "function",
57
+ "function": {
58
+ "name": "calendar_api_request",
59
+ "description": "Execute direct REST API calls to Google Calendar API (Base: https://www.googleapis.com).",
60
+ "parameters": {
61
+ "type": "object",
62
+ "properties": {
63
+ "method": {
64
+ "type": "string",
65
+ "enum": ["GET", "POST", "PUT", "PATCH", "DELETE"],
66
+ "description": "HTTP method."
67
+ },
68
+ "endpoint": {
69
+ "type": "string",
70
+ "description": "REST API endpoint path starting with leading slash (e.g., '/calendar/v3/calendars/primary/events', '/calendar/v3/users/me/calendarList')."
71
+ },
72
+ "params": {
73
+ "type": "object",
74
+ "description": "Optional URL query parameters (e.g., {'timeMin': '2026-01-01T00:00:00Z', 'singleEvents': True})."
75
+ },
76
+ "body": {
77
+ "type": "object",
78
+ "description": "Optional JSON request body for POST/PUT/PATCH requests."
79
+ }
80
+ },
81
+ "required": ["method", "endpoint"]
82
+ }
83
+ }
84
+ }
85
+
86
+ DRIVE_TOOL = {
87
+ "type": "function",
88
+ "function": {
89
+ "name": "drive_api_request",
90
+ "description": "Execute direct REST API calls to Google Drive API (Base: https://www.googleapis.com).",
91
+ "parameters": {
92
+ "type": "object",
93
+ "properties": {
94
+ "method": {
95
+ "type": "string",
96
+ "enum": ["GET", "POST", "PUT", "PATCH", "DELETE"],
97
+ "description": "HTTP method."
98
+ },
99
+ "endpoint": {
100
+ "type": "string",
101
+ "description": "REST API endpoint path starting with leading slash (e.g., '/drive/v3/files', '/drive/v3/about')."
102
+ },
103
+ "params": {
104
+ "type": "object",
105
+ "description": "Optional URL query parameters (e.g., {'q': \"name contains 'document'\", 'fields': 'files(id, name, mimeType)'})."
106
+ },
107
+ "body": {
108
+ "type": "object",
109
+ "description": "Optional JSON request body for POST/PUT/PATCH requests."
110
+ }
111
+ },
112
+ "required": ["method", "endpoint"]
113
+ }
114
+ }
115
+ }
116
+
117
+ NOTION_TOOL = {
118
+ "type": "function",
119
+ "function": {
120
+ "name": "notion_api_request",
121
+ "description": "Execute direct REST API calls to Notion API v1 (Base: https://api.notion.com).",
122
+ "parameters": {
123
+ "type": "object",
124
+ "properties": {
125
+ "method": {
126
+ "type": "string",
127
+ "enum": ["GET", "POST", "PATCH", "DELETE"],
128
+ "description": "HTTP method."
129
+ },
130
+ "endpoint": {
131
+ "type": "string",
132
+ "description": "REST API endpoint path starting with leading slash (e.g., '/v1/search', '/v1/pages', '/v1/databases/{database_id}/query', '/v1/blocks/{block_id}/children')."
133
+ },
134
+ "params": {
135
+ "type": "object",
136
+ "description": "Optional URL query parameters."
137
+ },
138
+ "body": {
139
+ "type": "object",
140
+ "description": "Optional JSON request body for POST/PATCH requests."
141
+ }
142
+ },
143
+ "required": ["method", "endpoint"]
144
+ }
145
+ }
146
+ }
147
+
148
+ GITHUB_TOOL = {
149
+ "type": "function",
150
+ "function": {
151
+ "name": "github_api_request",
152
+ "description": "Execute direct REST API calls to GitHub REST API (Base: https://api.github.com).",
153
+ "parameters": {
154
+ "type": "object",
155
+ "properties": {
156
+ "method": {
157
+ "type": "string",
158
+ "enum": ["GET", "POST", "PUT", "PATCH", "DELETE"],
159
+ "description": "HTTP method."
160
+ },
161
+ "endpoint": {
162
+ "type": "string",
163
+ "description": "REST API endpoint path starting with leading slash (e.g., '/user', '/user/repos', '/repos/{owner}/{repo}/issues', '/search/repositories')."
164
+ },
165
+ "params": {
166
+ "type": "object",
167
+ "description": "Optional URL query parameters (e.g., {'per_page': 10, 'state': 'open'})."
168
+ },
169
+ "body": {
170
+ "type": "object",
171
+ "description": "Optional JSON request body for POST/PUT/PATCH requests."
172
+ }
173
+ },
174
+ "required": ["method", "endpoint"]
175
+ }
176
+ }
177
+ }
178
+
179
+ def get_filtered_tools(connectors: list = None, web_search: bool = False) -> list:
180
+ active_tools = []
181
+ if web_search:
182
+ active_tools.append(TAVILY_TOOL)
183
+
184
+ if not connectors or not isinstance(connectors, list):
185
+ return active_tools
186
+
187
+ connector_keys = {str(c).lower().strip() for c in connectors}
188
+
189
+ if "gmail" in connector_keys or "google" in connector_keys:
190
+ active_tools.append(GMAIL_TOOL)
191
+ if "calendar" in connector_keys or "google" in connector_keys:
192
+ active_tools.append(CALENDAR_TOOL)
193
+ if "drive" in connector_keys or "google" in connector_keys:
194
+ active_tools.append(DRIVE_TOOL)
195
+ if "notion" in connector_keys:
196
+ active_tools.append(NOTION_TOOL)
197
+ if "github" in connector_keys:
198
+ active_tools.append(GITHUB_TOOL)
199
+
200
+ return active_tools