Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@langchain/google-vertexai": "workspace:*",
"@langchain/google-vertexai-web": "workspace:*",
"@langchain/groq": "workspace:*",
"@langchain/langgraph": "alpha",
"@langchain/langgraph": "next",
"@langchain/mistralai": "workspace:*",
"@langchain/mongodb": "workspace:*",
"@langchain/nomic": "workspace:*",
Expand Down
100 changes: 100 additions & 0 deletions examples/src/createAgent/middleware/bigTool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import * as z from "zod";
import { createAgent, HumanMessage, AIMessage, tool } from "langchain";
import { bigToolMiddleware } from "langchain/middleware";
import { ChatAnthropic } from "@langchain/anthropic";

/**
* Capture the raw requests to verify the tools are being selected correctly
*/
const requestBodies: any[] = [];
const llm = new ChatAnthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
model: "claude-sonnet-4-20250514",
clientOptions: {
fetch: (url, options) => {
requestBodies.push(JSON.parse(options?.body as string));
return fetch(url, options);
},
},
});

// Example usage
const agent = createAgent({
llm,
tools: [
tool(
({ a, b, operation }: { a: number; b: number; operation: string }) => {
if (operation === "add") {
return a + b;
} else if (operation === "multiply") {
return a * b;
} else if (operation === "subtract") {
return a - b;
} else if (operation === "divide") {
return a / b;
} else {
return "Unknown operation";
}
},
{
name: "calculator",
description: "Perform basic math operations",
schema: z.object({
a: z.number(),
b: z.number(),
operation: z.enum(["add", "multiply", "subtract", "divide"]),
}),
}
),
tool(
() => {
return "Database query result: 42";
},
{
name: "database",
description: "Query a database",
schema: z.object({
query: z.string(),
}),
}
),
],
middleware: [
bigToolMiddleware({
strategy: "custom",
customSelector: (tools, query) => {
if (query.includes("calculator")) {
return tools.filter((tool) => tool.name === "calculator");
} else if (query.includes("database")) {
return tools.filter((tool) => tool.name === "database");
}

return [];
},
maxTools: 1,
}),
] as const,
});

// Usage example with a long chat history for testing caching
const result = await agent.invoke({
messages: [new HumanMessage("Calculate 10 + 20")],
});
console.log(
"Calculate 10 + 20\nAgent response:",
result.messages.at(-1)?.content,
`\nAll available tools: ${requestBodies
.pop()
.tools.map((tool: { name: string }) => tool.name)}`
);

const result2 = await agent.invoke({
messages: [new HumanMessage("Query the database for 42")],
});
console.log(
"\nQuery the database for 42\nAgent response:",
result2.messages.at(-1)?.content,
`\nAll available tools: ${requestBodies
.pop()
.tools.map((tool: { name: string }) => tool.name)}`
);
4 changes: 2 additions & 2 deletions internal/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Shared ESLint configuration for LangChain.js projects",
"author": "LangChain",
"license": "MIT",
"main": "./index.ts",
"types": "./index.ts",
"main": "./src/index.ts",
"types": "./src/index.ts",
"type": "module",
"keywords": [
"eslint",
Expand Down
30 changes: 30 additions & 0 deletions libs/langchain-community/src/load/import_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,37 @@ export * as llms__togetherai from "../llms/togetherai.js";
export * as llms__watsonx_ai from "../llms/watsonx_ai.js";
export * as llms__writer from "../llms/writer.js";
export * as llms__yandex from "../llms/yandex.js";
export * as llms__layerup_security from "../llms/layerup_security.js";
export * as vectorstores__analyticdb from "../vectorstores/analyticdb.js";
export * as vectorstores__astradb from "../vectorstores/astradb.js";
export * as vectorstores__azion_edgesql from "../vectorstores/azion_edgesql.js";
export * as vectorstores__azure_aisearch from "../vectorstores/azure_aisearch.js";
export * as vectorstores__azure_cosmosdb from "../vectorstores/azure_cosmosdb.js";
export * as vectorstores__cassandra from "../vectorstores/cassandra.js";
export * as vectorstores__chroma from "../vectorstores/chroma.js";
export * as vectorstores__clickhouse from "../vectorstores/clickhouse.js";
export * as vectorstores__closevector__node from "../vectorstores/closevector/node.js";
export * as vectorstores__closevector__web from "../vectorstores/closevector/web.js";
export * as vectorstores__cloudflare_vectorize from "../vectorstores/cloudflare_vectorize.js";
export * as vectorstores__convex from "../vectorstores/convex.js";
export * as vectorstores__couchbase_search from "../vectorstores/couchbase_search.js";
export * as vectorstores__elasticsearch from "../vectorstores/elasticsearch.js";
export * as vectorstores__faiss from "../vectorstores/faiss.js";
export * as vectorstores__googlevertexai from "../vectorstores/googlevertexai.js";
export * as vectorstores__hnswlib from "../vectorstores/hnswlib.js";
export * as vectorstores__hanavector from "../vectorstores/hanavector.js";
export * as vectorstores__lancedb from "../vectorstores/lancedb.js";
export * as vectorstores__libsql from "../vectorstores/libsql.js";
export * as vectorstores__mariadb from "../vectorstores/mariadb.js";
export * as vectorstores__milvus from "../vectorstores/milvus.js";
export * as vectorstores__momento_vector_index from "../vectorstores/momento_vector_index.js";
export * as vectorstores__mongodb_atlas from "../vectorstores/mongodb_atlas.js";
export * as vectorstores__myscale from "../vectorstores/myscale.js";
export * as vectorstores__neo4j_vector from "../vectorstores/neo4j_vector.js";
export * as vectorstores__neon from "../vectorstores/neon.js";
export * as vectorstores__opensearch from "../vectorstores/opensearch.js";
export * as vectorstores__pgvector from "../vectorstores/pgvector.js";
export * as vectorstores__pinecone from "../vectorstores/pinecone.js";
export * as vectorstores__prisma from "../vectorstores/prisma.js";
export * as vectorstores__qdrant from "../vectorstores/qdrant.js";
export * as vectorstores__redis from "../vectorstores/redis.js";
Expand Down
11 changes: 1 addition & 10 deletions libs/langchain-core/src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@ export * from "./transformers.js";
export * from "./metadata.js";
export * from "./message.js";
export * from "./modifier.js";
// TODO: Use a star export when we deprecate the
// existing "ToolCall" type in "base.js".
export {
type ToolMessageFields,
ToolMessage,
ToolMessageChunk,
type InvalidToolCall,
isToolMessage,
isToolMessageChunk,
} from "./tool.js";
export * from "./tool.js";

// This is an old export for backwards compatibility with existing multimodal content blocks
// TODO: remove this in v2
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
},
"dependencies": {
"@langchain/textsplitters": "workspace:*",
"@langchain/langgraph": "^1.0.0-alpha",
"@langchain/langgraph": "next",
"@langchain/langgraph-checkpoint": "^0.1.1",
"js-yaml": "^4.1.0",
"jsonpointer": "^5.0.1",
Expand Down
14 changes: 14 additions & 0 deletions libs/langchain/src/agents/interrupt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
export { interrupt } from "@langchain/langgraph";

/**
* Represents information about an interrupt.
*/
export interface Interrupt<TValue = unknown> {
/**
* The ID of the interrupt.
*/
id: string;
/**
* The requests for human input.
*/
value: TValue;
}

/**
* Configuration interface that defines what actions are allowed for a human interrupt.
* This controls the available interaction options when the graph is paused for human input.
Expand Down
Loading
Loading