Skip to content

Commit 14691ab

Browse files
committed
LangGraph agent
1 parent 8721804 commit 14691ab

File tree

4 files changed

+36
-51
lines changed

4 files changed

+36
-51
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2026 New Relic Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
const LlmEvent = require('../base')
7+
8+
/**
9+
* Encapsulates a `@langchain/langgraph` LlmAgent event.
10+
*/
11+
class LangGraphLlmAgent extends LlmEvent {
12+
/**
13+
*
14+
* @param {object} params constructor parameters
15+
* @param {Agent} params.agent New Relic agent instance
16+
* @param {object} params.segment Current segment
17+
* @param {object} params.transaction Current and active transaction
18+
* @param {string} params.aiAgentName Name of the AI agent which can typically be captured through framework context
19+
* @param {boolean} [params.error] Set to `true` if an error occurred during creation call, omitted if no error occurred
20+
*/
21+
constructor({ agent, segment, transaction, aiAgentName, error }) {
22+
super({ agent, segment, transaction, vendor: 'langgraph', error })
23+
this.name = aiAgentName ?? 'agent'
24+
}
25+
}
26+
27+
module.exports = LangGraphLlmAgent

lib/llm-events/langgraph/agent.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

lib/subscribers/langgraph/graph-stream.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
const AiMonitoringSubscriber = require('../ai-monitoring/base')
77
const LlmErrorMessage = require('#agentlib/llm-events/error-message.js')
8-
const LangGraphAgentEvent = require('#agentlib/llm-events/langgraph/agent.js')
8+
const LlmAgent = require('#agentlib/llm-events-new/langgraph/agent.js')
99
const { AI: { LANGGRAPH, STREAMING_DISABLED } } = require('#agentlib/metrics/names.js')
1010

1111
class LangGraphStreamSubscriber extends AiMonitoringSubscriber {
@@ -104,9 +104,9 @@ class LangGraphStreamSubscriber extends AiMonitoringSubscriber {
104104
recordAiAgentEvent({ aiAgentName, transaction, segment, error }) {
105105
const { agent } = this
106106
segment.end()
107-
const agentEvent = new LangGraphAgentEvent({
107+
const agentEvent = new LlmAgent({
108108
agent,
109-
name: aiAgentName,
109+
aiAgentName,
110110
transaction,
111111
segment,
112112
error: !!error

test/unit/llm-events/langgraph/agent.test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
const test = require('node:test')
99
const assert = require('node:assert')
10-
const LangGraphAgentEvent = require('../../../../lib/llm-events/langgraph/agent')
10+
const LlmAgent = require('#agentlib/llm-events-new/langgraph/agent.js')
1111

1212
test.beforeEach((ctx) => {
1313
ctx.nr = {}
@@ -43,29 +43,28 @@ test.beforeEach((ctx) => {
4343
id: 'segment-1'
4444
}
4545

46-
ctx.nr.name = 'test-agent'
46+
ctx.nr.aiAgentName = 'test-agent'
4747
})
4848

4949
test('constructs default instance', async (t) => {
50-
const event = new LangGraphAgentEvent(t.nr)
50+
const event = new LlmAgent(t.nr)
5151
assert.equal(event.name, 'test-agent')
5252
assert.match(event.id, /[a-z0-9-]{36}/)
5353
assert.equal(event.span_id, 'segment-1')
5454
assert.equal(event.trace_id, 'trace-1')
5555
assert.equal(event['llm.foo'], 'bar')
5656
assert.equal(event.ingest_source, 'Node')
5757
assert.equal(event.vendor, 'langgraph')
58-
assert.equal(event.error, false)
5958
})
6059

6160
test('constructs instance with error', async (t) => {
6261
t.nr.error = true
63-
const event = new LangGraphAgentEvent(t.nr)
62+
const event = new LlmAgent(t.nr)
6463
assert.equal(event.error, true)
6564
})
6665

6766
test('uses default name when not provided', async (t) => {
68-
delete t.nr.name
69-
const event = new LangGraphAgentEvent(t.nr)
67+
delete t.nr.aiAgentName
68+
const event = new LlmAgent(t.nr)
7069
assert.equal(event.name, 'agent')
7170
})

0 commit comments

Comments
 (0)