Skip to content

Commit

Permalink
feat: Integrate current date-time tool
Browse files Browse the repository at this point in the history
  • Loading branch information
nadeesha committed Nov 29, 2024
1 parent fed85c6 commit c0f7963
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions control-plane/src/modules/workflows/agent/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import {
buildAccessKnowledgeArtifacts,
} from "./tools/knowledge-artifacts";
import { buildMockFunctionTool } from "./tools/mock-function";
import { events } from "../../observability/events";
import { getClusterInternalTools } from "./tools/cluster-internal-tools";
import { buildCurrentDateTimeTool } from "./tools/date-time";
import { CURRENT_DATE_TIME_TOOL_NAME } from "./tools/date-time";

/**
* Run a workflow from the most recent saved state
Expand Down Expand Up @@ -315,13 +316,18 @@ export const findRelevantTools = async (state: WorkflowAgentState) => {
// If functions are explicitly attached, skip relevant tools search
if (attachedFunctions.length > 0) {
for (const tool of attachedFunctions) {
if (tool.toLowerCase().startsWith("inferable")) {
if (tool.toLowerCase().startsWith("inferable_")) {
const internalToolName = tool.split("_")[1];

if (internalToolName === ACCESS_KNOWLEDGE_ARTIFACTS_TOOL_NAME) {
tools.push(await buildAccessKnowledgeArtifacts(workflow));
continue;
}

if (internalToolName === CURRENT_DATE_TIME_TOOL_NAME) {
tools.push(buildCurrentDateTimeTool());
continue;
}
}

const serviceFunctionDetails = await embeddableServiceFunction.getEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
} from "./knowledge-artifacts";
import { createCache } from "../../../../utilities/cache";
import { getClusterDetails } from "../../../management";
import {
buildCurrentDateTimeTool,
CURRENT_DATE_TIME_TOOL_NAME,
} from "./date-time";

const clusterSettingsCache = createCache<{
enableKnowledgebase: boolean;
Expand Down Expand Up @@ -41,5 +45,7 @@ export const getClusterInternalTools = async (
tools[ACCESS_KNOWLEDGE_ARTIFACTS_TOOL_NAME] = buildAccessKnowledgeArtifacts;
}

tools[CURRENT_DATE_TIME_TOOL_NAME] = buildCurrentDateTimeTool;

return tools;
};
14 changes: 14 additions & 0 deletions control-plane/src/modules/workflows/agent/tools/date-time.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { z } from "zod";
import { DynamicStructuredTool } from "@langchain/core/tools";

export const CURRENT_DATE_TIME_TOOL_NAME = "currentDateTime";

export const buildCurrentDateTimeTool = (): DynamicStructuredTool =>
new DynamicStructuredTool({
name: CURRENT_DATE_TIME_TOOL_NAME,
description: "Retrieves the current date and time in ISO 8601 format.",
schema: z.object({}),
func: async () => {
return new Date().toISOString();
},
});

0 comments on commit c0f7963

Please sign in to comment.