Skip to content

Commit 6c1c120

Browse files
committed
Add example tools
1 parent 4b99393 commit 6c1c120

13 files changed

Lines changed: 970 additions & 2 deletions

File tree

packages/torque/examples/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Example Tools for Torque SDK
3+
*
4+
* This module exports a collection of commonly-used tool definitions
5+
* that can be imported and used directly in your dataset generation scripts.
6+
*
7+
* Usage:
8+
* ```ts
9+
* import { calculatorTool, weatherTool } from "@qforge/torque/examples";
10+
* ```
11+
*/
12+
13+
export * from "./tools/calculator";
14+
export * from "./tools/weather";
15+
export * from "./tools/search";
16+
export * from "./tools/email";
17+
export * from "./tools/file-operations";
18+
export * from "./tools/database";
19+
export * from "./tools/timer";
20+
export * from "./tools/translation";
21+
export * from "./tools/calendar";
22+
export * from "./tools/code-execution";
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Calculator Tool
3+
*
4+
* A basic arithmetic calculator tool for performing mathematical operations.
5+
* Useful for training models to handle math queries and tool-assisted calculations.
6+
*/
7+
8+
import { tool } from "../../src/schema";
9+
import { z } from "zod";
10+
11+
export const calculatorTool = tool({
12+
name: "calculator",
13+
description: "Perform basic arithmetic operations",
14+
parameters: z.object({
15+
operation: z
16+
.enum(["add", "subtract", "multiply", "divide", "power", "modulo"])
17+
.describe("The arithmetic operation to perform"),
18+
a: z.number().describe("First operand"),
19+
b: z.number().describe("Second operand"),
20+
}),
21+
output: z.object({
22+
result: z.number().describe("The calculation result"),
23+
expression: z
24+
.string()
25+
.optional()
26+
.describe("The mathematical expression that was evaluated"),
27+
}),
28+
});
29+
30+
export const advancedCalculatorTool = tool({
31+
name: "advanced_calculator",
32+
description:
33+
"Perform advanced mathematical operations including trigonometry, logarithms, and roots",
34+
parameters: z.object({
35+
operation: z
36+
.enum([
37+
"sin",
38+
"cos",
39+
"tan",
40+
"log",
41+
"ln",
42+
"sqrt",
43+
"abs",
44+
"round",
45+
"ceil",
46+
"floor",
47+
])
48+
.describe("The mathematical function to apply"),
49+
value: z.number().describe("The input value"),
50+
precision: z
51+
.number()
52+
.int()
53+
.min(0)
54+
.max(10)
55+
.optional()
56+
.describe("Number of decimal places for rounding"),
57+
}),
58+
output: z.object({
59+
result: z.number().describe("The calculated result"),
60+
unit: z
61+
.string()
62+
.optional()
63+
.describe("Unit of the result (e.g., 'radians', 'degrees')"),
64+
}),
65+
});
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/**
2+
* Calendar and Event Tools
3+
*
4+
* Tools for managing calendar events, scheduling meetings, and checking availability.
5+
* Demonstrates temporal data and scheduling operations.
6+
*/
7+
8+
import { tool } from "../../src/schema";
9+
import { z } from "zod";
10+
11+
export const createEventTool = tool({
12+
name: "create_calendar_event",
13+
description: "Create a new calendar event",
14+
parameters: z.object({
15+
title: z.string().describe("Event title"),
16+
start_time: z.string().describe("Event start time (ISO datetime)"),
17+
end_time: z.string().describe("Event end time (ISO datetime)"),
18+
description: z.string().optional().describe("Event description"),
19+
location: z.string().optional().describe("Event location"),
20+
attendees: z
21+
.array(z.string().email())
22+
.optional()
23+
.describe("Email addresses of attendees"),
24+
reminder_minutes: z
25+
.number()
26+
.int()
27+
.optional()
28+
.describe("Minutes before event to send reminder"),
29+
recurrence: z
30+
.enum(["none", "daily", "weekly", "monthly"])
31+
.default("none")
32+
.optional(),
33+
}),
34+
output: z.object({
35+
event_id: z.string().describe("Unique event identifier"),
36+
created_at: z.string(),
37+
calendar_link: z.string().url().optional(),
38+
status: z.enum(["created", "error"]),
39+
}),
40+
});
41+
42+
export const checkAvailabilityTool = tool({
43+
name: "check_availability",
44+
description: "Check calendar availability for specific time slots",
45+
parameters: z.object({
46+
start_date: z.string().describe("Start date to check (YYYY-MM-DD)"),
47+
end_date: z.string().describe("End date to check (YYYY-MM-DD)"),
48+
attendees: z
49+
.array(z.string().email())
50+
.optional()
51+
.describe("Check availability for these attendees"),
52+
duration_minutes: z
53+
.number()
54+
.int()
55+
.min(15)
56+
.optional()
57+
.describe("Desired meeting duration"),
58+
}),
59+
output: z.object({
60+
available_slots: z.array(
61+
z.object({
62+
start_time: z.string(),
63+
end_time: z.string(),
64+
all_attendees_free: z.boolean().optional(),
65+
})
66+
),
67+
busy_slots: z
68+
.array(
69+
z.object({
70+
start_time: z.string(),
71+
end_time: z.string(),
72+
reason: z.string().optional(),
73+
})
74+
)
75+
.optional(),
76+
}),
77+
});
78+
79+
export const listEventsTool = tool({
80+
name: "list_calendar_events",
81+
description: "List calendar events within a date range",
82+
parameters: z.object({
83+
start_date: z.string().describe("Start date (YYYY-MM-DD)"),
84+
end_date: z.string().describe("End date (YYYY-MM-DD)"),
85+
calendar_id: z
86+
.string()
87+
.optional()
88+
.describe("Specific calendar ID to query"),
89+
search: z.string().optional().describe("Search term to filter events"),
90+
}),
91+
output: z.object({
92+
events: z.array(
93+
z.object({
94+
event_id: z.string(),
95+
title: z.string(),
96+
start_time: z.string(),
97+
end_time: z.string(),
98+
location: z.string().optional(),
99+
attendees_count: z.number().int().optional(),
100+
status: z.enum(["confirmed", "tentative", "cancelled"]).optional(),
101+
})
102+
),
103+
total_count: z.number().int(),
104+
}),
105+
});
106+
107+
export const updateEventTool = tool({
108+
name: "update_calendar_event",
109+
description: "Update an existing calendar event",
110+
parameters: z.object({
111+
event_id: z.string().describe("Event ID to update"),
112+
title: z.string().optional().describe("New event title"),
113+
start_time: z.string().optional().describe("New start time"),
114+
end_time: z.string().optional().describe("New end time"),
115+
description: z.string().optional(),
116+
location: z.string().optional(),
117+
status: z.enum(["confirmed", "tentative", "cancelled"]).optional(),
118+
}),
119+
output: z.object({
120+
event_id: z.string(),
121+
updated_at: z.string(),
122+
status: z.enum(["updated", "not_found", "error"]),
123+
notification_sent: z.boolean().optional(),
124+
}),
125+
});
126+
127+
export const deleteEventTool = tool({
128+
name: "delete_calendar_event",
129+
description: "Delete a calendar event",
130+
parameters: z.object({
131+
event_id: z.string().describe("Event ID to delete"),
132+
notify_attendees: z
133+
.boolean()
134+
.default(true)
135+
.optional()
136+
.describe("Send cancellation notice to attendees"),
137+
cancellation_message: z
138+
.string()
139+
.optional()
140+
.describe("Optional message to include in cancellation notice"),
141+
}),
142+
output: z.object({
143+
event_id: z.string(),
144+
status: z.enum(["deleted", "not_found", "error"]),
145+
attendees_notified: z.number().int().optional(),
146+
}),
147+
});
148+
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/**
2+
* Code Execution Tools
3+
*
4+
* Tools for executing code in various languages and environments.
5+
* Useful for training models to handle code generation and execution tasks.
6+
*/
7+
8+
import { tool } from "../../src/schema";
9+
import { z } from "zod";
10+
11+
export const executeCodeTool = tool({
12+
name: "execute_code",
13+
description: "Execute code in a sandboxed environment",
14+
parameters: z.object({
15+
code: z.string().describe("Code to execute"),
16+
language: z
17+
.enum([
18+
"python",
19+
"javascript",
20+
"typescript",
21+
"bash",
22+
"ruby",
23+
"go",
24+
"rust",
25+
"java",
26+
])
27+
.describe("Programming language"),
28+
timeout_seconds: z
29+
.number()
30+
.int()
31+
.min(1)
32+
.max(300)
33+
.default(30)
34+
.optional()
35+
.describe("Execution timeout"),
36+
input: z.string().optional().describe("Standard input for the program"),
37+
}),
38+
output: z.object({
39+
stdout: z.string().describe("Standard output from execution"),
40+
stderr: z.string().optional().describe("Standard error output"),
41+
exit_code: z.number().int().describe("Process exit code"),
42+
execution_time_ms: z.number().optional(),
43+
status: z.enum(["success", "error", "timeout"]),
44+
}),
45+
});
46+
47+
export const lintCodeTool = tool({
48+
name: "lint_code",
49+
description: "Run a linter on code to check for style and syntax issues",
50+
parameters: z.object({
51+
code: z.string().describe("Code to lint"),
52+
language: z
53+
.enum(["python", "javascript", "typescript", "go", "rust"])
54+
.describe("Programming language"),
55+
config: z
56+
.record(z.string(), z.any())
57+
.optional()
58+
.describe("Linter configuration options"),
59+
}),
60+
output: z.object({
61+
issues: z.array(
62+
z.object({
63+
line: z.number().int(),
64+
column: z.number().int().optional(),
65+
severity: z.enum(["error", "warning", "info"]),
66+
message: z.string(),
67+
rule: z.string().optional(),
68+
})
69+
),
70+
total_errors: z.number().int(),
71+
total_warnings: z.number().int(),
72+
status: z.enum(["passed", "failed"]),
73+
}),
74+
});
75+
76+
export const formatCodeTool = tool({
77+
name: "format_code",
78+
description: "Format code according to language conventions",
79+
parameters: z.object({
80+
code: z.string().describe("Code to format"),
81+
language: z
82+
.enum(["python", "javascript", "typescript", "go", "rust", "java", "html", "css"])
83+
.describe("Programming language"),
84+
style: z
85+
.string()
86+
.optional()
87+
.describe("Code style guide to use (e.g., 'google', 'airbnb')"),
88+
}),
89+
output: z.object({
90+
formatted_code: z.string(),
91+
changes_count: z.number().int().describe("Number of formatting changes made"),
92+
status: z.enum(["formatted", "no_changes", "error"]),
93+
}),
94+
});
95+
96+
export const explainCodeTool = tool({
97+
name: "explain_code",
98+
description: "Generate an explanation of what a code snippet does",
99+
parameters: z.object({
100+
code: z.string().describe("Code to explain"),
101+
language: z.string().describe("Programming language"),
102+
detail_level: z
103+
.enum(["brief", "detailed", "line-by-line"])
104+
.default("detailed")
105+
.optional(),
106+
}),
107+
output: z.object({
108+
explanation: z.string().describe("Natural language explanation of the code"),
109+
key_concepts: z
110+
.array(z.string())
111+
.optional()
112+
.describe("Important concepts used in the code"),
113+
complexity: z.enum(["low", "medium", "high"]).optional(),
114+
}),
115+
});
116+

0 commit comments

Comments
 (0)