Skip to content

Commit 4cc46e5

Browse files
committed
refactor: eliminate keyword-based tool gating — always expose all tools
1 parent e997009 commit 4cc46e5

2 files changed

Lines changed: 2 additions & 73 deletions

File tree

apps/chat/lib/agent.ts

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,67 +1769,6 @@ export function isAIRateLimitError(err: unknown): boolean {
17691769
return hasRateLimit || (status429 && (msg.includes("retry") || causeMsg.includes("retry")));
17701770
}
17711771

1772-
// ─── Context-aware tool filtering ─────────────────────────────────────────────
1773-
1774-
const CORE_TOOL_NAMES = new Set([
1775-
"list_event_types",
1776-
"list_event_types_by_username",
1777-
"check_availability",
1778-
"check_availability_public",
1779-
"book_meeting",
1780-
"book_meeting_public",
1781-
"add_booking_attendee",
1782-
"list_bookings",
1783-
"get_booking",
1784-
"cancel_booking",
1785-
"reschedule_booking",
1786-
"create_event_type",
1787-
"update_event_type",
1788-
"delete_event_type",
1789-
]);
1790-
1791-
const ADMIN_KEYWORDS = [
1792-
"schedule",
1793-
"working hours",
1794-
"profile",
1795-
"unlink",
1796-
"no-show",
1797-
"no show",
1798-
"confirm booking",
1799-
"decline",
1800-
"calendar link",
1801-
"busy times",
1802-
];
1803-
1804-
export function detectToolSet(
1805-
message: string,
1806-
history: ModelMessage[]
1807-
): "core" | "all" {
1808-
const lowerMsg = message.toLowerCase();
1809-
if (ADMIN_KEYWORDS.some((kw) => lowerMsg.includes(kw))) return "all";
1810-
// Also check last few history messages for admin context
1811-
for (const msg of history.slice(-3)) {
1812-
if (typeof msg.content === "string" && ADMIN_KEYWORDS.some((kw) => msg.content.toString().toLowerCase().includes(kw))) {
1813-
return "all";
1814-
}
1815-
}
1816-
return "core";
1817-
}
1818-
1819-
function filterTools<T extends Record<string, unknown>>(
1820-
allTools: T,
1821-
toolSet: "core" | "all"
1822-
): T {
1823-
if (toolSet === "all") return allTools;
1824-
const filtered = {} as Record<string, unknown>;
1825-
for (const [name, t] of Object.entries(allTools)) {
1826-
if (CORE_TOOL_NAMES.has(name)) {
1827-
filtered[name] = t;
1828-
}
1829-
}
1830-
return filtered as T;
1831-
}
1832-
18331772
// ─── Agent stream ─────────────────────────────────────────────────────────────
18341773

18351774
export interface AgentStreamOptions {
@@ -1844,8 +1783,6 @@ export interface AgentStreamOptions {
18441783
onErrorRef?: { current: Error | null };
18451784
/** Pre-verified user context from bot layer — injected into system prompt. */
18461785
userContext?: UserContext;
1847-
/** Which tool set to expose: 'core' (booking only) or 'all' (includes admin tools). */
1848-
toolSet?: "core" | "all";
18491786
}
18501787

18511788
export function runAgentStream({
@@ -1858,10 +1795,8 @@ export function runAgentStream({
18581795
logger,
18591796
onErrorRef,
18601797
userContext,
1861-
toolSet = "core",
18621798
}: AgentStreamOptions) {
1863-
const allTools = createCalTools(teamId, userId, platform, lookupPlatformUser);
1864-
const tools = filterTools(allTools, toolSet);
1799+
const tools = createCalTools(teamId, userId, platform, lookupPlatformUser);
18651800

18661801
// Keep only the last 10 messages from history to prevent stale context
18671802
// (e.g. an old booking request) from hijacking unrelated follow-up messages.

apps/chat/lib/bot.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
RateLimitError,
2727
} from "chat";
2828
import type { LookupPlatformUserFn, UserContext } from "./agent";
29-
import { detectToolSet, isAIRateLimitError, isAIToolCallError, runAgentStream } from "./agent";
29+
import { isAIRateLimitError, isAIToolCallError, runAgentStream } from "./agent";
3030
import { CalcomApiError } from "./calcom/client";
3131
import { generateAuthUrl } from "./calcom/oauth";
3232
import { validateRequiredEnv } from "./env";
@@ -837,7 +837,6 @@ bot.onNewMessage(/[\s\S]+/, async (thread, message) => {
837837

838838
const enrichedMessage = await buildEnrichedMessage(message.text, thread.id);
839839
const rawHistory = await buildHistory(thread);
840-
const toolSet = detectToolSet(message.text, rawHistory);
841840

842841
await withTelegramTypingRefresh(thread, ctx.platform, async () => {
843842
bot
@@ -853,7 +852,6 @@ bot.onNewMessage(/[\s\S]+/, async (thread, message) => {
853852
logger: bot.getLogger("agent"),
854853
onErrorRef: lastStreamErrorRef,
855854
userContext,
856-
toolSet,
857855
});
858856
await postAgentStream(thread, result, ctx, { onErrorRef: lastStreamErrorRef });
859857
});
@@ -960,7 +958,6 @@ bot.onNewMention(async (thread, message) => {
960958

961959
const enrichedMessage = await buildEnrichedMessage(resolvedMessage, thread.id);
962960
const rawHistory = await buildHistory(thread);
963-
const toolSet = detectToolSet(userMessage, rawHistory);
964961

965962
await withTelegramTypingRefresh(thread, ctx.platform, async () => {
966963
bot
@@ -977,7 +974,6 @@ bot.onNewMention(async (thread, message) => {
977974
logger: bot.getLogger("agent"),
978975
onErrorRef: lastStreamErrorRef,
979976
userContext,
980-
toolSet,
981977
});
982978
await postAgentStream(thread, result, ctx, { onErrorRef: lastStreamErrorRef });
983979
});
@@ -1071,7 +1067,6 @@ bot.onSubscribedMessage(async (thread, message) => {
10711067

10721068
const enrichedMessage = await buildEnrichedMessage(resolvedMessage, thread.id);
10731069
const rawHistory = await buildHistory(thread);
1074-
const toolSet = detectToolSet(userMessage, rawHistory);
10751070

10761071
await withTelegramTypingRefresh(thread, ctx.platform, async () => {
10771072
bot
@@ -1088,7 +1083,6 @@ bot.onSubscribedMessage(async (thread, message) => {
10881083
logger: bot.getLogger("agent"),
10891084
onErrorRef: lastStreamErrorRef,
10901085
userContext,
1091-
toolSet,
10921086
});
10931087
await postAgentStream(thread, result, ctx, { onErrorRef: lastStreamErrorRef });
10941088
});

0 commit comments

Comments
 (0)