Skip to content

fix(gettingStartedDocs): Update LangGraph example to use StateGraph API#109551

Merged
priscilawebdev merged 2 commits intomasterfrom
fix/agent-monitoring-langgraph-example
Feb 27, 2026
Merged

fix(gettingStartedDocs): Update LangGraph example to use StateGraph API#109551
priscilawebdev merged 2 commits intomasterfrom
fix/agent-monitoring-langgraph-example

Conversation

@priscilawebdev
Copy link
Member

@priscilawebdev priscilawebdev commented Feb 27, 2026

Update the LangGraph code snippet in the agent monitoring getting started guide.

instrumentLangGraph works by wrapping the .compile() method on a StateGraph to intercept the compilation step and inject tracing. This means it must be called before .compile() is invoked.

createReactAgent calls .compile() internally and returns the already-compiled graph — there's no hook point between graph construction and compilation. By the time you get the return value, the compile step has already happened, making it too late for instrumentLangGraph to do its job.

In short: createReactAgent hides the compile step, but instrumentLangGraph needs to wrap that exact step. They are fundamentally incompatible with the current SDK API.

The fix replaces createReactAgent with the lower-level StateGraph + MessagesAnnotation pattern, which keeps the compile step explicit and accessible.

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Feb 27, 2026
Replace createReactAgent with StateGraph and MessagesAnnotation in the
agent monitoring getting started guide.

instrumentLangGraph works by wrapping the .compile() method on a
StateGraph to intercept the compilation step and inject tracing.
This means it must be called before .compile() is invoked.

createReactAgent calls .compile() internally and returns the
already-compiled graph — there's no hook point between graph
construction and compilation. By the time you get the return value,
the compile step has already happened, making it too late for
instrumentLangGraph to do its job.

In short: createReactAgent hides the compile step, but
instrumentLangGraph needs to wrap that exact step. They are
fundamentally incompatible with the current SDK API.

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@shellmayr
Copy link
Member

If I'm not reading this entirely wrong, we have an issue in the SDK. The createReactAgent pattern is widespread for agents built with LangGraph and should be a functional example. Stategraphs should be wrapped, no matter where or how they are instantiated. @RulaKhaled is this an inherent limitation or can we do something about the way this is instrumented so that the createReactAgent path is also supported?

@priscilawebdev
Copy link
Member Author

If I'm not reading this entirely wrong, we have an issue in the SDK. The createReactAgent pattern is widespread for agents built with LangGraph and should be a functional example. Stategraphs should be wrapped, no matter where or how they are instantiated. @RulaKhaled is this an inherent limitation or can we do something about the way this is instrumented so that the createReactAgent path is also supported?

Agree! we should fix that. But for now, let’s have something that actually works as an example until the fix is ready

Copy link
Member

@shellmayr shellmayr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall - please address the agent comments regarding the end node in the graph before merging 🙏 (unless it's not an issue in practice of course)

Without an edge from the agent node to __end__, the StateGraph has no
termination path, causing agent.invoke() to fail at runtime.

Co-Authored-By: Claude <noreply@anthropic.com>
@priscilawebdev
Copy link
Member Author

Looks good overall - please address the agent comments regarding the end node in the graph before merging 🙏 (unless it's not an issue in practice of course)

yes, the commit should be here in any minute . Thanks for reviewing

@nicohrubec
Copy link
Member

@shellmayr We have something in the works for createReactAgent (see this PR). That one has been in the works for quite some time because we were struggling with some IITM and Otel limitations that we had to work out first, but hoping we can land that soonish

Copy link
Member

@nicohrubec nicohrubec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thank you

@priscilawebdev priscilawebdev merged commit abe4733 into master Feb 27, 2026
60 checks passed
@priscilawebdev priscilawebdev deleted the fix/agent-monitoring-langgraph-example branch February 27, 2026 10:30
@github-actions github-actions bot locked and limited conversation to collaborators Mar 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants