From 002c9a805a76139d08075a84961eccaf085112b3 Mon Sep 17 00:00:00 2001 From: akitaSummer Date: Wed, 14 Jan 2026 00:54:26 +0800 Subject: [PATCH 1/2] fix: add log --- plugin/langchain/lib/graph/CompiledStateGraphObject.ts | 8 ++++++++ .../langchain/app/modules/bar/controller/AppController.ts | 1 + plugin/langchain/test/llm.test.ts | 2 ++ 3 files changed, 11 insertions(+) diff --git a/plugin/langchain/lib/graph/CompiledStateGraphObject.ts b/plugin/langchain/lib/graph/CompiledStateGraphObject.ts index 8af5cbdd..f03f3299 100644 --- a/plugin/langchain/lib/graph/CompiledStateGraphObject.ts +++ b/plugin/langchain/lib/graph/CompiledStateGraphObject.ts @@ -37,6 +37,7 @@ export class CompiledStateGraphObject implements EggObject { const graph = this._obj as CompiledStateGraph; const originalInvoke = graph.invoke; + const originalStream = graph.stream; const langGraphTraceObj = await EggContainerFactory.getOrCreateEggObjectFromName('langGraphTracer'); const tracer = langGraphTraceObj.obj as LangGraphTracer; tracer.setName(this.graphName); @@ -47,6 +48,13 @@ export class CompiledStateGraphObject implements EggObject { return await originalInvoke.call(graph, input, config); }; + graph.stream = async (input: any, config?: any) => { + if (config?.tags?.includes('trace-log')) { + config.callbacks = [ tracer, ...(config?.callbacks || []) ]; + } + return await originalStream.call(graph, input, config) as any; + }; + this.status = EggObjectStatus.READY; } diff --git a/plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/controller/AppController.ts b/plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/controller/AppController.ts index 5c20bf76..39541eb6 100644 --- a/plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/controller/AppController.ts +++ b/plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/controller/AppController.ts @@ -51,6 +51,7 @@ export class AppController { configurable: { thread_id: '1', }, + tags: [ 'trace-log' ], }); return { diff --git a/plugin/langchain/test/llm.test.ts b/plugin/langchain/test/llm.test.ts index eca27953..35928dc9 100644 --- a/plugin/langchain/test/llm.test.ts +++ b/plugin/langchain/test/llm.test.ts @@ -72,9 +72,11 @@ describe('plugin/langchain/test/llm.test.ts', () => { }); it('should graph work', async () => { + app.mockLog(); await app.httpRequest() .get('/llm/graph') .expect(200, { value: 'hello graph toolhello world' }); + app.expectLog(/agent_run/); }); } }); From 7c15d9b1a5305e468e34ec3eac5d964ac0ab67f8 Mon Sep 17 00:00:00 2001 From: akitaSummer Date: Wed, 14 Jan 2026 11:31:18 +0800 Subject: [PATCH 2/2] fix: add options --- core/langchain-decorator/src/decorator/GraphNode.ts | 10 +++++++--- plugin/langchain/lib/graph/CompiledStateGraphObject.ts | 2 +- .../apps/langchain/app/modules/bar/service/Graph.ts | 10 +++++++--- plugin/langchain/test/llm.test.ts | 1 + 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/core/langchain-decorator/src/decorator/GraphNode.ts b/core/langchain-decorator/src/decorator/GraphNode.ts index b2a68350..164446d1 100644 --- a/core/langchain-decorator/src/decorator/GraphNode.ts +++ b/core/langchain-decorator/src/decorator/GraphNode.ts @@ -8,7 +8,7 @@ import { import { IGraphNodeMetadata } from '../model/GraphNodeMetadata'; import { GraphNodeInfoUtil } from '../util/GraphNodeInfoUtil'; -import { AnnotationRoot, StateDefinition, UpdateType } from '@langchain/langgraph'; +import { AnnotationRoot, Runtime, StateDefinition, StateGraph, UpdateType } from '@langchain/langgraph'; import { ConfigurableModel } from 'langchain/chat_models/universal'; import { ToolNode } from '@langchain/langgraph/prebuilt'; import { BaseChatOpenAI } from '@langchain/openai'; @@ -26,10 +26,14 @@ export function GraphNode(params: I }; } -export interface IGraphNode { +export type StateGraphAddNodeOptions = Parameters[2]; + +export type GraphRuntime, InterruptType = any, WriterType = any> = Runtime; - execute(state: AnnotationRoot['State']): Promise & Record> | Promise>; +export interface IGraphNode { + options?: StateGraphAddNodeOptions; + execute(state: AnnotationRoot['State'], options?: GraphRuntime): Promise & Record> | Promise>; build?: (tools: Parameters['0']) => Promise | ReturnType['bindTools']>>; } diff --git a/plugin/langchain/lib/graph/CompiledStateGraphObject.ts b/plugin/langchain/lib/graph/CompiledStateGraphObject.ts index f03f3299..08b0359b 100644 --- a/plugin/langchain/lib/graph/CompiledStateGraphObject.ts +++ b/plugin/langchain/lib/graph/CompiledStateGraphObject.ts @@ -95,7 +95,7 @@ export class CompiledStateGraphObject implements EggObject { if (TeggToolNode.prototype.isPrototypeOf(nodeObj)) { graphObj.addNode(nodeMetadata.nodeName, (nodeObj as unknown as TeggToolNode).toolNode); } else { - graphObj.addNode(nodeMetadata.nodeName, nodeObj.execute.bind(nodeObj)); + graphObj.addNode(nodeMetadata.nodeName, nodeObj.execute.bind(nodeObj), nodeObj.options); } } } diff --git a/plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/service/Graph.ts b/plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/service/Graph.ts index a22627f4..5e9991aa 100644 --- a/plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/service/Graph.ts +++ b/plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/service/Graph.ts @@ -1,5 +1,5 @@ -import { AccessLevel, SingletonProto, ToolArgs, ToolArgsSchema } from '@eggjs/tegg'; -import { Graph, GraphEdge, IGraphEdge, AbstractStateGraph, GraphNode, IGraphNode, GraphStateType, GraphTool, IGraphTool, TeggToolNode } from '@eggjs/tegg-langchain-decorator'; +import { AccessLevel, Inject, Logger, SingletonProto, ToolArgs, ToolArgsSchema } from '@eggjs/tegg'; +import { Graph, GraphEdge, IGraphEdge, AbstractStateGraph, GraphNode, IGraphNode, GraphStateType, GraphTool, IGraphTool, TeggToolNode, GraphRuntime } from '@eggjs/tegg-langchain-decorator'; import { Annotation, MemorySaver } from '@langchain/langgraph'; // import { AIMessage, BaseMessage, ToolMessage } from '@langchain/core/messages'; import * as z from 'zod/v4'; @@ -54,7 +54,11 @@ export class FooTool implements IGraphTool { mcpServers: [ 'bar' ], }) export class FooNode implements IGraphNode { - async execute(state: GraphStateType) { + @Inject() + logger: Logger; + + async execute(state: GraphStateType, options: GraphRuntime) { + this.logger.info('Executing FooNode thread_id is', options.configurable?.thread_id); console.log('response: ', state.messages); const messages = state.messages; const lastMessage = messages[messages.length - 1]; diff --git a/plugin/langchain/test/llm.test.ts b/plugin/langchain/test/llm.test.ts index 35928dc9..ac15fad5 100644 --- a/plugin/langchain/test/llm.test.ts +++ b/plugin/langchain/test/llm.test.ts @@ -77,6 +77,7 @@ describe('plugin/langchain/test/llm.test.ts', () => { .get('/llm/graph') .expect(200, { value: 'hello graph toolhello world' }); app.expectLog(/agent_run/); + app.expectLog(/Executing FooNode thread_id is 1/); }); } });