-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Attach knowledge artifact tool conditionally and async tool build
- Loading branch information
Showing
2 changed files
with
79 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
control-plane/src/modules/workflows/agent/tools/cluster-internal-tools.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { DynamicStructuredTool } from "@langchain/core/tools"; | ||
import { Run } from "../../workflows"; | ||
import { | ||
buildAccessKnowledgeArtifacts, | ||
ACCESS_KNOWLEDGE_ARTIFACTS_TOOL_NAME, | ||
} from "./knowledge-artifacts"; | ||
import { createCache } from "../../../../utilities/cache"; | ||
import { getClusterDetails } from "../../../management"; | ||
|
||
const clusterSettingsCache = createCache<{ | ||
enableKnowledgebase: boolean; | ||
}>(Symbol("cluster-settings")); | ||
|
||
const CACHE_TTL = 60 * 2; // 2 minutes | ||
|
||
export type InternalToolBuilder = ( | ||
workflow: Run, | ||
toolCallId: string | ||
) => DynamicStructuredTool | Promise<DynamicStructuredTool>; | ||
|
||
export const getClusterInternalTools = async ( | ||
clusterId: string | ||
): Promise<Record<string, InternalToolBuilder>> => { | ||
const cacheKey = `cluster:${clusterId}`; | ||
|
||
let settings = clusterSettingsCache.get(cacheKey); | ||
|
||
if (!settings) { | ||
// Get cluster settings | ||
const cluster = await getClusterDetails({ clusterId }); | ||
settings = { | ||
enableKnowledgebase: cluster.enableKnowledgebase, | ||
}; | ||
clusterSettingsCache.set(cacheKey, settings, CACHE_TTL); | ||
} | ||
|
||
const tools: Record<string, InternalToolBuilder> = {}; | ||
|
||
// Only include knowledge artifacts tool if enabled for cluster | ||
if (settings.enableKnowledgebase) { | ||
tools[ACCESS_KNOWLEDGE_ARTIFACTS_TOOL_NAME] = buildAccessKnowledgeArtifacts; | ||
} | ||
|
||
return tools; | ||
}; |