feat(core): Instrument langgraph createReactAgent#20344
Draft
andreiborza wants to merge 1 commit intodevelopfrom
Draft
feat(core): Instrument langgraph createReactAgent#20344andreiborza wants to merge 1 commit intodevelopfrom
andreiborza wants to merge 1 commit intodevelopfrom
Conversation
6aa24b0 to
09a4132
Compare
Contributor
size-limit report 📦
|
This PR adds instrumentation for LangGraph's `createReactAgent` API. It: - extracts agent name, LLM model, and tools from params - wraps compiled graph's `invoke()` with invoke_agent span - wraps tool `invoke()` with execute_tool spans (name, type, description, arguments, result per our new conventions) - injects LangChain callback handler + `lc_agent_name` metadata at invoke level for chat span creation and agent name propagation to all child spans - suppresses `StateGraph.compile` instrumentation inside `createReactAgent` to avoid duplicate spans The LangChain callback handler was improved to: - read gen_ai.agent.name from `metadata.lc_agent_name` (this is a convention in newer versions of LangGraph createAgent so we took this over for our supported version) - suppresses chain and tool callback spans inside agent context to avoid duplicates with our direct instrumentation (based on `metadata.loc_agent_name` presence) - extracts tool definitions from `extraParams` in `handleChatModelStart` - supports OpenAI tool calls via `message.tool_calls` (not just Anthropic content scanning) - normalizes tool call format and use our new convention attributes - uses `runName` for tool name (set by LangChain's StructuredTool) It exports: - `instrumentCreateReactAgent` from core, browser, cloudflare - New constants: - GEN_AI_TOOL_CALL_ARGUMENTS_ATTRIBUTE, - GEN_AI_TOOL_CALL_RESULT_ATTRIBUTE Closes: #19372
09a4132 to
e2d8d45
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds instrumentation for LangGraph's
createReactAgentAPI.It:
invoke()with invoke_agent spaninvoke()with execute_tool spans (name, type, description, arguments, result per our new conventions)lc_agent_namemetadata at invoke level for chat span creation and agent name propagation to all child spansStateGraph.compileinstrumentation insidecreateReactAgentto avoid duplicate spansThe LangChain callback handler was improved to:
metadata.lc_agent_name(this is a convention in newer versions of LangGraph createAgent so we took this over for our supported version)metadata.loc_agent_namepresence)extraParamsinhandleChatModelStartmessage.tool_calls(not just Anthropic content scanning)runNamefor tool name (set by LangChain's StructuredTool)It exports:
instrumentCreateReactAgentfrom core, browser, cloudflareGEN_AI_TOOL_CALL_ARGUMENTS_ATTRIBUTE,GEN_AI_TOOL_CALL_RESULT_ATTRIBUTECloses: #19372