@loopman/langchain-sdk 1.17.3 ā 1.17.4
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/README.md +8 -14
- package/dist/langgraph/loopman-validation-node.d.ts +9 -20
- package/dist/langgraph/loopman-validation-node.d.ts.map +1 -1
- package/dist/langgraph/loopman-validation-node.js +12 -35
- package/dist/langgraph/loopman-validation-node.js.map +1 -1
- package/dist/templates.json +3 -3
- 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 +2 -3
package/README.md
CHANGED
|
@@ -357,17 +357,16 @@ workflow.addNode("loopman_validation", (state, config) =>
|
|
|
357
357
|
validationNode(state, {
|
|
358
358
|
taskTitle: `Approve ${state.currentAction}`,
|
|
359
359
|
taskMessage: `Review action for user ${state.userId}`,
|
|
360
|
-
businessContext:
|
|
361
|
-
proposedDecision:
|
|
360
|
+
businessContext: `Risk: ${state.riskLevel}, Cost: $${state.estimatedCost}`,
|
|
361
|
+
proposedDecision: `Execute ${state.currentAction} on ${state.targetResource}`,
|
|
362
362
|
})
|
|
363
363
|
);
|
|
364
364
|
```
|
|
365
365
|
|
|
366
366
|
**Options:**
|
|
367
|
+
|
|
367
368
|
- `taskTitle`, `taskMessage` - Custom task information
|
|
368
|
-
- `businessContext`, `proposedDecision`, `decisionReasoning` - Context
|
|
369
|
-
- `formatState` - Custom formatter
|
|
370
|
-
- `includeFullState` - Include state (default: `true`)
|
|
369
|
+
- `businessContext`, `proposedDecision`, `decisionReasoning` - Context strings
|
|
371
370
|
|
|
372
371
|
**š Feedback Loop in Action:**
|
|
373
372
|
|
|
@@ -414,8 +413,7 @@ Comprehensive examples are organized in the `examples/` directory by complexity
|
|
|
414
413
|
|
|
415
414
|
**5. LangGraph Integration** (`examples/5-langgraph-integration/`)
|
|
416
415
|
|
|
417
|
-
- `loopman-validation-graph.ts` - LangGraph workflow with validation node and
|
|
418
|
-
- `full-state-example.ts` - Complete state sharing with business context and custom formatting
|
|
416
|
+
- `loopman-validation-graph.ts` - Complete LangGraph workflow with validation node, context enrichment and feedback loop
|
|
419
417
|
|
|
420
418
|
### Running Examples
|
|
421
419
|
|
|
@@ -437,7 +435,6 @@ npx tsx examples/4-advanced-patterns/conditional-hitl.ts
|
|
|
437
435
|
|
|
438
436
|
# LangGraph Integration
|
|
439
437
|
npx tsx examples/5-langgraph-integration/loopman-validation-graph.ts
|
|
440
|
-
npm run example:langgraph-full-state
|
|
441
438
|
```
|
|
442
439
|
|
|
443
440
|
See [Examples README](./examples/README.md) for detailed documentation and learning paths.
|
|
@@ -572,12 +569,9 @@ Creates a LangGraph node that handles human validation.
|
|
|
572
569
|
|
|
573
570
|
- `taskTitle` (string): Task title
|
|
574
571
|
- `taskMessage` (string): Task description
|
|
575
|
-
- `businessContext` (string
|
|
576
|
-
- `proposedDecision` (string
|
|
577
|
-
- `decisionReasoning` (string
|
|
578
|
-
- `includeFullState` (boolean): Include state (default: true)
|
|
579
|
-
- `formatState` (function): Custom state formatter
|
|
580
|
-
- `extractToolCall` (function): Custom tool call extractor
|
|
572
|
+
- `businessContext` (string): Business context
|
|
573
|
+
- `proposedDecision` (string): Proposed decision
|
|
574
|
+
- `decisionReasoning` (string): Decision reasoning
|
|
581
575
|
|
|
582
576
|
**Returns:** Node function `(state, options?) => Promise<StateUpdate>`
|
|
583
577
|
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* 3. Polling for human decisions
|
|
8
8
|
* 4. Enriching state with guidelines and decision context
|
|
9
9
|
*/
|
|
10
|
-
import { TaskInformation } from "../types";
|
|
11
10
|
/**
|
|
12
11
|
* Configuration for Loopman validation node (service-level config)
|
|
13
12
|
*/
|
|
@@ -35,22 +34,12 @@ export interface LoopmanValidationTaskOptions {
|
|
|
35
34
|
taskTitle?: string;
|
|
36
35
|
/** Custom message/description to display when creating task */
|
|
37
36
|
taskMessage?: string;
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/** Business context to include in the task (or function to extract from state) */
|
|
45
|
-
businessContext?: string | ((state: any) => string);
|
|
46
|
-
/** Proposed decision to include in the task (or function to extract from state) */
|
|
47
|
-
proposedDecision?: string | ((state: any) => string);
|
|
48
|
-
/** Decision reasoning to include in the task (or function to extract from state) */
|
|
49
|
-
decisionReasoning?: string | ((state: any) => string);
|
|
50
|
-
/** Whether to include full state in task information (default: true) */
|
|
51
|
-
includeFullState?: boolean;
|
|
52
|
-
/** Custom function to format state for task information (if not provided, uses default converter) */
|
|
53
|
-
formatState?: (state: any) => TaskInformation[];
|
|
37
|
+
/** Business context to include in the task */
|
|
38
|
+
businessContext?: string;
|
|
39
|
+
/** Proposed decision to include in the task */
|
|
40
|
+
proposedDecision?: string;
|
|
41
|
+
/** Decision reasoning to include in the task */
|
|
42
|
+
decisionReasoning?: string;
|
|
54
43
|
}
|
|
55
44
|
/**
|
|
56
45
|
* Creates a Loopman validation node for LangGraph
|
|
@@ -103,9 +92,9 @@ export interface LoopmanValidationTaskOptions {
|
|
|
103
92
|
* ```typescript
|
|
104
93
|
* workflow.addNode("loopman_validation", (state, config) =>
|
|
105
94
|
* loopmanNode(state, {
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
95
|
+
* taskTitle: "Approve Transaction",
|
|
96
|
+
* businessContext: `Processing user ${state.userId}: ${state.userQuery}`,
|
|
97
|
+
* proposedDecision: `Execute ${state.currentAction} on ${state.targetResource}`,
|
|
109
98
|
* })
|
|
110
99
|
* );
|
|
111
100
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loopman-validation-node.d.ts","sourceRoot":"","sources":["../../src/langgraph/loopman-validation-node.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"loopman-validation-node.d.ts","sourceRoot":"","sources":["../../src/langgraph/loopman-validation-node.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+CAA+C;IAC/C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gDAAgD;IAChD,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,2BAA2B,IAerB,OAAO,GAAG,EAAE,UAAS,4BAAiC,kBAiLrE"}
|
|
@@ -61,9 +61,9 @@ import { createLoopmanContextNode } from "./loopman-context-node.js";
|
|
|
61
61
|
* ```typescript
|
|
62
62
|
* workflow.addNode("loopman_validation", (state, config) =>
|
|
63
63
|
* loopmanNode(state, {
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
64
|
+
* taskTitle: "Approve Transaction",
|
|
65
|
+
* businessContext: `Processing user ${state.userId}: ${state.userQuery}`,
|
|
66
|
+
* proposedDecision: `Execute ${state.currentAction} on ${state.targetResource}`,
|
|
67
67
|
* })
|
|
68
68
|
* );
|
|
69
69
|
* ```
|
|
@@ -86,9 +86,7 @@ export function createLoopmanValidationNode(config) {
|
|
|
86
86
|
const logger = loopmanService.logger;
|
|
87
87
|
// Extract tool call from last message (optional - can be used without tool calls)
|
|
88
88
|
const lastMessage = messages[messages.length - 1];
|
|
89
|
-
const toolCall =
|
|
90
|
-
? options.extractToolCall(messages)
|
|
91
|
-
: extractDefaultToolCall(lastMessage);
|
|
89
|
+
const toolCall = extractDefaultToolCall(lastMessage);
|
|
92
90
|
// Step 1: Check if we're retrying an existing task (NEEDS_CHANGES scenario)
|
|
93
91
|
const isRetry = !!loopmanTaskId;
|
|
94
92
|
if (toolCall) {
|
|
@@ -117,29 +115,14 @@ export function createLoopmanValidationNode(config) {
|
|
|
117
115
|
? `Validation required for tool: ${toolCall.name}`
|
|
118
116
|
: "Human validation required for this decision");
|
|
119
117
|
// Extract businessContext, proposedDecision, and decisionReasoning
|
|
120
|
-
const businessContext =
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
: options.decisionReasoning;
|
|
129
|
-
// Prepare additional information from state (enabled by default)
|
|
130
|
-
let additionalInformation;
|
|
131
|
-
const shouldIncludeState = options.includeFullState !== false; // Default to true
|
|
132
|
-
if (shouldIncludeState) {
|
|
133
|
-
if (options.formatState) {
|
|
134
|
-
additionalInformation = options.formatState(state);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
additionalInformation = convertStateToInformation(state);
|
|
138
|
-
}
|
|
139
|
-
logger.debug("[LoopmanNode] Including full state in task information", {
|
|
140
|
-
informationCount: additionalInformation.length,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
118
|
+
const businessContext = options.businessContext;
|
|
119
|
+
const proposedDecision = options.proposedDecision;
|
|
120
|
+
const decisionReasoning = options.decisionReasoning;
|
|
121
|
+
// Always include state information with default formatter
|
|
122
|
+
const additionalInformation = convertStateToInformation(state);
|
|
123
|
+
logger.debug("[LoopmanNode] Including full state in task information", {
|
|
124
|
+
informationCount: additionalInformation.length,
|
|
125
|
+
});
|
|
143
126
|
try {
|
|
144
127
|
const task = await loopmanService.createTaskForValidation(taskTitle, // Custom title
|
|
145
128
|
taskMessage, businessContext, undefined, // parentTaskId
|
|
@@ -244,12 +227,6 @@ export function createLoopmanValidationNode(config) {
|
|
|
244
227
|
*/
|
|
245
228
|
function convertStateToInformation(state) {
|
|
246
229
|
const information = [];
|
|
247
|
-
// Add a header indicating this is the full state
|
|
248
|
-
information.push({
|
|
249
|
-
type: "text",
|
|
250
|
-
label: "Full State",
|
|
251
|
-
value: "Complete agent state snapshot",
|
|
252
|
-
});
|
|
253
230
|
// Iterate through state properties
|
|
254
231
|
for (const [key, value] of Object.entries(state)) {
|
|
255
232
|
// Skip messages array (too verbose)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loopman-validation-node.js","sourceRoot":"","sources":["../../src/langgraph/loopman-validation-node.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"loopman-validation-node.js","sourceRoot":"","sources":["../../src/langgraph/loopman-validation-node.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAsClE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;G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E,EAAE;QACvC,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,IAAI,WAAW,CAAC;gBACrB,OAAO;gBACP,YAAY,EAAE,UAAU;aACzB,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IACvC,CAAC,CAAC;IAEF,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,UAAU;YACb,OAAO;gBACL,YAAY,CACV,QAAQ;oBACN,CAAC,CAAC,0CAA0C,QAAQ,GAAG;oBACvD,CAAC,CAAC,qDAAqD,CAC1D;aACF,CAAC;QAEJ,KAAK,UAAU;YACb,OAAO;gBACL,YAAY,CACV,QAAQ;oBACN,CAAC,CAAC,wCAAwC,QAAQ,GAAG;oBACrD,CAAC,CAAC,wDAAwD,CAC7D;aACF,CAAC;QAEJ,KAAK,eAAe;YAClB,OAAO;gBACL,YAAY,CACV,QAAQ;oBACN,CAAC,CAAC,yCAAyC,QAAQ,GAAG;oBACtD,CAAC,CAAC,mEAAmE,CACxE;aACF,CAAC;QAEJ,KAAK,SAAS;YACZ,OAAO;gBACL,YAAY,CACV,0DAA0D,CAC3D;aACF,CAAC;QAEJ,KAAK,SAAS,CAAC;QACf,KAAK,OAAO,CAAC;QACb;YACE,OAAO,CAAC,YAAY,CAAC,sBAAsB,MAAM,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC"}
|
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: typeof LoopmanGraphState.State) {\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 };\n}\n\n// Tool execution node\nasync function toolNode(state: typeof LoopmanGraphState.State) {\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: String(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: \"hello-world-workflow\",\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: \"hello-world-workflow\",\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.7\",\n \"@langchain/openai\": \"^1.0.0\",\n \"@loopman/langchain-sdk\": \"^1.17.
|
|
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.7\",\n \"@langchain/openai\": \"^1.0.0\",\n \"@loopman/langchain-sdk\": \"^1.17.4\",\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 \"types\": [\"node\"]\n },\n \"include\": [\"**/*.ts\"],\n \"exclude\": [\"node_modules\", \"dist\"]\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.7\",\n \"@langchain/openai\": \"^1.0.0\",\n \"@loopman/langchain-sdk\": \"^1.17.
|
|
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.7\",\n \"@langchain/openai\": \"^1.0.0\",\n \"@loopman/langchain-sdk\": \"^1.17.4\",\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",
|
|
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.7\",\n \"@langchain/openai\": \"^1.0.0\",\n \"@loopman/langchain-sdk\": \"^1.17.
|
|
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.7\",\n \"@langchain/openai\": \"^1.0.0\",\n \"@loopman/langchain-sdk\": \"^1.17.4\",\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",
|
|
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
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@langchain/mcp-adapters": "^1.0.0",
|
|
16
16
|
"@langchain/langgraph": "^1.0.7",
|
|
17
17
|
"@langchain/openai": "^1.0.0",
|
|
18
|
-
"@loopman/langchain-sdk": "^1.17.
|
|
18
|
+
"@loopman/langchain-sdk": "^1.17.4",
|
|
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.7",
|
|
17
17
|
"@langchain/openai": "^1.0.0",
|
|
18
|
-
"@loopman/langchain-sdk": "^1.17.
|
|
18
|
+
"@loopman/langchain-sdk": "^1.17.4",
|
|
19
19
|
"dotenv": "^17.2.3",
|
|
20
20
|
"langchain": "^1.0.2",
|
|
21
21
|
"tsx": "^4.20.6",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopman/langchain-sdk",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.4",
|
|
4
4
|
"description": "LangChain TypeScript SDK - Human-in-the-Loop validation via Loopman platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
"fix-esm": "node scripts/fix-esm-imports.mjs",
|
|
18
18
|
"clean": "rm -rf dist",
|
|
19
19
|
"release": "./scripts/release.sh",
|
|
20
|
-
"export-templates": "mkdir -p dist && node scripts/export-templates.mjs"
|
|
21
|
-
"example:langgraph-full-state": "tsx examples/5-langgraph-integration/full-state-example.ts"
|
|
20
|
+
"export-templates": "mkdir -p dist && node scripts/export-templates.mjs"
|
|
22
21
|
},
|
|
23
22
|
"keywords": [
|
|
24
23
|
"langchain",
|