@loopman/langchain-sdk 1.12.3 → 1.14.1
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/dist/agents/loopman-agent.js +5 -5
- package/dist/client/loopman-api.js +1 -1
- package/dist/index.js +11 -11
- package/dist/langgraph/index.js +5 -5
- package/dist/langgraph/loopman-context-node.js +1 -1
- package/dist/langgraph/loopman-validation-node.js +2 -2
- package/dist/loopman-middleware.js +1 -1
- package/dist/services/index.js +3 -3
- package/dist/services/loopman.service.js +3 -3
- package/dist/templates.json +3 -3
- package/examples/README.md +103 -31
- package/examples/templates/langchain-full-review/package.json +1 -1
- package/examples/templates/langchain-tool-validation/package.json +1 -1
- package/examples/templates/langgraph-hello-world/package.json +1 -1
- package/package.json +12 -3
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createAgent } from "langchain";
|
|
2
|
-
import { buildLoopmanSystemPrompt, extractConfidence, extractTaskId, } from "../helpers/prompt-orchestrator";
|
|
3
|
-
import { loopmanMiddleware } from "../loopman-middleware";
|
|
4
|
-
import { LoopmanMcpClient } from "../mcp/loopman-mcp-client";
|
|
5
|
-
import { LoopmanToolRegistry } from "../mcp/tool-registry";
|
|
6
|
-
import { LoopmanService } from "../services/loopman.service";
|
|
2
|
+
import { buildLoopmanSystemPrompt, extractConfidence, extractTaskId, } from "../helpers/prompt-orchestrator.js";
|
|
3
|
+
import { loopmanMiddleware } from "../loopman-middleware.js";
|
|
4
|
+
import { LoopmanMcpClient } from "../mcp/loopman-mcp-client.js";
|
|
5
|
+
import { LoopmanToolRegistry } from "../mcp/tool-registry.js";
|
|
6
|
+
import { LoopmanService } from "../services/loopman.service.js";
|
|
7
7
|
export class LoopmanAgent {
|
|
8
8
|
config;
|
|
9
9
|
hasFixedExecutionId;
|
package/dist/index.js
CHANGED
|
@@ -4,25 +4,25 @@
|
|
|
4
4
|
* LangChain middleware for Human-in-the-Loop validation via Loopman platform
|
|
5
5
|
*/
|
|
6
6
|
// Middleware exports
|
|
7
|
-
export { loopmanMiddleware } from "./loopman-middleware";
|
|
7
|
+
export { loopmanMiddleware } from "./loopman-middleware.js";
|
|
8
8
|
// Agent helper exports (optional auto-retry on human feedback)
|
|
9
9
|
export { createLoopmanAgent as createLoopmanAgentWrapper, createLoopmanAgent as deprecatedCreateLoopmanAgent, invokeWithRetry, // Recommended: explicit retry helper for invoke()
|
|
10
|
-
streamWithRetry, } from "./loopman-agent-wrapper";
|
|
10
|
+
streamWithRetry, } from "./loopman-agent-wrapper.js";
|
|
11
11
|
// New Agent implementation (MCP + HITL)
|
|
12
|
-
export { createLoopmanAgent, LoopmanAgent } from "./agents/loopman-agent";
|
|
12
|
+
export { createLoopmanAgent, LoopmanAgent } from "./agents/loopman-agent.js";
|
|
13
13
|
// Prompt helpers
|
|
14
|
-
export { buildLoopmanSystemPrompt, extractConfidence, extractTaskId, } from "./helpers/prompt-orchestrator";
|
|
14
|
+
export { buildLoopmanSystemPrompt, extractConfidence, extractTaskId, } from "./helpers/prompt-orchestrator.js";
|
|
15
15
|
// Template generator (for Node.js/server-side)
|
|
16
|
-
export { getLangGraphHelloWorldTemplate, getLangChainToolValidationTemplate, getLangChainFullReviewTemplate, } from "./helpers/template-generator";
|
|
16
|
+
export { getLangGraphHelloWorldTemplate, getLangChainToolValidationTemplate, getLangChainFullReviewTemplate, } from "./helpers/template-generator.js";
|
|
17
17
|
// Template generator static (for web/browser)
|
|
18
|
-
export { getLangGraphHelloWorldTemplate as getLangGraphHelloWorldTemplateStatic, } from "./helpers/template-generator-static";
|
|
18
|
+
export { getLangGraphHelloWorldTemplate as getLangGraphHelloWorldTemplateStatic, } from "./helpers/template-generator-static.js";
|
|
19
19
|
// MCP utilities
|
|
20
|
-
export { LoopmanMcpClient } from "./mcp/loopman-mcp-client";
|
|
20
|
+
export { LoopmanMcpClient } from "./mcp/loopman-mcp-client.js";
|
|
21
21
|
// LangGraph integration (re-export from centralized index)
|
|
22
|
-
export { LoopmanGraphState, createLoopmanValidationNode, createLoopmanConditionalEdge, createLoopmanContextNode, enrichSystemPrompt, formatGuidelines, formatDecisionContext, hasLoopmanContext, getCriticalGuidelines, getLatestDecision, } from "./langgraph";
|
|
22
|
+
export { LoopmanGraphState, createLoopmanValidationNode, createLoopmanConditionalEdge, createLoopmanContextNode, enrichSystemPrompt, formatGuidelines, formatDecisionContext, hasLoopmanContext, getCriticalGuidelines, getLatestDecision, } from "./langgraph.js";
|
|
23
23
|
// Client exports
|
|
24
|
-
export { LoopmanApiClient } from "./client/loopman-api";
|
|
24
|
+
export { LoopmanApiClient } from "./client/loopman-api.js";
|
|
25
25
|
// Service exports (import from services/index.ts for centralized exports)
|
|
26
|
-
export * from "./services";
|
|
27
|
-
export { LoopmanConnectionError, LoopmanError, LoopmanTimeoutError, LoopmanValidationError, } from "./types";
|
|
26
|
+
export * from "./services.js";
|
|
27
|
+
export { LoopmanConnectionError, LoopmanError, LoopmanTimeoutError, LoopmanValidationError, } from "./types.js";
|
|
28
28
|
//# sourceMappingURL=index.js.map
|
package/dist/langgraph/index.js
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* Human-in-the-Loop validation into your workflows.
|
|
6
6
|
*/
|
|
7
7
|
// Export types and state
|
|
8
|
-
export { LoopmanGraphState } from "./types";
|
|
8
|
+
export { LoopmanGraphState } from "./types.js";
|
|
9
9
|
// Export validation node
|
|
10
|
-
export { createLoopmanValidationNode } from "./loopman-validation-node";
|
|
10
|
+
export { createLoopmanValidationNode } from "./loopman-validation-node.js";
|
|
11
11
|
// Export conditional edge
|
|
12
|
-
export { createLoopmanConditionalEdge } from "./loopman-conditional-edge";
|
|
12
|
+
export { createLoopmanConditionalEdge } from "./loopman-conditional-edge.js";
|
|
13
13
|
// Export context node
|
|
14
|
-
export { createLoopmanContextNode } from "./loopman-context-node";
|
|
14
|
+
export { createLoopmanContextNode } from "./loopman-context-node.js";
|
|
15
15
|
// Export helper functions
|
|
16
|
-
export { enrichSystemPrompt, formatGuidelines, formatDecisionContext, hasLoopmanContext, getCriticalGuidelines, getLatestDecision, } from "./helpers";
|
|
16
|
+
export { enrichSystemPrompt, formatGuidelines, formatDecisionContext, hasLoopmanContext, getCriticalGuidelines, getLatestDecision, } from "./helpers.js";
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This node fetches validation guidelines and historical decision context
|
|
5
5
|
* from Loopman API and adds them to the graph state.
|
|
6
6
|
*/
|
|
7
|
-
import { LoopmanService } from "../services/loopman.service";
|
|
7
|
+
import { LoopmanService } from "../services/loopman.service.js";
|
|
8
8
|
/**
|
|
9
9
|
* Factory function to create a Loopman context enrichment node
|
|
10
10
|
*
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* 4. Enriching state with guidelines and decision context
|
|
9
9
|
*/
|
|
10
10
|
import { ToolMessage } from "@langchain/core/messages";
|
|
11
|
-
import { LoopmanService } from "../services/loopman.service";
|
|
12
|
-
import { createLoopmanContextNode } from "./loopman-context-node";
|
|
11
|
+
import { LoopmanService } from "../services/loopman.service.js";
|
|
12
|
+
import { createLoopmanContextNode } from "./loopman-context-node.js";
|
|
13
13
|
/**
|
|
14
14
|
* Creates a Loopman validation node for LangGraph
|
|
15
15
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AIMessage, SystemMessage, ToolMessage, } from "@langchain/core/messages";
|
|
2
2
|
import { createMiddleware } from "langchain";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { LoopmanService } from "./services/loopman.service";
|
|
4
|
+
import { LoopmanService } from "./services/loopman.service.js";
|
|
5
5
|
/**
|
|
6
6
|
* Loopman middleware for LangChain v1.0
|
|
7
7
|
*
|
package/dist/services/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Core services for interacting with the Loopman API
|
|
5
5
|
*/
|
|
6
|
-
export { LoopmanService } from "./loopman.service";
|
|
7
|
-
export { PollingService } from "./polling.service";
|
|
8
|
-
export { LoggerService } from "./logger.service";
|
|
6
|
+
export { LoopmanService } from "./loopman.service.js";
|
|
7
|
+
export { PollingService } from "./polling.service.js";
|
|
8
|
+
export { LoggerService } from "./logger.service.js";
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LoopmanApiClient } from "../client/loopman-api";
|
|
2
|
-
import { LoggerService } from "./logger.service";
|
|
3
|
-
import { PollingService } from "./polling.service";
|
|
1
|
+
import { LoopmanApiClient } from "../client/loopman-api.js";
|
|
2
|
+
import { LoggerService } from "./logger.service.js";
|
|
3
|
+
import { PollingService } from "./polling.service.js";
|
|
4
4
|
/**
|
|
5
5
|
* Service to interact with Loopman Backoffice API
|
|
6
6
|
* Handles logs, decisions, and polling
|
package/dist/templates.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"langgraph-hello-world": {
|
|
3
3
|
"index.ts": "import { HumanMessage, ToolMessage } from \"@langchain/core/messages\";\nimport { END, MemorySaver, START, StateGraph } from \"@langchain/langgraph\";\nimport { ChatOpenAI } from \"@langchain/openai\";\nimport { config } from \"dotenv\";\nimport { tool } from \"langchain\";\nimport * as z from \"zod\";\n\nimport {\n LoopmanGraphState,\n createLoopmanConditionalEdge,\n createLoopmanContextNode,\n createLoopmanValidationNode,\n enrichSystemPrompt,\n} from \"@loopman/langchain-sdk\";\n\nconfig();\n\n// Define your tools\nconst sayHello = tool(\n ({ name }) => {\n console.log(`Hello, ${name}!`);\n return `Hello, ${name}! Welcome to Loopman.`;\n },\n {\n name: \"say_hello\",\n description: \"Say hello to someone\",\n schema: z.object({\n name: z.string().describe(\"The name of the person to greet\"),\n }),\n }\n);\n\n// Agent node with context enrichment\nasync function agentNode(state: any) {\n const { messages, guidelines, decisionContext } = state;\n\n // Enrich system prompt with guidelines and decision history\n const systemPrompt = enrichSystemPrompt(\n \"You are a helpful assistant that greets people ....\",\n { guidelines, decisionContext },\n { maxDecisions: 3 }\n );\n\n const model = new ChatOpenAI({ model: \"gpt-4o-mini\" });\n const modelWithTools = model.bindTools([sayHello]);\n\n const messagesWithContext =\n (guidelines && guidelines.length > 0) ||\n (decisionContext && decisionContext.length > 0)\n ? [{ role: \"system\", content: systemPrompt }, ...messages]\n : messages;\n\n const response = await modelWithTools.invoke(messagesWithContext);\n\n return {\n messages: [response],\n requiresValidation: response.tool_calls && response.tool_calls.length > 0,\n };\n}\n\n// Tool execution node\nasync function toolNode(state: any) {\n const { messages } = state;\n const lastMessage = messages[messages.length - 1];\n\n if (!lastMessage.tool_calls || lastMessage.tool_calls.length === 0) {\n return {};\n }\n\n const toolCall = lastMessage.tool_calls[0];\n const result = await sayHello.invoke(toolCall.args);\n\n return {\n messages: [\n new ToolMessage({\n content: result,\n tool_call_id: toolCall.id,\n }),\n ],\n };\n}\n\n// Build the graph with context loading\nconst workflow = new StateGraph(LoopmanGraphState)\n .addNode(\n \"load_context\",\n createLoopmanContextNode({\n apiKey: process.env.LOOPMAN_API_KEY!,\n workflowId: process.env.LOOPMAN_WORKFLOW_ID!,\n category: \"hello-world\",\n debug: true,\n })\n )\n .addNode(\"agent\", agentNode)\n .addNode(\n \"loopman_validation\",\n createLoopmanValidationNode({\n apiKey: process.env.LOOPMAN_API_KEY!,\n workflowId: process.env.LOOPMAN_WORKFLOW_ID!,\n debug: true,\n })\n )\n .addNode(\"tools\", toolNode)\n .addEdge(START, \"load_context\")\n .addEdge(\"load_context\", \"agent\")\n .addEdge(\"agent\", \"loopman_validation\")\n .addConditionalEdges(\n \"loopman_validation\",\n createLoopmanConditionalEdge({ debug: true }),\n {\n execute: \"tools\",\n rejected: END,\n retry: \"agent\",\n timeout: END,\n error: END,\n }\n )\n .addEdge(\"tools\", END);\n\n// Compile and run\nconst checkpointer = new MemorySaver();\nconst app = workflow.compile({ checkpointer });\n\nasync function main() {\n const config = { configurable: { thread_id: \"hello-world-thread\" } };\n const inputs = {\n messages: [new HumanMessage(\"Say hello to Alice\")],\n };\n\n console.log(\"Starting LangGraph workflow with context enrichment...\");\n\n for await (const output of await app.stream(inputs, config)) {\n const nodeName = Object.keys(output)[0];\n console.log(`Step: ${nodeName}`);\n }\n\n const finalState = await app.getState(config);\n console.log(\"Final status:\", finalState.values.loopmanTaskStatus);\n console.log(\"Guidelines loaded:\", finalState.values.guidelines?.length || 0);\n console.log(\n \"Decision context loaded:\",\n finalState.values.decisionContext?.length || 0\n );\n console.log(\"Workflow completed!\");\n}\n\nmain().catch(console.error);\n",
|
|
4
|
-
"package.json": "{\n \"name\": \"loopman-langgraph-hello-world\",\n \"version\": \"1.0.0\",\n \"description\": \"Loopman LangGraph Hello World Example\",\n \"main\": \"index.ts\",\n \"type\": \"module\",\n \"scripts\": {\n \"start\": \"tsx index.ts\",\n \"dev\": \"tsx index.ts\",\n \"build\": \"tsc\",\n \"run\": \"node dist/index.js\"\n },\n \"dependencies\": {\n \"@langchain/core\": \"^1.0.2\",\n \"@langchain/langgraph\": \"^1.0.1\",\n \"@langchain/openai\": \"^1.0.0\",\n \"@loopman/langchain-sdk\": \"^1.
|
|
4
|
+
"package.json": "{\n \"name\": \"loopman-langgraph-hello-world\",\n \"version\": \"1.0.0\",\n \"description\": \"Loopman LangGraph Hello World Example\",\n \"main\": \"index.ts\",\n \"type\": \"module\",\n \"scripts\": {\n \"start\": \"tsx index.ts\",\n \"dev\": \"tsx index.ts\",\n \"build\": \"tsc\",\n \"run\": \"node dist/index.js\"\n },\n \"dependencies\": {\n \"@langchain/core\": \"^1.0.2\",\n \"@langchain/langgraph\": \"^1.0.1\",\n \"@langchain/openai\": \"^1.0.0\",\n \"@loopman/langchain-sdk\": \"^1.14.1\",\n \"dotenv\": \"^17.2.3\",\n \"langchain\": \"^1.0.2\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.9.3\",\n \"zod\": \"^3.25.76\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^24.9.2\"\n }\n}\n",
|
|
5
5
|
"tsconfig.json": "{\n \"compilerOptions\": {\n \"target\": \"ES2022\",\n \"module\": \"ES2022\",\n \"lib\": [\"ES2022\"],\n \"moduleResolution\": \"bundler\",\n \"resolveJsonModule\": true,\n \"allowJs\": true,\n \"outDir\": \"./dist\",\n \"rootDir\": \"./\",\n \"strict\": true,\n \"esModuleInterop\": true,\n \"skipLibCheck\": true,\n \"forceConsistentCasingInFileNames\": true,\n \"declaration\": true,\n \"declarationMap\": true,\n \"sourceMap\": true\n },\n \"include\": [\"**/*.ts\"],\n \"exclude\": [\"node_modules\", \"dist\"]\n}\n\n",
|
|
6
6
|
"README.md": "# Loopman LangGraph Hello World\n\nThis project demonstrates how to integrate Loopman with LangGraph using Context Enrichment / Feedback Loop mode.\n\n## About LangGraph\n\nLangGraph is LangChain's official framework for building stateful, multi-actor applications with LLMs. It provides:\n\n- **Stateful workflows**: Explicit state management across nodes\n- **Conditional routing**: Dynamic edges based on state\n- **Streaming support**: Real-time updates during execution\n- **Visual debugging**: Graph visualization and inspection\n\n## Setup\n\n1. Install dependencies:\n```bash\nnpm install\n```\n\n2. Copy .env.example to .env and configure your keys:\n```bash\ncp .env.example .env\n```\n\nEdit the .env file and replace the placeholders with your actual values:\n- `OPENAI_API_KEY`: Your OpenAI API key\n- `LOOPMAN_API_KEY`: Your Loopman API key\n- `LOOPMAN_WORKFLOW_ID`: Your workflow ID from Loopman\n\n3. Run the example:\n```bash\nnpm start\n```\n\n## Graph Architecture\n\nThe workflow follows this pattern:\n\n```\nSTART\n ↓\nload_context (load guidelines and decision history)\n ↓\nagent (LLM decides action)\n ↓\nloopman_validation (create task + poll)\n ↓\n[conditional edge based on status]\n ↓\n├─→ tools (APPROVED: execute)\n├─→ agent (NEEDS_CHANGES: retry)\n└─→ END (REJECTED/TIMEOUT/ERROR: end)\n ↓\nEND\n```\n\n## Key Features\n\n- **Context Enrichment**: Loads validation guidelines and historical decisions\n- **Prompt Enhancement**: Automatically enriches system prompts with context\n- **Learning from History**: Agent learns from past human decisions\n- **Category Filtering**: Guidelines filtered by category for relevance\n- **Feedback Loop**: Human feedback is stored and used to improve future decisions\n\n## Learn More\n\n- [LangGraph Documentation](https://js.langchain.com/docs/langgraph/)\n- [Loopman LangGraph Integration Guide](https://github.com/loopman/loopman-langchain-sdk/blob/main/docs/LANGGRAPH_INTEGRATION.md)\n- [Loopman Documentation](https://loopman.dev/docs)\n\n"
|
|
7
7
|
},
|
|
8
8
|
"langchain-tool-validation": {
|
|
9
9
|
"index.ts": "import { MemorySaver } from \"@langchain/langgraph\";\nimport { config } from \"dotenv\";\nimport { createAgent, tool } from \"langchain\";\nimport * as z from \"zod\";\nimport { loopmanMiddleware } from \"@loopman/langchain-sdk\";\n\n// Load environment variables\nconfig();\n\n// Simple hello world tool\nconst sayHello = tool(\n ({ name }) => {\n console.log(`Hello, ${name}!`);\n return `Hello, ${name}! Welcome to Loopman.`;\n },\n {\n name: \"say_hello\",\n description: \"Say hello to someone\",\n schema: z.object({\n name: z.string().describe(\"The name of the person to greet\"),\n }),\n }\n);\n\n// Create agent with Loopman middleware\nconst checkpointer = new MemorySaver();\n\nconst agent = createAgent({\n model: \"openai:gpt-4o-mini\",\n systemPrompt: \"You are a helpful assistant that greets people.\",\n tools: [sayHello],\n middleware: [\n loopmanMiddleware({\n apiKey: process.env.LOOPMAN_API_KEY!,\n workflowId: process.env.LOOPMAN_WORKFLOW_ID!,\n interruptOn: {\n say_hello: true, // Requires human validation\n },\n debug: true,\n }),\n ],\n checkpointer,\n});\n\n// Run the agent\nasync function main() {\n const config = { configurable: { thread_id: \"hello-world-thread\" } };\n\n const result = await agent.invoke(\n {\n messages: [\n {\n role: \"user\",\n content: \"Say hello to Alice\",\n },\n ],\n },\n config\n );\n\n console.log(\"Agent response:\", result.messages[result.messages.length - 1].content);\n}\n\nmain().catch(console.error);\n\n",
|
|
10
|
-
"package.json": "{\n \"name\": \"loopman-langchain-tool-validation\",\n \"version\": \"1.0.0\",\n \"description\": \"Loopman LangChain Tool Validation Example\",\n \"main\": \"index.ts\",\n \"type\": \"module\",\n \"scripts\": {\n \"start\": \"tsx index.ts\",\n \"dev\": \"tsx index.ts\",\n \"build\": \"tsc\",\n \"run\": \"node dist/index.js\"\n },\n \"dependencies\": {\n \"@langchain/core\": \"^1.0.2\",\n \"@langchain/mcp-adapters\": \"^1.0.0\",\n \"@langchain/langgraph\": \"^1.0.1\",\n \"@langchain/openai\": \"^1.0.0\",\n \"@loopman/langchain-sdk\": \"^1.
|
|
10
|
+
"package.json": "{\n \"name\": \"loopman-langchain-tool-validation\",\n \"version\": \"1.0.0\",\n \"description\": \"Loopman LangChain Tool Validation Example\",\n \"main\": \"index.ts\",\n \"type\": \"module\",\n \"scripts\": {\n \"start\": \"tsx index.ts\",\n \"dev\": \"tsx index.ts\",\n \"build\": \"tsc\",\n \"run\": \"node dist/index.js\"\n },\n \"dependencies\": {\n \"@langchain/core\": \"^1.0.2\",\n \"@langchain/mcp-adapters\": \"^1.0.0\",\n \"@langchain/langgraph\": \"^1.0.1\",\n \"@langchain/openai\": \"^1.0.0\",\n \"@loopman/langchain-sdk\": \"^1.14.1\",\n \"dotenv\": \"^17.2.3\",\n \"langchain\": \"^1.0.2\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.9.3\",\n \"zod\": \"^3.25.76\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^24.9.2\"\n }\n}\n\n",
|
|
11
11
|
"tsconfig.json": "{\n \"compilerOptions\": {\n \"target\": \"ES2022\",\n \"module\": \"ES2022\",\n \"lib\": [\"ES2022\"],\n \"moduleResolution\": \"bundler\",\n \"resolveJsonModule\": true,\n \"allowJs\": true,\n \"outDir\": \"./dist\",\n \"rootDir\": \"./\",\n \"strict\": true,\n \"esModuleInterop\": true,\n \"skipLibCheck\": true,\n \"forceConsistentCasingInFileNames\": true,\n \"declaration\": true,\n \"declarationMap\": true,\n \"sourceMap\": true\n },\n \"include\": [\"**/*.ts\"],\n \"exclude\": [\"node_modules\", \"dist\"]\n}\n\n",
|
|
12
12
|
"README.md": "# Loopman LangChain - Tool Validation Mode\n\nThis project demonstrates how to integrate Loopman with LangChain using **Tool Validation** mode.\n\n## About Tool Validation Mode\n\nIn this mode, Loopman middleware intercepts specific tool calls and requires human validation before execution. This is useful when:\n- Certain actions need human approval (e.g., sending emails, making payments)\n- You want to validate AI decisions before they affect real systems\n- Compliance requires human oversight for specific operations\n\n## Setup\n\n1. Install dependencies:\n```bash\nnpm install\n```\n\n2. Copy .env.example to .env and configure your keys:\n```bash\ncp .env.example .env\n```\n\nEdit the .env file and replace the placeholders with your actual values:\n- `OPENAI_API_KEY`: Your OpenAI API key\n- `LOOPMAN_API_KEY`: Your Loopman API key\n- `LOOPMAN_WORKFLOW_ID`: Your workflow ID from Loopman\n\n3. Run the example:\n```bash\nnpm start\n```\n\n## How It Works\n\n### 1. Define Tools\n\n```typescript\nconst sayHello = tool(\n ({ name }) => {\n console.log(`Hello, ${name}!`);\n return `Hello, ${name}! Welcome to Loopman.`;\n },\n {\n name: \"say_hello\",\n description: \"Say hello to someone\",\n schema: z.object({\n name: z.string().describe(\"The name of the person to greet\"),\n }),\n }\n);\n```\n\n### 2. Add Loopman Middleware\n\n```typescript\nconst agent = createAgent({\n model: \"openai:gpt-4o-mini\",\n tools: [sayHello],\n middleware: [\n loopmanMiddleware({\n apiKey: process.env.LOOPMAN_API_KEY!,\n workflowId: process.env.LOOPMAN_WORKFLOW_ID!,\n interruptOn: {\n say_hello: true, // Requires human validation\n },\n debug: true,\n }),\n ],\n checkpointer,\n});\n```\n\n### 3. Run the Agent\n\n```typescript\nconst result = await agent.invoke(\n {\n messages: [{ role: \"user\", content: \"Say hello to Alice\" }],\n },\n config\n);\n```\n\n## Key Features\n\n- **Selective Validation**: Only specified tools require approval\n- **Automatic Interception**: Middleware handles validation workflow\n- **Stateful**: Uses checkpointer to maintain conversation state\n- **Debug Mode**: Verbose logging for development\n\n## Workflow\n\n```\n1. User sends message\n ↓\n2. Agent generates tool call (say_hello)\n ↓\n3. Loopman middleware intercepts\n ↓\n4. Creates validation task\n ↓\n5. Waits for human decision\n ↓\n6. If approved → Execute tool\n If rejected → Return to agent with feedback\n```\n\n## Configuration Options\n\n### interruptOn\n\nSpecify which tools require validation:\n\n```typescript\ninterruptOn: {\n say_hello: true, // Always validate\n send_email: true, // Always validate\n get_weather: false, // Never validate (auto-execute)\n}\n```\n\n### debug\n\nEnable/disable verbose logging:\n\n```typescript\ndebug: true // Show detailed logs\ndebug: false // Production mode\n```\n\n## Learn More\n\n- [Loopman Middleware Documentation](https://github.com/loopman/loopman-langchain-sdk/blob/main/docs/TOOL_VALIDATION_MODE.md)\n- [LangChain Agent Documentation](https://js.langchain.com/docs/how_to/agent_executor)\n- [Loopman Documentation](https://loopman.dev/docs)\n\n"
|
|
13
13
|
},
|
|
14
14
|
"langchain-full-review": {
|
|
15
15
|
"index.ts": "import { config } from \"dotenv\";\nimport { tool } from \"langchain\";\nimport * as z from \"zod\";\nimport { createLoopmanAgent } from \"@loopman/langchain-sdk\";\n\n// Load environment variables\nconfig();\n\n// Simple hello world tool\nconst sayHello = tool(\n ({ name }) => {\n console.log(`Hello, ${name}!`);\n return `Hello, ${name}! Welcome to Loopman.`;\n },\n {\n name: \"say_hello\",\n description: \"Say hello to someone\",\n schema: z.object({\n name: z.string().describe(\"The name of the person to greet\"),\n }),\n }\n);\n\n// Create Loopman agent with full human review process\nconst agent = createLoopmanAgent({\n apiKey: process.env.LOOPMAN_API_KEY!,\n workflowId: process.env.LOOPMAN_WORKFLOW_ID!,\n model: \"openai:gpt-4o-mini\",\n systemPrompt: \"You are a helpful assistant that greets people.\",\n category: \"hello-world\",\n additionalTools: [sayHello],\n requireApprovalForTools: [\"say_hello\"], // Requires validation\n debug: true,\n});\n\n// Run the agent\nasync function main() {\n const result = await agent.processWithHumanValidation({\n input: \"Say hello to Alice\",\n });\n\n console.log(\"Agent response:\", result.response);\n if (result.decision) {\n console.log(\"Decision status:\", result.decision.status);\n if (result.decision.feedback) {\n console.log(\"Human feedback:\", result.decision.feedback);\n }\n }\n\n await agent.disconnect();\n}\n\nmain().catch(console.error);\n\n",
|
|
16
|
-
"package.json": "{\n \"name\": \"loopman-langchain-full-review\",\n \"version\": \"1.0.0\",\n \"description\": \"Loopman LangChain Full Human Review Example\",\n \"main\": \"index.ts\",\n \"type\": \"module\",\n \"scripts\": {\n \"start\": \"tsx index.ts\",\n \"dev\": \"tsx index.ts\",\n \"build\": \"tsc\",\n \"run\": \"node dist/index.js\"\n },\n \"dependencies\": {\n \"@langchain/core\": \"^1.0.2\",\n \"@langchain/mcp-adapters\": \"^1.0.0\",\n \"@langchain/langgraph\": \"^1.0.1\",\n \"@langchain/openai\": \"^1.0.0\",\n \"@loopman/langchain-sdk\": \"^1.
|
|
16
|
+
"package.json": "{\n \"name\": \"loopman-langchain-full-review\",\n \"version\": \"1.0.0\",\n \"description\": \"Loopman LangChain Full Human Review Example\",\n \"main\": \"index.ts\",\n \"type\": \"module\",\n \"scripts\": {\n \"start\": \"tsx index.ts\",\n \"dev\": \"tsx index.ts\",\n \"build\": \"tsc\",\n \"run\": \"node dist/index.js\"\n },\n \"dependencies\": {\n \"@langchain/core\": \"^1.0.2\",\n \"@langchain/mcp-adapters\": \"^1.0.0\",\n \"@langchain/langgraph\": \"^1.0.1\",\n \"@langchain/openai\": \"^1.0.0\",\n \"@loopman/langchain-sdk\": \"^1.14.1\",\n \"dotenv\": \"^17.2.3\",\n \"langchain\": \"^1.0.2\",\n \"tsx\": \"^4.20.6\",\n \"typescript\": \"^5.9.3\",\n \"zod\": \"^3.25.76\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^24.9.2\"\n }\n}\n\n",
|
|
17
17
|
"tsconfig.json": "{\n \"compilerOptions\": {\n \"target\": \"ES2022\",\n \"module\": \"ES2022\",\n \"lib\": [\"ES2022\"],\n \"moduleResolution\": \"bundler\",\n \"resolveJsonModule\": true,\n \"allowJs\": true,\n \"outDir\": \"./dist\",\n \"rootDir\": \"./\",\n \"strict\": true,\n \"esModuleInterop\": true,\n \"skipLibCheck\": true,\n \"forceConsistentCasingInFileNames\": true,\n \"declaration\": true,\n \"declarationMap\": true,\n \"sourceMap\": true\n },\n \"include\": [\"**/*.ts\"],\n \"exclude\": [\"node_modules\", \"dist\"]\n}\n\n",
|
|
18
18
|
"README.md": "# Loopman LangChain - Full Human Review Mode\n\nThis project demonstrates how to integrate Loopman with LangChain using **Full Human Review Process** mode.\n\n## About Full Human Review Mode\n\nIn this mode, the Loopman Agent handles the entire workflow including:\n- Creating validation tasks\n- Waiting for human approval\n- Handling feedback and retries\n- Managing the complete lifecycle\n\nThis is useful when:\n- You want a complete HITL (Human-In-The-Loop) solution\n- The agent should wait for human decisions before proceeding\n- You need full control over the validation workflow\n\n## Setup\n\n1. Install dependencies:\n```bash\nnpm install\n```\n\n2. Copy .env.example to .env and configure your keys:\n```bash\ncp .env.example .env\n```\n\nEdit the .env file and replace the placeholders with your actual values:\n- `OPENAI_API_KEY`: Your OpenAI API key\n- `LOOPMAN_API_KEY`: Your Loopman API key\n- `LOOPMAN_WORKFLOW_ID`: Your workflow ID from Loopman\n\n3. Run the example:\n```bash\nnpm start\n```\n\n## How It Works\n\n### 1. Define Tools\n\n```typescript\nconst sayHello = tool(\n ({ name }) => {\n console.log(`Hello, ${name}!`);\n return `Hello, ${name}! Welcome to Loopman.`;\n },\n {\n name: \"say_hello\",\n description: \"Say hello to someone\",\n schema: z.object({\n name: z.string().describe(\"The name of the person to greet\"),\n }),\n }\n);\n```\n\n### 2. Create Loopman Agent\n\n```typescript\nconst agent = createLoopmanAgent({\n apiKey: process.env.LOOPMAN_API_KEY!,\n workflowId: process.env.LOOPMAN_WORKFLOW_ID!,\n model: \"openai:gpt-4o-mini\",\n systemPrompt: \"You are a helpful assistant that greets people.\",\n category: \"hello-world\",\n additionalTools: [sayHello],\n requireApprovalForTools: [\"say_hello\"],\n debug: true,\n});\n```\n\n### 3. Process with Human Validation\n\n```typescript\nconst result = await agent.processWithHumanValidation({\n input: \"Say hello to Alice\",\n});\n\nconsole.log(\"Agent response:\", result.response);\nif (result.decision) {\n console.log(\"Decision status:\", result.decision.status);\n console.log(\"Human feedback:\", result.decision.feedback);\n}\n```\n\n## Key Features\n\n- **Complete HITL Workflow**: Agent manages the entire validation lifecycle\n- **Automatic Polling**: Waits for human decisions\n- **Feedback Handling**: Processes human feedback and retries if needed\n- **Category Support**: Organize validations by category\n- **Debug Mode**: Verbose logging for development\n\n## Workflow\n\n```\n1. User sends message\n ↓\n2. Agent processes with LLM\n ↓\n3. Agent generates tool call\n ↓\n4. Creates Loopman validation task\n ↓\n5. Polls for human decision\n ↓\n6. If approved → Execute and return result\n If rejected → Process feedback and retry\n If timeout → Handle timeout\n```\n\n## Configuration Options\n\n### requireApprovalForTools\n\nSpecify which tools require validation:\n\n```typescript\nrequireApprovalForTools: [\"say_hello\", \"send_email\"]\n// Only these tools will require human approval\n```\n\n### category\n\nOrganize validations by category:\n\n```typescript\ncategory: \"hello-world\"\n// Helps filter and organize validation tasks\n```\n\n### debug\n\nEnable/disable verbose logging:\n\n```typescript\ndebug: true // Show detailed logs\ndebug: false // Production mode\n```\n\n## Response Structure\n\nThe `processWithHumanValidation` method returns:\n\n```typescript\n{\n response: string, // Final agent response\n decision?: {\n status: \"APPROVED\" | \"REJECTED\" | \"NEEDS_CHANGES\",\n feedback?: string, // Human feedback if provided\n createdAt: Date,\n updatedAt: Date,\n }\n}\n```\n\n## Learn More\n\n- [Loopman Agent Documentation](https://github.com/loopman/loopman-langchain-sdk/blob/main/docs/LOOPMAN_AGENT.md)\n- [LangChain Documentation](https://js.langchain.com/docs)\n- [Loopman Documentation](https://loopman.dev/docs)\n\n"
|
|
19
19
|
}
|
package/examples/README.md
CHANGED
|
@@ -9,7 +9,8 @@ examples/
|
|
|
9
9
|
├── 1-basics/ # LangChain fundamentals (no Loopman)
|
|
10
10
|
├── 2-loopman-integration/ # Loopman HITL core features
|
|
11
11
|
├── 3-real-world-examples/ # Production use cases
|
|
12
|
-
|
|
12
|
+
├── 4-advanced-patterns/ # Sophisticated HITL patterns
|
|
13
|
+
└── 5-langgraph-integration/ # LangGraph workflows (Recommended)
|
|
13
14
|
```
|
|
14
15
|
|
|
15
16
|
---
|
|
@@ -17,33 +18,45 @@ examples/
|
|
|
17
18
|
## 🎓 Learning Path
|
|
18
19
|
|
|
19
20
|
### For Beginners
|
|
21
|
+
|
|
20
22
|
Start with the basics and progress through each level:
|
|
21
23
|
|
|
22
24
|
1. **[1-basics/](1-basics/README.md)** - Learn LangChain agent fundamentals
|
|
25
|
+
|
|
23
26
|
- Simple agents with tools
|
|
24
27
|
- Conversational memory
|
|
25
28
|
- Native HITL middleware
|
|
26
29
|
|
|
27
30
|
2. **[2-loopman-integration/](2-loopman-integration/README.md)** - Add Loopman HITL
|
|
31
|
+
|
|
28
32
|
- Transparent validation
|
|
29
33
|
- Middleware modes
|
|
30
34
|
- MCP integration
|
|
31
35
|
|
|
32
36
|
3. **[3-real-world-examples/](3-real-world-examples/README.md)** - Apply to real scenarios
|
|
37
|
+
|
|
33
38
|
- Task management
|
|
34
39
|
- Data processing
|
|
35
40
|
- Content workflows
|
|
36
41
|
|
|
37
42
|
4. **[4-advanced-patterns/](4-advanced-patterns/README.md)** - Master advanced techniques
|
|
43
|
+
|
|
38
44
|
- Conditional HITL
|
|
39
45
|
- Context-aware validation
|
|
40
46
|
- Risk-based approval
|
|
41
47
|
|
|
48
|
+
5. **[5-langgraph-integration/](5-langgraph-integration/README.md)** - Build stateful workflows (Recommended)
|
|
49
|
+
- Validation nodes
|
|
50
|
+
- Feedback loop with retry
|
|
51
|
+
- Context enrichment
|
|
52
|
+
|
|
42
53
|
### For Experienced Developers
|
|
54
|
+
|
|
43
55
|
Jump directly to relevant sections:
|
|
44
56
|
|
|
45
57
|
- **Need HITL fast?** → [2-loopman-integration/01-middleware-basic.ts](2-loopman-integration/01-middleware-basic.ts)
|
|
46
|
-
- **Building a workflow?** → [
|
|
58
|
+
- **Building a production workflow?** → [5-langgraph-integration/](5-langgraph-integration/README.md) (Recommended)
|
|
59
|
+
- **Need feedback loop?** → [5-langgraph-integration/loopman-validation-graph.ts](5-langgraph-integration/loopman-validation-graph.ts)
|
|
47
60
|
- **Need conditional approval?** → [4-advanced-patterns/conditional-hitl.ts](4-advanced-patterns/conditional-hitl.ts)
|
|
48
61
|
- **Want the complete agent API?** → [2-loopman-integration/03-loopman-agent.ts](2-loopman-integration/03-loopman-agent.ts)
|
|
49
62
|
- **Review LangChain basics** → [1-basics/](1-basics/README.md)
|
|
@@ -77,6 +90,10 @@ npx tsx 3-real-world-examples/task-management/task-approval.ts
|
|
|
77
90
|
|
|
78
91
|
# 4. Advanced pattern
|
|
79
92
|
npx tsx 4-advanced-patterns/conditional-hitl.ts
|
|
93
|
+
|
|
94
|
+
# 5. LangGraph integration (Recommended)
|
|
95
|
+
npx tsx 5-langgraph-integration/loopman-validation-graph.ts
|
|
96
|
+
npm run example:langgraph-full-state
|
|
80
97
|
```
|
|
81
98
|
|
|
82
99
|
---
|
|
@@ -84,17 +101,19 @@ npx tsx 4-advanced-patterns/conditional-hitl.ts
|
|
|
84
101
|
## 📂 Detailed Breakdown
|
|
85
102
|
|
|
86
103
|
### 1️⃣ Basics - LangChain Fundamentals
|
|
104
|
+
|
|
87
105
|
**Path:** `1-basics/`
|
|
88
106
|
|
|
89
107
|
Learn core LangChain concepts without Loopman complexity:
|
|
90
108
|
|
|
91
|
-
| Example
|
|
92
|
-
|
|
93
|
-
| `01-simple-agent.ts`
|
|
94
|
-
| `02-memory-and-context.ts`
|
|
95
|
-
| `03-langchain-native-hitl.ts` | Native HITL
|
|
109
|
+
| Example | Concept | Key Learning |
|
|
110
|
+
| ----------------------------- | --------------------- | ---------------------------------- |
|
|
111
|
+
| `01-simple-agent.ts` | Basic agent | Tools, memory, invoke |
|
|
112
|
+
| `02-memory-and-context.ts` | Conversational memory | Checkpointers, thread IDs, context |
|
|
113
|
+
| `03-langchain-native-hitl.ts` | Native HITL | Interruptions, Command.resume() |
|
|
96
114
|
|
|
97
115
|
**Who should start here:**
|
|
116
|
+
|
|
98
117
|
- New to LangChain v1.0
|
|
99
118
|
- Want to understand agent fundamentals
|
|
100
119
|
- Need reference for vanilla LangChain patterns
|
|
@@ -104,15 +123,16 @@ Learn core LangChain concepts without Loopman complexity:
|
|
|
104
123
|
---
|
|
105
124
|
|
|
106
125
|
### 2️⃣ Loopman Integration - Core HITL Features
|
|
126
|
+
|
|
107
127
|
**Path:** `2-loopman-integration/`
|
|
108
128
|
|
|
109
129
|
Loopman's transparent HITL middleware and agent patterns:
|
|
110
130
|
|
|
111
|
-
| Example
|
|
112
|
-
|
|
113
|
-
| `01-middleware-basic.ts` | Transparent HITL
|
|
114
|
-
| `02-middleware-modes.ts` | Three operation modes
|
|
115
|
-
| `03-loopman-agent.ts`
|
|
131
|
+
| Example | Concept | Key Feature |
|
|
132
|
+
| ------------------------ | ---------------------- | ----------------------------------------- |
|
|
133
|
+
| `01-middleware-basic.ts` | Transparent HITL | No interrupt handling needed! |
|
|
134
|
+
| `02-middleware-modes.ts` | Three operation modes | tool-validation, prompt-enhancement, full |
|
|
135
|
+
| `03-loopman-agent.ts` | High-level Loopman API | All-in-one solution (recommended) |
|
|
116
136
|
|
|
117
137
|
**Key differences from native HITL:**
|
|
118
138
|
|
|
@@ -133,14 +153,15 @@ const result = await agent.invoke(...);
|
|
|
133
153
|
---
|
|
134
154
|
|
|
135
155
|
### 3️⃣ Real-World Examples - Production Use Cases
|
|
156
|
+
|
|
136
157
|
**Path:** `3-real-world-examples/`
|
|
137
158
|
|
|
138
159
|
Complete, domain-specific implementations:
|
|
139
160
|
|
|
140
|
-
| Domain
|
|
141
|
-
|
|
142
|
-
| **Task Management**
|
|
143
|
-
| **Data Processing**
|
|
161
|
+
| Domain | Example | Scenario |
|
|
162
|
+
| -------------------- | ------------------------------------ | ----------------------------------- |
|
|
163
|
+
| **Task Management** | `task-management/task-approval.ts` | CRUD ops with selective approval |
|
|
164
|
+
| **Data Processing** | `data-processing/data-validation.ts` | ETL with quality checks and fixes |
|
|
144
165
|
| **Content Workflow** | `content-workflow/content-review.ts` | Draft/publish with editorial review |
|
|
145
166
|
|
|
146
167
|
**Pattern:** Safe operations auto-approved, destructive operations require approval
|
|
@@ -159,12 +180,13 @@ interruptOn: {
|
|
|
159
180
|
---
|
|
160
181
|
|
|
161
182
|
### 4️⃣ Advanced Patterns - Sophisticated HITL
|
|
183
|
+
|
|
162
184
|
**Path:** `4-advanced-patterns/`
|
|
163
185
|
|
|
164
186
|
Context-aware, intelligent validation:
|
|
165
187
|
|
|
166
|
-
| Pattern
|
|
167
|
-
|
|
188
|
+
| Pattern | Example | Use Case |
|
|
189
|
+
| -------------------- | --------------------- | ------------------------------------------ |
|
|
168
190
|
| **Conditional HITL** | `conditional-hitl.ts` | Amount-based, risk-based, time-based rules |
|
|
169
191
|
|
|
170
192
|
**Example:** Auto-approve small payments, require approval for large ones
|
|
@@ -180,6 +202,45 @@ const needsApproval =
|
|
|
180
202
|
|
|
181
203
|
---
|
|
182
204
|
|
|
205
|
+
### 5️⃣ LangGraph Integration - Stateful Workflows (Recommended)
|
|
206
|
+
|
|
207
|
+
**Path:** `5-langgraph-integration/`
|
|
208
|
+
|
|
209
|
+
Complete LangGraph workflows with validation nodes and feedback loops:
|
|
210
|
+
|
|
211
|
+
| Example | Concept | Key Feature |
|
|
212
|
+
| ----------------------------- | ---------------------- | ------------------------------------------------------ |
|
|
213
|
+
| `loopman-validation-graph.ts` | Complete workflow | Validation nodes + conditional routing + feedback loop |
|
|
214
|
+
| `full-state-example.ts` | Advanced state sharing | Custom state + business context |
|
|
215
|
+
|
|
216
|
+
**Why LangGraph?**
|
|
217
|
+
|
|
218
|
+
LangGraph is the **recommended** approach for production workflows because it provides:
|
|
219
|
+
|
|
220
|
+
- ✅ **Automatic Feedback Loop**: Route `NEEDS_CHANGES` back to agent for retry
|
|
221
|
+
- ✅ **Context Enrichment**: Auto-load guidelines and decision history
|
|
222
|
+
- ✅ **Flexible Routing**: Conditional edges based on human decisions
|
|
223
|
+
- ✅ **State Management**: Track validation status across workflow
|
|
224
|
+
- ✅ **Reusable Nodes**: Validation and context nodes work in any workflow
|
|
225
|
+
|
|
226
|
+
**Example: Feedback Loop**
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
.addConditionalEdges(
|
|
230
|
+
"loopman_validation",
|
|
231
|
+
createLoopmanConditionalEdge(),
|
|
232
|
+
{
|
|
233
|
+
execute: "tools", // APPROVED → execute
|
|
234
|
+
retry: "agent", // NEEDS_CHANGES → retry with feedback 🔄
|
|
235
|
+
rejected: END, // REJECTED → end
|
|
236
|
+
}
|
|
237
|
+
)
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
[👉 Full documentation](5-langgraph-integration/README.md)
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
183
244
|
## 🔧 Environment Configuration
|
|
184
245
|
|
|
185
246
|
Create a `.env` file in the examples directory:
|
|
@@ -203,19 +264,19 @@ Categorize operations by risk level:
|
|
|
203
264
|
|
|
204
265
|
```typescript
|
|
205
266
|
// ✅ Always safe - read operations
|
|
206
|
-
list_items: false
|
|
207
|
-
get_item: false
|
|
208
|
-
analyze_data: false
|
|
267
|
+
list_items: false;
|
|
268
|
+
get_item: false;
|
|
269
|
+
analyze_data: false;
|
|
209
270
|
|
|
210
271
|
// ✅ Usually safe - create/update
|
|
211
|
-
create_draft: false
|
|
212
|
-
update_task: false
|
|
272
|
+
create_draft: false;
|
|
273
|
+
update_task: false;
|
|
213
274
|
|
|
214
275
|
// ⚠️ Requires approval - destructive/public
|
|
215
|
-
delete_item: true
|
|
216
|
-
publish_content: true
|
|
217
|
-
send_email: true
|
|
218
|
-
bulk_operations: true
|
|
276
|
+
delete_item: true;
|
|
277
|
+
publish_content: true;
|
|
278
|
+
send_email: true;
|
|
279
|
+
bulk_operations: true;
|
|
219
280
|
```
|
|
220
281
|
|
|
221
282
|
### Pattern 2: Transparent HITL with Loopman
|
|
@@ -275,29 +336,37 @@ const myTool = tool(({ amount, user }) => {
|
|
|
275
336
|
## 🎯 Choose Your Path
|
|
276
337
|
|
|
277
338
|
### I want to learn LangChain basics
|
|
339
|
+
|
|
278
340
|
👉 Start with [1-basics/01-simple-agent.ts](1-basics/01-simple-agent.ts)
|
|
279
341
|
|
|
280
342
|
### I need to add HITL to my agent
|
|
343
|
+
|
|
281
344
|
👉 Jump to [2-loopman-integration/01-middleware-basic.ts](2-loopman-integration/01-middleware-basic.ts)
|
|
282
345
|
|
|
283
346
|
### I'm building a specific feature
|
|
347
|
+
|
|
284
348
|
👉 Browse [3-real-world-examples/](3-real-world-examples/README.md) for your domain
|
|
285
349
|
|
|
286
350
|
### I need advanced validation logic
|
|
351
|
+
|
|
287
352
|
👉 Study [4-advanced-patterns/conditional-hitl.ts](4-advanced-patterns/conditional-hitl.ts)
|
|
288
353
|
|
|
354
|
+
### I want production-ready workflows with feedback loop
|
|
355
|
+
|
|
356
|
+
👉 Use [5-langgraph-integration/loopman-validation-graph.ts](5-langgraph-integration/loopman-validation-graph.ts) (Recommended)
|
|
357
|
+
|
|
289
358
|
---
|
|
290
359
|
|
|
291
360
|
## 📖 Additional Resources
|
|
292
361
|
|
|
293
362
|
### Documentation
|
|
363
|
+
|
|
294
364
|
- [Main README](../README.md) - SDK overview and API reference
|
|
295
|
-
- [
|
|
296
|
-
- [
|
|
297
|
-
- [Middleware Modes](../docs/TOOL_VALIDATION_MODE.md)
|
|
298
|
-
- [Loopman Agent Guide](../docs/LOOPMAN_AGENT.md)
|
|
365
|
+
- [Loopman Platform](https://loopman.ai) - Official website
|
|
366
|
+
- [Get API Key](https://app.loopman.ai) - Sign up for free
|
|
299
367
|
|
|
300
368
|
### LangChain Resources
|
|
369
|
+
|
|
301
370
|
- [LangChain v1.0 Quickstart](https://docs.langchain.com/oss/javascript/langchain/quickstart)
|
|
302
371
|
- [Human-in-the-Loop Guide](https://docs.langchain.com/oss/javascript/langchain/human-in-the-loop)
|
|
303
372
|
- [Tools Documentation](https://docs.langchain.com/oss/javascript/langchain/tools)
|
|
@@ -307,16 +376,19 @@ const myTool = tool(({ amount, user }) => {
|
|
|
307
376
|
## 🛠️ Development Tips
|
|
308
377
|
|
|
309
378
|
### Debugging
|
|
379
|
+
|
|
310
380
|
- Enable `debug: true` in middleware config
|
|
311
381
|
- Use VSCode debug configurations (`.vscode/launch.json`)
|
|
312
382
|
- Check console output for detailed logs
|
|
313
383
|
|
|
314
384
|
### Testing
|
|
385
|
+
|
|
315
386
|
- Use short timeouts during development (30s instead of 5min)
|
|
316
387
|
- Mock API responses to avoid rate limits
|
|
317
388
|
- Test with different `thread_id` values for isolated conversations
|
|
318
389
|
|
|
319
390
|
### Production
|
|
391
|
+
|
|
320
392
|
- Replace `MemorySaver` with `PostgresSaver` or `RedisSaver`
|
|
321
393
|
- Set appropriate timeouts based on expected human response times
|
|
322
394
|
- Monitor approval rates and tune thresholds
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@langchain/mcp-adapters": "^1.0.0",
|
|
16
16
|
"@langchain/langgraph": "^1.0.1",
|
|
17
17
|
"@langchain/openai": "^1.0.0",
|
|
18
|
-
"@loopman/langchain-sdk": "^1.
|
|
18
|
+
"@loopman/langchain-sdk": "^1.14.1",
|
|
19
19
|
"dotenv": "^17.2.3",
|
|
20
20
|
"langchain": "^1.0.2",
|
|
21
21
|
"tsx": "^4.20.6",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@langchain/mcp-adapters": "^1.0.0",
|
|
16
16
|
"@langchain/langgraph": "^1.0.1",
|
|
17
17
|
"@langchain/openai": "^1.0.0",
|
|
18
|
-
"@loopman/langchain-sdk": "^1.
|
|
18
|
+
"@loopman/langchain-sdk": "^1.14.1",
|
|
19
19
|
"dotenv": "^17.2.3",
|
|
20
20
|
"langchain": "^1.0.2",
|
|
21
21
|
"tsx": "^4.20.6",
|
package/package.json
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopman/langchain-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.1",
|
|
4
4
|
"description": "LangChain TypeScript SDK - Human-in-the-Loop validation via Loopman platform",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"scripts": {
|
|
8
|
-
"build": "npm run export-templates && tsc",
|
|
16
|
+
"build": "npm run export-templates && tsc && npm run fix-esm",
|
|
17
|
+
"fix-esm": "node scripts/fix-esm-imports.mjs",
|
|
9
18
|
"clean": "rm -rf dist",
|
|
10
19
|
"release": "./scripts/release.sh",
|
|
11
|
-
"export-templates": "mkdir -p dist && node scripts/export-templates.
|
|
20
|
+
"export-templates": "mkdir -p dist && node scripts/export-templates.mjs",
|
|
12
21
|
"example:langgraph-full-state": "tsx examples/5-langgraph-integration/full-state-example.ts"
|
|
13
22
|
},
|
|
14
23
|
"keywords": [
|