@loopman/langchain-sdk 1.8.0 → 1.12.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.
Files changed (49) hide show
  1. package/README.md +7 -1
  2. package/dist/agents/loopman-agent.d.ts.map +1 -1
  3. package/dist/agents/loopman-agent.js.map +1 -1
  4. package/dist/helpers/template-generator-static.d.ts +27 -0
  5. package/dist/helpers/template-generator-static.d.ts.map +1 -0
  6. package/dist/helpers/template-generator-static.js +52 -0
  7. package/dist/helpers/template-generator-static.js.map +1 -0
  8. package/dist/helpers/template-generator.d.ts +50 -0
  9. package/dist/helpers/template-generator.d.ts.map +1 -0
  10. package/dist/helpers/template-generator.js +85 -0
  11. package/dist/helpers/template-generator.js.map +1 -0
  12. package/dist/index.d.ts +3 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +4 -0
  15. package/dist/index.js.map +1 -1
  16. package/dist/langgraph/loopman-context-node.d.ts +2 -2
  17. package/dist/langgraph/loopman-context-node.d.ts.map +1 -1
  18. package/dist/langgraph/loopman-context-node.js +32 -20
  19. package/dist/langgraph/loopman-context-node.js.map +1 -1
  20. package/dist/langgraph/loopman-validation-node.d.ts +45 -15
  21. package/dist/langgraph/loopman-validation-node.d.ts.map +1 -1
  22. package/dist/langgraph/loopman-validation-node.js +144 -21
  23. package/dist/langgraph/loopman-validation-node.js.map +1 -1
  24. package/dist/mcp/loopman-mcp-client.d.ts.map +1 -1
  25. package/dist/mcp/loopman-mcp-client.js +5 -0
  26. package/dist/mcp/loopman-mcp-client.js.map +1 -1
  27. package/dist/services/loopman.service.d.ts +11 -2
  28. package/dist/services/loopman.service.d.ts.map +1 -1
  29. package/dist/services/loopman.service.js +26 -9
  30. package/dist/services/loopman.service.js.map +1 -1
  31. package/dist/templates.json +20 -0
  32. package/examples/README.md +346 -0
  33. package/examples/templates/README.md +285 -0
  34. package/examples/templates/langchain-full-review/.env.example +3 -0
  35. package/examples/templates/langchain-full-review/README.md +165 -0
  36. package/examples/templates/langchain-full-review/index.ts +54 -0
  37. package/examples/templates/langchain-full-review/package.json +29 -0
  38. package/examples/templates/langchain-full-review/tsconfig.json +22 -0
  39. package/examples/templates/langchain-tool-validation/.env.example +3 -0
  40. package/examples/templates/langchain-tool-validation/README.md +137 -0
  41. package/examples/templates/langchain-tool-validation/index.ts +65 -0
  42. package/examples/templates/langchain-tool-validation/package.json +29 -0
  43. package/examples/templates/langchain-tool-validation/tsconfig.json +22 -0
  44. package/examples/templates/langgraph-hello-world/.env.example +3 -0
  45. package/examples/templates/langgraph-hello-world/README.md +71 -0
  46. package/examples/templates/langgraph-hello-world/index.ts +147 -0
  47. package/examples/templates/langgraph-hello-world/package.json +27 -0
  48. package/examples/templates/langgraph-hello-world/tsconfig.json +22 -0
  49. package/package.json +7 -4
