@mondaydotcomorg/atp-langchain 0.17.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/tools.ts ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * LangChain Integration for Agent Tool Protocol
3
+ *
4
+ * Converts ATP client tools into LangChain DynamicTool instances
5
+ */
6
+
7
+ import {
8
+ AgentToolProtocolClient,
9
+ createToolsFromATPClient,
10
+ type Tool,
11
+ type ClientHooks,
12
+ } from '@mondaydotcomorg/atp-client';
13
+ import { DynamicTool } from '@langchain/core/tools';
14
+
15
+ /**
16
+ * Creates ATP client and returns LangChain-compatible DynamicTool instances
17
+ * The client is automatically connected and ready to use.
18
+ *
19
+ * @param serverUrl - ATP server URL (e.g. 'http://localhost:3333')
20
+ * @param headers - Optional headers for authentication (e.g. { Authorization: 'Bearer token' })
21
+ * @param hooks - Optional hooks for intercepting and modifying client behavior
22
+ * @returns Promise of { client, tools } where tools is an array of LangChain DynamicTools
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const { client, tools } = await createATPTools('http://localhost:3333', {
27
+ * Authorization: 'Bearer api-key'
28
+ * });
29
+ *
30
+ * // Use tools with any LangChain agent
31
+ * const agent = await createReactAgent({ llm, tools, prompt });
32
+ * const executor = new AgentExecutor({ agent, tools });
33
+ * ```
34
+ */
35
+ export async function createATPTools(
36
+ serverUrl: string,
37
+ headers?: Record<string, string>,
38
+ hooks?: ClientHooks
39
+ ) {
40
+ const client = new AgentToolProtocolClient({ baseUrl: serverUrl, headers, hooks });
41
+ await client.connect();
42
+
43
+ const atpTools = createToolsFromATPClient(client);
44
+
45
+ const tools = atpTools.map(
46
+ (tool: Tool) =>
47
+ new DynamicTool({
48
+ name: tool.name,
49
+ description: tool.description || '',
50
+ func: tool.func,
51
+ })
52
+ );
53
+
54
+ return { client, tools };
55
+ }
56
+
57
+ /**
58
+ * Converts generic ATP tools into LangChain DynamicTool instances
59
+ *
60
+ * @param tools - Array of ATP tools (with inputSchema and func)
61
+ * @returns Array of LangChain DynamicTools
62
+ */
63
+ export function convertToLangChainTools(tools: Tool[]): DynamicTool[] {
64
+ return tools.map(
65
+ (tool: Tool) =>
66
+ new DynamicTool({
67
+ name: tool.name,
68
+ description: tool.description || '',
69
+ func: tool.func,
70
+ })
71
+ );
72
+ }