bigtool-ts 0.1.0
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/CHANGELOG.md +27 -0
- package/LICENSE +21 -0
- package/README.md +641 -0
- package/dist/adapters/agent-protocol.d.ts +149 -0
- package/dist/adapters/agent-protocol.d.ts.map +1 -0
- package/dist/adapters/agent-protocol.js +133 -0
- package/dist/adapters/agent-protocol.js.map +1 -0
- package/dist/adapters/index.d.ts +39 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +42 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/inngest.d.ts +234 -0
- package/dist/adapters/inngest.d.ts.map +1 -0
- package/dist/adapters/inngest.js +276 -0
- package/dist/adapters/inngest.js.map +1 -0
- package/dist/adapters/mastra.d.ts +201 -0
- package/dist/adapters/mastra.d.ts.map +1 -0
- package/dist/adapters/mastra.js +250 -0
- package/dist/adapters/mastra.js.map +1 -0
- package/dist/adapters/types.d.ts +42 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +6 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/adapters/vercel-ai.d.ts +176 -0
- package/dist/adapters/vercel-ai.d.ts.map +1 -0
- package/dist/adapters/vercel-ai.js +244 -0
- package/dist/adapters/vercel-ai.js.map +1 -0
- package/dist/catalog/index.d.ts +177 -0
- package/dist/catalog/index.d.ts.map +1 -0
- package/dist/catalog/index.js +244 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/graph/agent.d.ts +214 -0
- package/dist/graph/agent.d.ts.map +1 -0
- package/dist/graph/agent.js +196 -0
- package/dist/graph/agent.js.map +1 -0
- package/dist/graph/index.d.ts +5 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +4 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/nodes.d.ts +100 -0
- package/dist/graph/nodes.d.ts.map +1 -0
- package/dist/graph/nodes.js +190 -0
- package/dist/graph/nodes.js.map +1 -0
- package/dist/graph/search-tool.d.ts +34 -0
- package/dist/graph/search-tool.d.ts.map +1 -0
- package/dist/graph/search-tool.js +54 -0
- package/dist/graph/search-tool.js.map +1 -0
- package/dist/graph/state.d.ts +26 -0
- package/dist/graph/state.d.ts.map +1 -0
- package/dist/graph/state.js +29 -0
- package/dist/graph/state.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/loader/index.d.ts +172 -0
- package/dist/loader/index.d.ts.map +1 -0
- package/dist/loader/index.js +179 -0
- package/dist/loader/index.js.map +1 -0
- package/dist/loader/loader.d.ts +114 -0
- package/dist/loader/loader.d.ts.map +1 -0
- package/dist/loader/loader.js +185 -0
- package/dist/loader/loader.js.map +1 -0
- package/dist/search/cache.d.ts +76 -0
- package/dist/search/cache.d.ts.map +1 -0
- package/dist/search/cache.js +135 -0
- package/dist/search/cache.js.map +1 -0
- package/dist/search/index.d.ts +63 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +122 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/normalize.d.ts +104 -0
- package/dist/search/normalize.d.ts.map +1 -0
- package/dist/search/normalize.js +211 -0
- package/dist/search/normalize.js.map +1 -0
- package/dist/search/orama.d.ts +256 -0
- package/dist/search/orama.d.ts.map +1 -0
- package/dist/search/orama.js +511 -0
- package/dist/search/orama.js.map +1 -0
- package/dist/search/types.d.ts +96 -0
- package/dist/search/types.d.ts.map +1 -0
- package/dist/search/types.js +8 -0
- package/dist/search/types.js.map +1 -0
- package/dist/sources/dynamic.d.ts +200 -0
- package/dist/sources/dynamic.d.ts.map +1 -0
- package/dist/sources/dynamic.js +194 -0
- package/dist/sources/dynamic.js.map +1 -0
- package/dist/sources/index.d.ts +11 -0
- package/dist/sources/index.d.ts.map +1 -0
- package/dist/sources/index.js +14 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/local.d.ts +128 -0
- package/dist/sources/local.d.ts.map +1 -0
- package/dist/sources/local.js +155 -0
- package/dist/sources/local.js.map +1 -0
- package/dist/sources/mcp.d.ts +438 -0
- package/dist/sources/mcp.d.ts.map +1 -0
- package/dist/sources/mcp.js +438 -0
- package/dist/sources/mcp.js.map +1 -0
- package/dist/sources/types.d.ts +16 -0
- package/dist/sources/types.d.ts.map +1 -0
- package/dist/sources/types.js +7 -0
- package/dist/sources/types.js.map +1 -0
- package/dist/sources/with-metadata.d.ts +7 -0
- package/dist/sources/with-metadata.d.ts.map +1 -0
- package/dist/sources/with-metadata.js +7 -0
- package/dist/sources/with-metadata.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types.d.ts +700 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +97 -0
- package/dist/types.js.map +1 -0
- package/package.json +118 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph Nodes
|
|
3
|
+
*
|
|
4
|
+
* Node factories for the BigTool LangGraph agent.
|
|
5
|
+
*/
|
|
6
|
+
import { isAIMessage, SystemMessage, ToolMessage, } from "@langchain/core/messages";
|
|
7
|
+
import { ToolNode } from "@langchain/langgraph/prebuilt";
|
|
8
|
+
/**
|
|
9
|
+
* Creates the agent node that invokes the LLM with bound tools.
|
|
10
|
+
*
|
|
11
|
+
* The agent always has access to:
|
|
12
|
+
* 1. search_tools - for discovering new tools
|
|
13
|
+
* 2. pinnedTools - always available tools
|
|
14
|
+
* 3. selectedTools - tools discovered via search
|
|
15
|
+
*
|
|
16
|
+
* @param config - Agent node configuration
|
|
17
|
+
* @returns A node function for the StateGraph
|
|
18
|
+
*/
|
|
19
|
+
export function createAgentNode(config) {
|
|
20
|
+
const { llm, loader, pinnedTools, searchTool, systemPrompt } = config;
|
|
21
|
+
return async (state, runnableConfig) => {
|
|
22
|
+
// Load selected tools from the loader
|
|
23
|
+
const selectedTools = await Promise.all(state.selectedToolIds.map(async (id) => {
|
|
24
|
+
try {
|
|
25
|
+
return await loader.load(id);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Tool might have been removed - skip it
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
// Filter out nulls (failed loads)
|
|
33
|
+
const loadedSelectedTools = selectedTools.filter((t) => t !== null);
|
|
34
|
+
// Combine all tools: search_tools + pinned + selected
|
|
35
|
+
const allTools = [searchTool, ...pinnedTools, ...loadedSelectedTools];
|
|
36
|
+
// Bind tools to the LLM
|
|
37
|
+
if (!llm.bindTools) {
|
|
38
|
+
throw new Error('LLM does not support tool binding');
|
|
39
|
+
}
|
|
40
|
+
const modelWithTools = llm.bindTools(allTools);
|
|
41
|
+
// Prepare messages with optional system prompt
|
|
42
|
+
let messages = state.messages;
|
|
43
|
+
if (systemPrompt &&
|
|
44
|
+
(messages.length === 0 || messages[0]._getType() !== "system")) {
|
|
45
|
+
messages = [new SystemMessage(systemPrompt), ...messages];
|
|
46
|
+
}
|
|
47
|
+
// Invoke the LLM
|
|
48
|
+
const response = await modelWithTools.invoke(messages, runnableConfig);
|
|
49
|
+
return { messages: [response] };
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates the search node that executes search_tools calls.
|
|
54
|
+
*
|
|
55
|
+
* This node:
|
|
56
|
+
* 1. Extracts search_tools calls from the last message
|
|
57
|
+
* 2. Executes searches against the index
|
|
58
|
+
* 3. Updates selectedToolIds with found tools
|
|
59
|
+
* 4. Returns ToolMessages with search results
|
|
60
|
+
*
|
|
61
|
+
* @param config - Search node configuration
|
|
62
|
+
* @returns A node function for the StateGraph
|
|
63
|
+
*/
|
|
64
|
+
export function createSearchNode(config) {
|
|
65
|
+
const { index, catalog, searchLimit = 5 } = config;
|
|
66
|
+
return async (state, _runnableConfig) => {
|
|
67
|
+
const lastMessage = state.messages[state.messages.length - 1];
|
|
68
|
+
// Verify we have an AI message with tool calls
|
|
69
|
+
if (!isAIMessage(lastMessage) || !lastMessage.tool_calls?.length) {
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
const toolMessages = [];
|
|
73
|
+
const newToolIds = [];
|
|
74
|
+
const searchQueries = [];
|
|
75
|
+
// Process each tool call
|
|
76
|
+
for (const toolCall of lastMessage.tool_calls) {
|
|
77
|
+
// Only handle search_tools calls
|
|
78
|
+
if (toolCall.name !== "search_tools") {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const { query } = toolCall.args;
|
|
82
|
+
// Execute the search
|
|
83
|
+
const results = await index.search(query, { limit: searchLimit });
|
|
84
|
+
const foundIds = results.map((r) => r.toolId);
|
|
85
|
+
newToolIds.push(...foundIds);
|
|
86
|
+
// Record the search for history
|
|
87
|
+
searchQueries.push({
|
|
88
|
+
query,
|
|
89
|
+
results: foundIds,
|
|
90
|
+
timestamp: Date.now(),
|
|
91
|
+
});
|
|
92
|
+
// Format the response for the LLM
|
|
93
|
+
let content;
|
|
94
|
+
if (foundIds.length === 0) {
|
|
95
|
+
content = `No tools found matching "${query}". Try a different search query.`;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const toolDescriptions = foundIds
|
|
99
|
+
.map((id) => {
|
|
100
|
+
const meta = catalog.getMetadata(id);
|
|
101
|
+
return meta ? `- **${meta.name}**: ${meta.description}` : null;
|
|
102
|
+
})
|
|
103
|
+
.filter(Boolean)
|
|
104
|
+
.join("\n");
|
|
105
|
+
content = `Found ${foundIds.length} tool${foundIds.length === 1 ? "" : "s"}:\n${toolDescriptions}\n\nYou can now use these tools.`;
|
|
106
|
+
}
|
|
107
|
+
toolMessages.push(new ToolMessage({
|
|
108
|
+
content,
|
|
109
|
+
tool_call_id: toolCall.id ?? "",
|
|
110
|
+
name: "search_tools",
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
messages: toolMessages,
|
|
115
|
+
selectedToolIds: newToolIds,
|
|
116
|
+
searchHistory: searchQueries,
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Creates the execute node that runs selected tools.
|
|
122
|
+
*
|
|
123
|
+
* Uses LangGraph's ToolNode to execute tool calls from the last message.
|
|
124
|
+
* Tools are loaded from the loader + pinnedTools.
|
|
125
|
+
*
|
|
126
|
+
* @param config - Execute node configuration
|
|
127
|
+
* @returns A node function for the StateGraph
|
|
128
|
+
*/
|
|
129
|
+
export function createExecuteNode(config) {
|
|
130
|
+
const { loader, pinnedTools } = config;
|
|
131
|
+
return async (state, runnableConfig) => {
|
|
132
|
+
// Load selected tools
|
|
133
|
+
const selectedTools = await Promise.all(state.selectedToolIds.map(async (id) => {
|
|
134
|
+
try {
|
|
135
|
+
return await loader.load(id);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}));
|
|
141
|
+
const loadedSelectedTools = selectedTools.filter((t) => t !== null);
|
|
142
|
+
// Create ToolNode with all available tools
|
|
143
|
+
const allTools = [...pinnedTools, ...loadedSelectedTools];
|
|
144
|
+
const toolNode = new ToolNode(allTools);
|
|
145
|
+
// Execute the tools
|
|
146
|
+
const result = await toolNode.invoke(state, runnableConfig);
|
|
147
|
+
return result;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
151
|
+
// LEGACY EXPORTS (for backwards compatibility)
|
|
152
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
153
|
+
/**
|
|
154
|
+
* @deprecated Use createSearchNode instead
|
|
155
|
+
*/
|
|
156
|
+
export async function searchNode(_state, _config) {
|
|
157
|
+
throw new Error("searchNode: Use createSearchNode factory to create a configured node");
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Routing function - determines next node based on last message.
|
|
161
|
+
*
|
|
162
|
+
* Returns:
|
|
163
|
+
* - "search" if agent called search_tools
|
|
164
|
+
* - "execute" if agent called other tools
|
|
165
|
+
* - "end" if agent responded without tool calls
|
|
166
|
+
*/
|
|
167
|
+
export function routeNode(state) {
|
|
168
|
+
const lastMessage = state.messages[state.messages.length - 1];
|
|
169
|
+
if (!lastMessage) {
|
|
170
|
+
return "end";
|
|
171
|
+
}
|
|
172
|
+
// Check if it's an AI message
|
|
173
|
+
if (!isAIMessage(lastMessage)) {
|
|
174
|
+
return "end";
|
|
175
|
+
}
|
|
176
|
+
// Check for tool calls
|
|
177
|
+
if (!lastMessage.tool_calls || lastMessage.tool_calls.length === 0) {
|
|
178
|
+
return "end";
|
|
179
|
+
}
|
|
180
|
+
// Check if it's a search request
|
|
181
|
+
const hasSearchCall = lastMessage.tool_calls.some((tc) => tc.name === "search_tools");
|
|
182
|
+
return hasSearchCall ? "search" : "execute";
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* @deprecated Use createExecuteNode instead
|
|
186
|
+
*/
|
|
187
|
+
export async function executeNode(_state, _config) {
|
|
188
|
+
throw new Error("executeNode: Use createExecuteNode factory to create a configured node");
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../src/graph/nodes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,WAAW,EACX,aAAa,EACb,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAiCzD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuB;IACrD,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAEtE,OAAO,KAAK,EACV,KAAyB,EACzB,cAA8B,EACS,EAAE;QACzC,sCAAsC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UAAU,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,iCAAiC;IACjC,MAAM,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,CAC/C,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,cAAc,CACnC,CAAC;IAEF,OAAO,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAA0B,EAC1B,OAAuB;IAEvB,MAAM,IAAI,KAAK,CACb,wEAAwE,CACzE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* search_tools Tool
|
|
3
|
+
*
|
|
4
|
+
* The dynamic tool that allows the LLM to discover relevant tools
|
|
5
|
+
* by searching through the tool catalog.
|
|
6
|
+
*/
|
|
7
|
+
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
8
|
+
import type { SearchIndex, ToolCatalog } from "../types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for creating the search_tools tool
|
|
11
|
+
*/
|
|
12
|
+
export interface CreateSearchToolsToolConfig {
|
|
13
|
+
/** The search index for finding tools */
|
|
14
|
+
index: SearchIndex;
|
|
15
|
+
/** The tool catalog for getting metadata */
|
|
16
|
+
catalog: ToolCatalog;
|
|
17
|
+
/** Maximum number of results to return */
|
|
18
|
+
limit?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates the search_tools DynamicStructuredTool.
|
|
22
|
+
*
|
|
23
|
+
* This tool is always bound to the LLM and allows it to discover
|
|
24
|
+
* relevant tools based on what it needs to accomplish.
|
|
25
|
+
*
|
|
26
|
+
* @param config - Configuration for the search tool
|
|
27
|
+
* @returns A DynamicStructuredTool for searching tools
|
|
28
|
+
*/
|
|
29
|
+
export declare function createSearchToolsTool(config: CreateSearchToolsToolConfig): DynamicStructuredTool;
|
|
30
|
+
/**
|
|
31
|
+
* Type of the search_tools tool
|
|
32
|
+
*/
|
|
33
|
+
export type SearchToolsTool = ReturnType<typeof createSearchToolsTool>;
|
|
34
|
+
//# sourceMappingURL=search-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-tool.d.ts","sourceRoot":"","sources":["../../src/graph/search-tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAW5D;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,yCAAyC;IACzC,KAAK,EAAE,WAAW,CAAC;IACnB,4CAA4C;IAC5C,OAAO,EAAE,WAAW,CAAC;IACrB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,2BAA2B,GAClC,qBAAqB,CAgCvB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* search_tools Tool
|
|
3
|
+
*
|
|
4
|
+
* The dynamic tool that allows the LLM to discover relevant tools
|
|
5
|
+
* by searching through the tool catalog.
|
|
6
|
+
*/
|
|
7
|
+
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
/**
|
|
10
|
+
* Schema for the search_tools input
|
|
11
|
+
*/
|
|
12
|
+
const SearchToolsSchema = z.object({
|
|
13
|
+
query: z.string().describe("Search query to find relevant tools. Use natural language like 'github', 'send message', 'create file'"),
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Creates the search_tools DynamicStructuredTool.
|
|
17
|
+
*
|
|
18
|
+
* This tool is always bound to the LLM and allows it to discover
|
|
19
|
+
* relevant tools based on what it needs to accomplish.
|
|
20
|
+
*
|
|
21
|
+
* @param config - Configuration for the search tool
|
|
22
|
+
* @returns A DynamicStructuredTool for searching tools
|
|
23
|
+
*/
|
|
24
|
+
export function createSearchToolsTool(config) {
|
|
25
|
+
const { index, catalog, limit = 5 } = config;
|
|
26
|
+
return new DynamicStructuredTool({
|
|
27
|
+
name: "search_tools",
|
|
28
|
+
description: `Search for relevant tools based on what you need to accomplish.
|
|
29
|
+
Use this when you need to find tools for a specific task.
|
|
30
|
+
Example queries: "github", "send message", "create file", "database query"
|
|
31
|
+
|
|
32
|
+
After searching, the found tools will become available for you to use.`,
|
|
33
|
+
schema: SearchToolsSchema,
|
|
34
|
+
func: async ({ query }) => {
|
|
35
|
+
// Execute the search
|
|
36
|
+
const results = await index.search(query, { limit });
|
|
37
|
+
if (results.length === 0) {
|
|
38
|
+
return `No tools found matching "${query}". Try a different search query.`;
|
|
39
|
+
}
|
|
40
|
+
// Format the results with descriptions
|
|
41
|
+
const descriptions = results
|
|
42
|
+
.map((result) => {
|
|
43
|
+
const meta = catalog.getMetadata(result.toolId);
|
|
44
|
+
if (!meta)
|
|
45
|
+
return null;
|
|
46
|
+
return `- **${meta.name}**: ${meta.description}`;
|
|
47
|
+
})
|
|
48
|
+
.filter(Boolean)
|
|
49
|
+
.join("\n");
|
|
50
|
+
return `Found ${results.length} tool${results.length === 1 ? "" : "s"}:\n${descriptions}\n\nYou can now use these tools.`;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=search-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-tool.js","sourceRoot":"","sources":["../../src/graph/search-tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAE,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AAE,CAAC,CAAC,CAAC,GAAG,MAAM,YAAY,kCAAkC,CAAC;QAC5H,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
/**
|
|
3
|
+
* Search query recorded in history
|
|
4
|
+
*/
|
|
5
|
+
export interface SearchQuery {
|
|
6
|
+
query: string;
|
|
7
|
+
results: string[];
|
|
8
|
+
timestamp: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* State annotation for the tool discovery graph.
|
|
12
|
+
*
|
|
13
|
+
* Tracks conversation messages, currently selected tools,
|
|
14
|
+
* and search history for context.
|
|
15
|
+
*/
|
|
16
|
+
export declare const ToolDiscoveryAnnotation: import("@langchain/langgraph").AnnotationRoot<{
|
|
17
|
+
/** Conversation messages with automatic message merging */
|
|
18
|
+
messages: import("@langchain/langgraph").BinaryOperatorAggregate<BaseMessage<import("@langchain/core/messages").MessageStructure<import("@langchain/core/messages").MessageToolSet>, import("@langchain/core/messages").MessageType>[], BaseMessage<import("@langchain/core/messages").MessageStructure<import("@langchain/core/messages").MessageToolSet>, import("@langchain/core/messages").MessageType>[]>;
|
|
19
|
+
/** Currently selected tool IDs (available to the agent) */
|
|
20
|
+
selectedToolIds: import("@langchain/langgraph").BinaryOperatorAggregate<string[], string[]>;
|
|
21
|
+
/** History of search queries for context */
|
|
22
|
+
searchHistory: import("@langchain/langgraph").BinaryOperatorAggregate<SearchQuery[], SearchQuery[]>;
|
|
23
|
+
}>;
|
|
24
|
+
export type ToolDiscoveryState = typeof ToolDiscoveryAnnotation.State;
|
|
25
|
+
export type ToolDiscoveryUpdate = typeof ToolDiscoveryAnnotation.Update;
|
|
26
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/graph/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;IAClC,2DAA2D;;IAM3D,2DAA2D;;IAU3D,4CAA4C;;EAK5C,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,OAAO,uBAAuB,CAAC,KAAK,CAAC;AACtE,MAAM,MAAM,mBAAmB,GAAG,OAAO,uBAAuB,CAAC,MAAM,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Annotation, messagesStateReducer } from '@langchain/langgraph';
|
|
2
|
+
/**
|
|
3
|
+
* State annotation for the tool discovery graph.
|
|
4
|
+
*
|
|
5
|
+
* Tracks conversation messages, currently selected tools,
|
|
6
|
+
* and search history for context.
|
|
7
|
+
*/
|
|
8
|
+
export const ToolDiscoveryAnnotation = Annotation.Root({
|
|
9
|
+
/** Conversation messages with automatic message merging */
|
|
10
|
+
messages: Annotation({
|
|
11
|
+
reducer: messagesStateReducer,
|
|
12
|
+
default: () => [],
|
|
13
|
+
}),
|
|
14
|
+
/** Currently selected tool IDs (available to the agent) */
|
|
15
|
+
selectedToolIds: Annotation({
|
|
16
|
+
reducer: (current, update) => {
|
|
17
|
+
// Deduplicate tool IDs
|
|
18
|
+
const set = new Set([...current, ...update]);
|
|
19
|
+
return Array.from(set);
|
|
20
|
+
},
|
|
21
|
+
default: () => [],
|
|
22
|
+
}),
|
|
23
|
+
/** History of search queries for context */
|
|
24
|
+
searchHistory: Annotation({
|
|
25
|
+
reducer: (current, update) => [...current, ...update],
|
|
26
|
+
default: () => [],
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/graph/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAYxE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAC,IAAI,CAAC;IACrD,2DAA2D;IAC3D,QAAQ,EAAE,UAAU,CAAgB;QAClC,OAAO,EAAE,oBAAoB;QAC7B,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;IAEF,2DAA2D;IAC3D,eAAe,EAAE,UAAU,CAAW;QACpC,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3B,uBAAuB;YACvB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC;YAC7C,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;IAEF,4CAA4C;IAC5C,aAAa,EAAE,UAAU,CAAgB;QACvC,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC;QACrD,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;CACH,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @repo/bigtool-ts
|
|
3
|
+
*
|
|
4
|
+
* BigTool-TS: Dynamic tool discovery and management for LangGraph agents.
|
|
5
|
+
*
|
|
6
|
+
* This package provides a complete system for managing large tool collections
|
|
7
|
+
* with intelligent search-based discovery. Instead of loading all tools into
|
|
8
|
+
* the LLM context, agents can search for and load tools on demand.
|
|
9
|
+
*
|
|
10
|
+
* ## Core Concepts
|
|
11
|
+
*
|
|
12
|
+
* - **ToolSource**: Provides tools from a specific origin (local, MCP server, dynamic)
|
|
13
|
+
* - **ToolCatalog**: Registry that aggregates tools from multiple sources
|
|
14
|
+
* - **SearchIndex**: Enables fast tool discovery via text or semantic search
|
|
15
|
+
* - **ToolLoader**: Lazy-loads tool implementations with LRU caching
|
|
16
|
+
*
|
|
17
|
+
* ## Quick Start
|
|
18
|
+
*
|
|
19
|
+
* @example Basic usage with local tools
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { createAgent, OramaSearch } from '@repo/bigtool-ts';
|
|
22
|
+
* import { ChatOpenAI } from '@langchain/openai';
|
|
23
|
+
*
|
|
24
|
+
* const agent = await createAgent({
|
|
25
|
+
* llm: new ChatOpenAI({ model: 'gpt-4o' }),
|
|
26
|
+
* tools: [myTool1, myTool2, myTool3],
|
|
27
|
+
* search: new OramaSearch(),
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* const result = await agent.invoke({
|
|
31
|
+
* messages: [{ role: 'user', content: 'Create a GitHub PR' }]
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Advanced usage with multiple sources
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import {
|
|
38
|
+
* createAgent,
|
|
39
|
+
* LocalSource,
|
|
40
|
+
* MCPSource,
|
|
41
|
+
* OramaSearch,
|
|
42
|
+
* } from '@repo/bigtool-ts';
|
|
43
|
+
*
|
|
44
|
+
* const agent = await createAgent({
|
|
45
|
+
* llm: new ChatOpenAI({ model: 'gpt-4o' }),
|
|
46
|
+
* sources: [
|
|
47
|
+
* new LocalSource(myLocalTools),
|
|
48
|
+
* new MCPSource(mcpClient, { namespace: 'github' }),
|
|
49
|
+
* ],
|
|
50
|
+
* search: new OramaSearch({ mode: 'hybrid', embeddings }),
|
|
51
|
+
* pinnedTools: [alwaysAvailableTool],
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @packageDocumentation
|
|
56
|
+
*/
|
|
57
|
+
export { createAgent, createToolDiscoveryGraph } from './graph/agent.js';
|
|
58
|
+
export type { CreateAgentOptions } from './graph/agent.js';
|
|
59
|
+
export type { ToolSource, ToolMetadata, ToolCatalog, ToolsChangedEvent, SearchIndex, SearchOptions, SearchResult, ToolLoader, EventEmitter, EventHandler, Unsubscribe, ToolEnhancement, EnhancedTool, } from './types.js';
|
|
60
|
+
export { createEventEmitter, withMetadata } from './types.js';
|
|
61
|
+
export { LocalSource } from './sources/local.js';
|
|
62
|
+
export { MCPSource, createMCPSource, type MCPSourceOptions, type MCPClient, type MCPServerConfig, type MCPStdioConfig, type MCPSSEConfig, type MCPWebSocketConfig, } from './sources/mcp.js';
|
|
63
|
+
export { DynamicSource, type DynamicSourceOptions } from './sources/dynamic.js';
|
|
64
|
+
export { DefaultToolCatalog } from './catalog/index.js';
|
|
65
|
+
export { OramaSearch, type OramaSearchConfig } from './search/index.js';
|
|
66
|
+
export { DefaultToolLoader, type ToolLoaderOptions } from './loader/index.js';
|
|
67
|
+
export { ToolDiscoveryAnnotation, type ToolDiscoveryState, type ToolDiscoveryUpdate, type SearchQuery } from './graph/state.js';
|
|
68
|
+
export { searchNode, routeNode, executeNode } from './graph/nodes.js';
|
|
69
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAMH,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACzE,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAM3D,YAAY,EAEV,UAAU,EACV,YAAY,EAGZ,WAAW,EACX,iBAAiB,EAGjB,WAAW,EACX,aAAa,EACb,YAAY,EAGZ,UAAU,EAGV,YAAY,EACZ,YAAY,EACZ,WAAW,EAGX,eAAe,EACf,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM9D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EACL,SAAS,EACT,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,kBAAkB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAMhF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAMxD,OAAO,EAAE,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAMxE,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAM9E,OAAO,EAAE,uBAAuB,EAAE,KAAK,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChI,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @repo/bigtool-ts
|
|
3
|
+
*
|
|
4
|
+
* BigTool-TS: Dynamic tool discovery and management for LangGraph agents.
|
|
5
|
+
*
|
|
6
|
+
* This package provides a complete system for managing large tool collections
|
|
7
|
+
* with intelligent search-based discovery. Instead of loading all tools into
|
|
8
|
+
* the LLM context, agents can search for and load tools on demand.
|
|
9
|
+
*
|
|
10
|
+
* ## Core Concepts
|
|
11
|
+
*
|
|
12
|
+
* - **ToolSource**: Provides tools from a specific origin (local, MCP server, dynamic)
|
|
13
|
+
* - **ToolCatalog**: Registry that aggregates tools from multiple sources
|
|
14
|
+
* - **SearchIndex**: Enables fast tool discovery via text or semantic search
|
|
15
|
+
* - **ToolLoader**: Lazy-loads tool implementations with LRU caching
|
|
16
|
+
*
|
|
17
|
+
* ## Quick Start
|
|
18
|
+
*
|
|
19
|
+
* @example Basic usage with local tools
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { createAgent, OramaSearch } from '@repo/bigtool-ts';
|
|
22
|
+
* import { ChatOpenAI } from '@langchain/openai';
|
|
23
|
+
*
|
|
24
|
+
* const agent = await createAgent({
|
|
25
|
+
* llm: new ChatOpenAI({ model: 'gpt-4o' }),
|
|
26
|
+
* tools: [myTool1, myTool2, myTool3],
|
|
27
|
+
* search: new OramaSearch(),
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* const result = await agent.invoke({
|
|
31
|
+
* messages: [{ role: 'user', content: 'Create a GitHub PR' }]
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Advanced usage with multiple sources
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import {
|
|
38
|
+
* createAgent,
|
|
39
|
+
* LocalSource,
|
|
40
|
+
* MCPSource,
|
|
41
|
+
* OramaSearch,
|
|
42
|
+
* } from '@repo/bigtool-ts';
|
|
43
|
+
*
|
|
44
|
+
* const agent = await createAgent({
|
|
45
|
+
* llm: new ChatOpenAI({ model: 'gpt-4o' }),
|
|
46
|
+
* sources: [
|
|
47
|
+
* new LocalSource(myLocalTools),
|
|
48
|
+
* new MCPSource(mcpClient, { namespace: 'github' }),
|
|
49
|
+
* ],
|
|
50
|
+
* search: new OramaSearch({ mode: 'hybrid', embeddings }),
|
|
51
|
+
* pinnedTools: [alwaysAvailableTool],
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @packageDocumentation
|
|
56
|
+
*/
|
|
57
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
58
|
+
// MAIN API
|
|
59
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
60
|
+
export { createAgent, createToolDiscoveryGraph } from './graph/agent.js';
|
|
61
|
+
export { createEventEmitter, withMetadata } from './types.js';
|
|
62
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
63
|
+
// SOURCES
|
|
64
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
65
|
+
export { LocalSource } from './sources/local.js';
|
|
66
|
+
export { MCPSource, createMCPSource, } from './sources/mcp.js';
|
|
67
|
+
export { DynamicSource } from './sources/dynamic.js';
|
|
68
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
69
|
+
// CATALOG
|
|
70
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
71
|
+
export { DefaultToolCatalog } from './catalog/index.js';
|
|
72
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
73
|
+
// SEARCH
|
|
74
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
75
|
+
export { OramaSearch } from './search/index.js';
|
|
76
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
77
|
+
// LOADER
|
|
78
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
79
|
+
export { DefaultToolLoader } from './loader/index.js';
|
|
80
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
81
|
+
// GRAPH
|
|
82
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
83
|
+
export { ToolDiscoveryAnnotation } from './graph/state.js';
|
|
84
|
+
export { searchNode, routeNode, executeNode } from './graph/nodes.js';
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH,sEAAsE;AACtE,WAAW;AACX,sEAAsE;AAEtE,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAkCzE,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,sEAAsE;AACtE,UAAU;AACV,sEAAsE;AAEtE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EACL,SAAS,EACT,eAAe,GAOhB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAA6B,MAAM,sBAAsB,CAAC;AAEhF,sEAAsE;AACtE,UAAU;AACV,sEAAsE;AAEtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,sEAAsE;AACtE,SAAS;AACT,sEAAsE;AAEtE,OAAO,EAAE,WAAW,EAA0B,MAAM,mBAAmB,CAAC;AAExE,sEAAsE;AACtE,SAAS;AACT,sEAAsE;AAEtE,OAAO,EAAE,iBAAiB,EAA0B,MAAM,mBAAmB,CAAC;AAE9E,sEAAsE;AACtE,QAAQ;AACR,sEAAsE;AAEtE,OAAO,EAAE,uBAAuB,EAAuE,MAAM,kBAAkB,CAAC;AAChI,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
|