@@ -0,0 +1,165 @@
1
+ # Loopman LangChain - Full Human Review Mode
2
+
3
+ This project demonstrates how to integrate Loopman with LangChain using **Full Human Review Process** mode.
4
+
5
+ ## About Full Human Review Mode
6
+
7
+ In this mode, the Loopman Agent handles the entire workflow including:
8
+ - Creating validation tasks
9
+ - Waiting for human approval
10
+ - Handling feedback and retries
11
+ - Managing the complete lifecycle
12
+
13
+ This is useful when:
14
+ - You want a complete HITL (Human-In-The-Loop) solution
15
+ - The agent should wait for human decisions before proceeding
16
+ - You need full control over the validation workflow
17
+
18
+ ## Setup
19
+
20
+ 1. Install dependencies:
21
+ ```bash
22
+ npm install
23
+ ```
24
+
25
+ 2. Copy .env.example to .env and configure your keys:
26
+ ```bash
27
+ cp .env.example .env
28
+ ```
29
+
30
+ Edit the .env file and replace the placeholders with your actual values:
31
+ - `OPENAI_API_KEY`: Your OpenAI API key
32
+ - `LOOPMAN_API_KEY`: Your Loopman API key
33
+ - `LOOPMAN_WORKFLOW_ID`: Your workflow ID from Loopman
34
+
35
+ 3. Run the example:
36
+ ```bash
37
+ npm start
38
+ ```
39
+
40
+ ## How It Works
41
+
42
+ ### 1. Define Tools
43
+
44
+ ```typescript
45
+ const sayHello = tool(
46
+ ({ name }) => {
47
+ console.log(`Hello, ${name}!`);
48
+ return `Hello, ${name}! Welcome to Loopman.`;
49
+ },
50
+ {
51
+ name: "say_hello",
52
+ description: "Say hello to someone",
53
+ schema: z.object({
54
+ name: z.string().describe("The name of the person to greet"),
55
+ }),
56
+ }
57
+ );
58
+ ```
59
+
60
+ ### 2. Create Loopman Agent
61
+
62
+ ```typescript
63
+ const agent = createLoopmanAgent({
64
+ apiKey: process.env.LOOPMAN_API_KEY!,
65
+ workflowId: process.env.LOOPMAN_WORKFLOW_ID!,
66
+ model: "openai:gpt-4o-mini",
67
+ systemPrompt: "You are a helpful assistant that greets people.",
68
+ category: "hello-world",
69
+ additionalTools: [sayHello],
70
+ requireApprovalForTools: ["say_hello"],
71
+ debug: true,
72
+ });
73
+ ```
74
+
75
+ ### 3. Process with Human Validation
76
+
77
+ ```typescript
78
+ const result = await agent.processWithHumanValidation({
79
+ input: "Say hello to Alice",
80
+ });
81
+
82
+ console.log("Agent response:", result.response);
83
+ if (result.decision) {
84
+ console.log("Decision status:", result.decision.status);
85
+ console.log("Human feedback:", result.decision.feedback);
86
+ }
87
+ ```
88
+
89
+ ## Key Features
90
+
91
+ - **Complete HITL Workflow**: Agent manages the entire validation lifecycle
92
+ - **Automatic Polling**: Waits for human decisions
93
+ - **Feedback Handling**: Processes human feedback and retries if needed
94
+ - **Category Support**: Organize validations by category
95
+ - **Debug Mode**: Verbose logging for development
96
+
97
+ ## Workflow
98
+
99
+ ```
100
+ 1. User sends message
101
+
102
+ 2. Agent processes with LLM
103
+
104
+ 3. Agent generates tool call
105
+
106
+ 4. Creates Loopman validation task
107
+
108
+ 5. Polls for human decision
109
+
110
+ 6. If approved → Execute and return result
111
+ If rejected → Process feedback and retry
112
+ If timeout → Handle timeout
113
+ ```
114
+
115
+ ## Configuration Options
116
+
117
+ ### requireApprovalForTools
118
+
119
+ Specify which tools require validation:
120
+
121
+ ```typescript
122
+ requireApprovalForTools: ["say_hello", "send_email"]
123
+ // Only these tools will require human approval
124
+ ```
125
+
126
+ ### category
127
+
128
+ Organize validations by category:
129
+
130
+ ```typescript
131
+ category: "hello-world"
132
+ // Helps filter and organize validation tasks
133
+ ```
134
+
135
+ ### debug
136
+
137
+ Enable/disable verbose logging:
138
+
139
+ ```typescript
140
+ debug: true // Show detailed logs
141
+ debug: false // Production mode
142
+ ```
143
+
144
+ ## Response Structure
145
+
146
+ The `processWithHumanValidation` method returns:
147
+
148
+ ```typescript
149
+ {
150
+ response: string, // Final agent response
151
+ decision?: {
152
+ status: "APPROVED" | "REJECTED" | "NEEDS_CHANGES",
153
+ feedback?: string, // Human feedback if provided
154
+ createdAt: Date,
155
+ updatedAt: Date,
156
+ }
157
+ }
158
+ ```
159
+
160
+ ## Learn More
161
+
162
+ - [Loopman Agent Documentation](https://github.com/loopman/loopman-langchain-sdk/blob/main/docs/LOOPMAN_AGENT.md)
163
+ - [LangChain Documentation](https://js.langchain.com/docs)
164
+ - [Loopman Documentation](https://loopman.dev/docs)
165
+
@@ -0,0 +1,54 @@
1
+ import { config } from "dotenv";
2
+ import { tool } from "langchain";
3
+ import * as z from "zod";
4
+ import { createLoopmanAgent } from "@loopman/langchain-sdk";
5
+
6
+ // Load environment variables
7
+ config();
8
+
9
+ // Simple hello world tool
10
+ const sayHello = tool(
11
+ ({ name }) => {
12
+ console.log(`Hello, ${name}!`);
13
+ return `Hello, ${name}! Welcome to Loopman.`;
14
+ },
15
+ {
16
+ name: "say_hello",
17
+ description: "Say hello to someone",
18
+ schema: z.object({
19
+ name: z.string().describe("The name of the person to greet"),
20
+ }),
21
+ }
22
+ );
23
+
24
+ // Create Loopman agent with full human review process
25
+ const agent = createLoopmanAgent({
26
+ apiKey: process.env.LOOPMAN_API_KEY!,
27
+ workflowId: process.env.LOOPMAN_WORKFLOW_ID!,
28
+ model: "openai:gpt-4o-mini",
29
+ systemPrompt: "You are a helpful assistant that greets people.",
30
+ category: "hello-world",
31
+ additionalTools: [sayHello],
32
+ requireApprovalForTools: ["say_hello"], // Requires validation
33
+ debug: true,
34
+ });
35
+
36
+ // Run the agent
37
+ async function main() {
38
+ const result = await agent.processWithHumanValidation({
39
+ input: "Say hello to Alice",
40
+ });
41
+
42
+ console.log("Agent response:", result.response);
43
+ if (result.decision) {
44
+ console.log("Decision status:", result.decision.status);
45
+ if (result.decision.feedback) {
46
+ console.log("Human feedback:", result.decision.feedback);
47
+ }
48
+ }
49
+
50
+ await agent.disconnect();
51
+ }
52
+
53
+ main().catch(console.error);
54
+
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "loopman-langchain-full-review",
3
+ "version": "1.0.0",
4
+ "description": "Loopman LangChain Full Human Review Example",
5
+ "main": "index.ts",
6
+ "type": "module",
7
+ "scripts": {
8
+ "start": "tsx index.ts",
9
+ "dev": "tsx index.ts",
10
+ "build": "tsc",
11
+ "run": "node dist/index.js"
12
+ },
13
+ "dependencies": {
14
+ "@langchain/core": "^1.0.2",
15
+ "@langchain/mcp-adapters": "^1.0.0",
16
+ "@langchain/langgraph": "^1.0.1",
17
+ "@langchain/openai": "^1.0.0",
18
+ "@loopman/langchain-sdk": "^1.12.1",
19
+ "dotenv": "^17.2.3",
20
+ "langchain": "^1.0.2",
21
+ "tsx": "^4.20.6",
22
+ "typescript": "^5.9.3",
23
+ "zod": "^3.25.76"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^24.9.2"
27
+ }
28
+ }
29
+
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "lib": ["ES2022"],
6
+ "moduleResolution": "bundler",
7
+ "resolveJsonModule": true,
8
+ "allowJs": true,
9
+ "outDir": "./dist",
10
+ "rootDir": "./",
11
+ "strict": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "declaration": true,
16
+ "declarationMap": true,
17
+ "sourceMap": true
18
+ },
19
+ "include": ["**/*.ts"],
20
+ "exclude": ["node_modules", "dist"]
21
+ }
22
+
@@ -0,0 +1,3 @@
1
+ OPENAI_API_KEY=your-openai-api-key-here
2
+ LOOPMAN_API_KEY=your-loopman-api-key-here
3
+ LOOPMAN_WORKFLOW_ID=your-workflow-id-here
@@ -0,0 +1,137 @@
1
+ # Loopman LangChain - Tool Validation Mode
2
+
3
+ This project demonstrates how to integrate Loopman with LangChain using **Tool Validation** mode.
4
+
5
+ ## About Tool Validation Mode
6
+
7
+ In this mode, Loopman middleware intercepts specific tool calls and requires human validation before execution. This is useful when:
8
+ - Certain actions need human approval (e.g., sending emails, making payments)
9
+ - You want to validate AI decisions before they affect real systems
10
+ - Compliance requires human oversight for specific operations
11
+
12
+ ## Setup
13
+
14
+ 1. Install dependencies:
15
+ ```bash
16
+ npm install
17
+ ```
18
+
19
+ 2. Copy .env.example to .env and configure your keys:
20
+ ```bash
21
+ cp .env.example .env
22
+ ```
23
+
24
+ Edit the .env file and replace the placeholders with your actual values:
25
+ - `OPENAI_API_KEY`: Your OpenAI API key
26
+ - `LOOPMAN_API_KEY`: Your Loopman API key
27
+ - `LOOPMAN_WORKFLOW_ID`: Your workflow ID from Loopman
28
+
29
+ 3. Run the example:
30
+ ```bash
31
+ npm start
32
+ ```
33
+
34
+ ## How It Works
35
+
36
+ ### 1. Define Tools
37
+
38
+ ```typescript
39
+ const sayHello = tool(
40
+ ({ name }) => {
41
+ console.log(`Hello, ${name}!`);
42
+ return `Hello, ${name}! Welcome to Loopman.`;
43
+ },
44
+ {
45
+ name: "say_hello",
46
+ description: "Say hello to someone",
47
+ schema: z.object({
48
+ name: z.string().describe("The name of the person to greet"),
49
+ }),
50
+ }
51
+ );
52
+ ```
53
+
54
+ ### 2. Add Loopman Middleware
55
+
56
+ ```typescript
57
+ const agent = createAgent({
58
+ model: "openai:gpt-4o-mini",
59
+ tools: [sayHello],
60
+ middleware: [
61
+ loopmanMiddleware({
62
+ apiKey: process.env.LOOPMAN_API_KEY!,
63
+ workflowId: process.env.LOOPMAN_WORKFLOW_ID!,
64
+ interruptOn: {
65
+ say_hello: true, // Requires human validation
66
+ },
67
+ debug: true,
68
+ }),
69
+ ],
70
+ checkpointer,
71
+ });
72
+ ```
73
+
74
+ ### 3. Run the Agent
75
+
76
+ ```typescript
77
+ const result = await agent.invoke(
78
+ {
79
+ messages: [{ role: "user", content: "Say hello to Alice" }],
80
+ },
81
+ config
82
+ );
83
+ ```
84
+
85
+ ## Key Features
86
+
87
+ - **Selective Validation**: Only specified tools require approval
88
+ - **Automatic Interception**: Middleware handles validation workflow
89
+ - **Stateful**: Uses checkpointer to maintain conversation state
90
+ - **Debug Mode**: Verbose logging for development
91
+
92
+ ## Workflow
93
+
94
+ ```
95
+ 1. User sends message
96
+
97
+ 2. Agent generates tool call (say_hello)
98
+
99
+ 3. Loopman middleware intercepts
100
+
101
+ 4. Creates validation task
102
+
103
+ 5. Waits for human decision
104
+
105
+ 6. If approved → Execute tool
106
+ If rejected → Return to agent with feedback
107
+ ```
108
+
109
+ ## Configuration Options
110
+
111
+ ### interruptOn
112
+
113
+ Specify which tools require validation:
114
+
115
+ ```typescript
116
+ interruptOn: {
117
+ say_hello: true, // Always validate
118
+ send_email: true, // Always validate
119
+ get_weather: false, // Never validate (auto-execute)
120
+ }
121
+ ```
122
+
123
+ ### debug
124
+
125
+ Enable/disable verbose logging:
126
+
127
+ ```typescript
128
+ debug: true // Show detailed logs
129
+ debug: false // Production mode
130
+ ```
131
+
132
+ ## Learn More
133
+
134
+ - [Loopman Middleware Documentation](https://github.com/loopman/loopman-langchain-sdk/blob/main/docs/TOOL_VALIDATION_MODE.md)
135
+ - [LangChain Agent Documentation](https://js.langchain.com/docs/how_to/agent_executor)
136
+ - [Loopman Documentation](https://loopman.dev/docs)
137
+
@@ -0,0 +1,65 @@
1
+ import { MemorySaver } from "@langchain/langgraph";
2
+ import { config } from "dotenv";
3
+ import { createAgent, tool } from "langchain";
4
+ import * as z from "zod";
5
+ import { loopmanMiddleware } from "@loopman/langchain-sdk";
6
+
7
+ // Load environment variables
8
+ config();
9
+
10
+ // Simple hello world tool
11
+ const sayHello = tool(
12
+ ({ name }) => {
13
+ console.log(`Hello, ${name}!`);
14
+ return `Hello, ${name}! Welcome to Loopman.`;
15
+ },
16
+ {
17
+ name: "say_hello",
18
+ description: "Say hello to someone",
19
+ schema: z.object({
20
+ name: z.string().describe("The name of the person to greet"),
21
+ }),
22
+ }
23
+ );
24
+
25
+ // Create agent with Loopman middleware
26
+ const checkpointer = new MemorySaver();
27
+
28
+ const agent = createAgent({
29
+ model: "openai:gpt-4o-mini",
30
+ systemPrompt: "You are a helpful assistant that greets people.",
31
+ tools: [sayHello],
32
+ middleware: [
33
+ loopmanMiddleware({
34
+ apiKey: process.env.LOOPMAN_API_KEY!,
35
+ workflowId: process.env.LOOPMAN_WORKFLOW_ID!,
36
+ interruptOn: {
37
+ say_hello: true, // Requires human validation
38
+ },
39
+ debug: true,
40
+ }),
41
+ ],
42
+ checkpointer,
43
+ });
44
+
45
+ // Run the agent
46
+ async function main() {
47
+ const config = { configurable: { thread_id: "hello-world-thread" } };
48
+
49
+ const result = await agent.invoke(
50
+ {
51
+ messages: [
52
+ {
53
+ role: "user",
54
+ content: "Say hello to Alice",
55
+ },
56
+ ],
57
+ },
58
+ config
59
+ );
60
+
61
+ console.log("Agent response:", result.messages[result.messages.length - 1].content);
62
+ }
63
+
64
+ main().catch(console.error);
65
+
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "loopman-langchain-tool-validation",
3
+ "version": "1.0.0",
4
+ "description": "Loopman LangChain Tool Validation Example",
5
+ "main": "index.ts",
6
+ "type": "module",
7
+ "scripts": {
8
+ "start": "tsx index.ts",
9
+ "dev": "tsx index.ts",
10
+ "build": "tsc",
11
+ "run": "node dist/index.js"
12
+ },
13
+ "dependencies": {
14
+ "@langchain/core": "^1.0.2",
15
+ "@langchain/mcp-adapters": "^1.0.0",
16
+ "@langchain/langgraph": "^1.0.1",
17
+ "@langchain/openai": "^1.0.0",
18
+ "@loopman/langchain-sdk": "^1.12.1",
19
+ "dotenv": "^17.2.3",
20
+ "langchain": "^1.0.2",
21
+ "tsx": "^4.20.6",
22
+ "typescript": "^5.9.3",
23
+ "zod": "^3.25.76"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^24.9.2"
27
+ }
28
+ }
29
+
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "lib": ["ES2022"],
6
+ "moduleResolution": "bundler",
7
+ "resolveJsonModule": true,
8
+ "allowJs": true,
9
+ "outDir": "./dist",
10
+ "rootDir": "./",
11
+ "strict": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "declaration": true,
16
+ "declarationMap": true,
17
+ "sourceMap": true
18
+ },
19
+ "include": ["**/*.ts"],
20
+ "exclude": ["node_modules", "dist"]
21
+ }
22
+
@@ -0,0 +1,3 @@
1
+ OPENAI_API_KEY=your-openai-api-key-here
2
+ LOOPMAN_API_KEY=your-loopman-api-key-here
3
+ LOOPMAN_WORKFLOW_ID=your-workflow-id-here
@@ -0,0 +1,71 @@
1
+ # Loopman LangGraph Hello World
2
+
3
+ This project demonstrates how to integrate Loopman with LangGraph using Context Enrichment / Feedback Loop mode.
4
+
5
+ ## About LangGraph
6
+
7
+ LangGraph is LangChain's official framework for building stateful, multi-actor applications with LLMs. It provides:
8
+
9
+ - **Stateful workflows**: Explicit state management across nodes
10
+ - **Conditional routing**: Dynamic edges based on state
11
+ - **Streaming support**: Real-time updates during execution
12
+ - **Visual debugging**: Graph visualization and inspection
13
+
14
+ ## Setup
15
+
16
+ 1. Install dependencies:
17
+ ```bash
18
+ npm install
19
+ ```
20
+
21
+ 2. Copy .env.example to .env and configure your keys:
22
+ ```bash
23
+ cp .env.example .env
24
+ ```
25
+
26
+ Edit the .env file and replace the placeholders with your actual values:
27
+ - `OPENAI_API_KEY`: Your OpenAI API key
28
+ - `LOOPMAN_API_KEY`: Your Loopman API key
29
+ - `LOOPMAN_WORKFLOW_ID`: Your workflow ID from Loopman
30
+
31
+ 3. Run the example:
32
+ ```bash
33
+ npm start
34
+ ```
35
+
36
+ ## Graph Architecture
37
+
38
+ The workflow follows this pattern:
39
+
40
+ ```
41
+ START
42
+
43
+ load_context (load guidelines and decision history)
44
+
45
+ agent (LLM decides action)
46
+
47
+ loopman_validation (create task + poll)
48
+
49
+ [conditional edge based on status]
50
+
51
+ ├─→ tools (APPROVED: execute)
52
+ ├─→ agent (NEEDS_CHANGES: retry)
53
+ └─→ END (REJECTED/TIMEOUT/ERROR: end)
54
+
55
+ END
56
+ ```
57
+
58
+ ## Key Features
59
+
60
+ - **Context Enrichment**: Loads validation guidelines and historical decisions
61
+ - **Prompt Enhancement**: Automatically enriches system prompts with context
62
+ - **Learning from History**: Agent learns from past human decisions
63
+ - **Category Filtering**: Guidelines filtered by category for relevance
64
+ - **Feedback Loop**: Human feedback is stored and used to improve future decisions
65
+
66
+ ## Learn More
67
+
68
+ - [LangGraph Documentation](https://js.langchain.com/docs/langgraph/)
69
+ - [Loopman LangGraph Integration Guide](https://github.com/loopman/loopman-langchain-sdk/blob/main/docs/LANGGRAPH_INTEGRATION.md)
70
+ - [Loopman Documentation](https://loopman.dev/docs)
71
+