-
Notifications
You must be signed in to change notification settings - Fork 371
feat(@langchain/langgraph): initial integration support #7412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
crysmags
wants to merge
6
commits into
master
Choose a base branch
from
crysmags/agentic-llm-langgraph-test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5c3719f
testing llm obs workflow using langGraph and Orchestrion
crysmags a85d0a1
fixing esm support
crysmags ec350c6
revert: remove test utility improvements from util.js
crysmags 6d3c48d
fix: apply eslint fixes to langgraph integration
crysmags c564838
ensuring we are finishing the span when the result is consumed from t…
crysmags fec5e8c
adding dependencies for langgraph
crysmags File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ declare -a plugins=( | |
| "knex" | ||
| "koa" | ||
| "langchain" | ||
| "langgraph" | ||
| "ldapjs" | ||
| "mariadb" | ||
| "memcached" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ | |
| module.exports = [ | ||
| ...require('./langchain'), | ||
| ...require('./bullmq'), | ||
| ...require('./langgraph'), | ||
| ] | ||
56 changes: 56 additions & 0 deletions
56
packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langgraph.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| 'use strict' | ||
|
|
||
| module.exports = [ | ||
| { | ||
| module: { | ||
| name: '@langchain/langgraph', | ||
| versionRange: '>=1.1.2', | ||
| filePath: 'dist/pregel/index.js', | ||
| }, | ||
| functionQuery: { | ||
| methodName: 'invoke', | ||
| className: 'Pregel', | ||
| kind: 'Async', | ||
| }, | ||
| channelName: 'Pregel_invoke', | ||
| }, | ||
| { | ||
| module: { | ||
| name: '@langchain/langgraph', | ||
| versionRange: '>=1.1.2', | ||
| filePath: 'dist/pregel/index.cjs', | ||
| }, | ||
| functionQuery: { | ||
| methodName: 'invoke', | ||
| className: 'Pregel', | ||
| kind: 'Async', | ||
| }, | ||
| channelName: 'Pregel_invoke', | ||
| }, | ||
| { | ||
| module: { | ||
| name: '@langchain/langgraph', | ||
| versionRange: '>=1.1.2', | ||
| filePath: 'dist/pregel/index.js', | ||
| }, | ||
| functionQuery: { | ||
| methodName: 'stream', | ||
| className: 'Pregel', | ||
| kind: 'Async', | ||
| }, | ||
| channelName: 'Pregel_stream', | ||
| }, | ||
| { | ||
| module: { | ||
| name: '@langchain/langgraph', | ||
| versionRange: '>=1.1.2', | ||
| filePath: 'dist/pregel/index.cjs', | ||
| }, | ||
| functionQuery: { | ||
| methodName: 'stream', | ||
| className: 'Pregel', | ||
| kind: 'Async', | ||
| }, | ||
| channelName: 'Pregel_stream', | ||
| }, | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| 'use strict' | ||
|
|
||
| const { addHook, getHooks } = require('./helpers/instrument') | ||
|
|
||
| for (const hook of getHooks('@langchain/langgraph')) { | ||
| addHook(hook, exports => exports) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| 'use strict' | ||
|
|
||
| const CompositePlugin = require('../../dd-trace/src/plugins/composite') | ||
| const langgraphLLMObsPlugins = require('../../dd-trace/src/llmobs/plugins/langgraph') | ||
| const internalPlugin = require('./internal') | ||
|
|
||
| const plugins = {} | ||
|
|
||
| // CRITICAL: LLMObs plugins MUST come first | ||
| for (const Plugin of langgraphLLMObsPlugins) { | ||
| plugins[Plugin.id] = Plugin | ||
| } | ||
|
|
||
| // Tracing plugins second | ||
| for (const [id, Plugin] of Object.entries(internalPlugin)) { | ||
| plugins[id] = Plugin | ||
| } | ||
|
|
||
| class LanggraphPlugin extends CompositePlugin { | ||
| static id = 'langgraph' | ||
| static plugins = plugins | ||
| } | ||
|
|
||
| module.exports = LanggraphPlugin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| 'use strict' | ||
|
|
||
| const TracingPlugin = require('../../dd-trace/src/plugins/tracing') | ||
|
|
||
| class BaseLanggraphInternalPlugin extends TracingPlugin { | ||
| static id = 'langgraph' | ||
| static prefix = 'tracing:orchestrion:@langchain/langgraph:Pregel_invoke' | ||
|
|
||
| bindStart (ctx) { | ||
| const meta = this.getTags(ctx) | ||
|
|
||
| this.startSpan('langgraph.invoke', { | ||
| service: this.config.service, | ||
| meta, | ||
| }, ctx) | ||
|
|
||
| return ctx.currentStore | ||
| } | ||
|
|
||
| getTags (ctx) { | ||
| return { | ||
| component: 'langgraph', | ||
| 'span.kind': 'internal', | ||
| } | ||
| } | ||
|
|
||
| asyncEnd (ctx) { | ||
| this.finish(ctx) | ||
| } | ||
| } | ||
|
|
||
| class PregelStreamPlugin extends TracingPlugin { | ||
| static prefix = 'tracing:orchestrion:@langchain/langgraph:Pregel_stream' | ||
|
|
||
| bindStart (ctx) { | ||
| this.startSpan('langgraph.stream', { | ||
| service: this.config.service, | ||
| component: 'langgraph', | ||
| 'span.kind': 'internal', | ||
| }, ctx) | ||
|
|
||
| return ctx.currentStore | ||
| } | ||
|
|
||
| asyncStart (ctx) { | ||
| const span = ctx.currentStore?.span | ||
| if (!span) { | ||
| return | ||
| } | ||
|
|
||
| const asyncIterable = ctx.result | ||
|
|
||
| const originalAsyncIterator = asyncIterable[Symbol.asyncIterator].bind(asyncIterable) | ||
|
|
||
| asyncIterable[Symbol.asyncIterator] = function () { | ||
| const originalIterator = originalAsyncIterator() | ||
|
|
||
| return { | ||
| async next (...args) { | ||
| try { | ||
| const result = await originalIterator.next(...args) | ||
|
|
||
| if (result.done) span.finish() | ||
|
|
||
| return result | ||
| } catch (error) { | ||
| span.setTag('error', error) | ||
| span.finish() | ||
| throw error | ||
| } | ||
| }, | ||
|
|
||
| async return (...args) { | ||
| span.finish() | ||
|
|
||
| if (originalIterator.return) { | ||
| return await originalIterator.return(...args) | ||
| } | ||
| return { done: true, value: undefined } | ||
| }, | ||
|
|
||
| async throw (error) { | ||
| span.setTag('error', error) | ||
| span.finish() | ||
|
|
||
| if (originalIterator.throw) { | ||
| return await originalIterator.throw(error) | ||
| } | ||
| throw error | ||
| }, | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| BaseLanggraphInternalPlugin, | ||
| PregelStreamPlugin, | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should try and do this in the
langgraph.jsinstrumentation file maybe, and add a custom subscriber there and useshimmer.wrapfor robustness. then we can emit a new event with the context that thisPregelStreamPlugincan listen forThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are trying to avoid this so that we can continue to use Orchestrion, right now since we only have
tracePromisewe need to handle this on the subscriber.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, what i mean is we can do this out directly in the
langgraph.jsinsteadjust so any/all custom wrapping logic happens in instrumentation and not in the plugins directly. lmk if this doesn't make any sense tho as idk if we do something like this currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a common pattern to mix publisher and subscriber logic in the instrumentation. I would think it would be cleaner to keep it on the subscriber/plugin side, but I can defer to @rochdev on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok i don't have too strong a preference, just that we had done something like that previously for langchain before we had some more orchestrion capabilities (ref).
i think in either case we should use
shimmerto patch instead of modifying properties directly (even if shimmer just does this directly under the hood)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we have to implement iterator support in orchestrion-js and @rochdev already has an open PR for that, so I guess that is related.