@arizeai/openinference-instrumentation-beeai 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/helpers/getSerializedObjectSafe.d.ts.map +1 -1
- package/dist/esm/helpers/getSerializedObjectSafe.js +171 -164
- package/dist/esm/helpers/getSerializedObjectSafe.js.map +1 -1
- package/dist/esm/middleware.d.ts.map +1 -1
- package/dist/esm/middleware.js +113 -81
- package/dist/esm/middleware.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esnext/helpers/getSerializedObjectSafe.d.ts.map +1 -1
- package/dist/esnext/helpers/getSerializedObjectSafe.js +128 -121
- package/dist/esnext/helpers/getSerializedObjectSafe.js.map +1 -1
- package/dist/esnext/middleware.d.ts.map +1 -1
- package/dist/esnext/middleware.js +103 -71
- package/dist/esnext/middleware.js.map +1 -1
- package/dist/esnext/tsconfig.esnext.tsbuildinfo +1 -1
- package/dist/examples/run-react-agent.d.ts +2 -0
- package/dist/examples/run-react-agent.d.ts.map +1 -0
- package/dist/examples/{run-agent.js → run-react-agent.js} +1 -1
- package/dist/examples/run-react-agent.js.map +1 -0
- package/dist/examples/run-toolcalling-agent.d.ts +2 -0
- package/dist/examples/run-toolcalling-agent.d.ts.map +1 -0
- package/dist/examples/run-toolcalling-agent.js +36 -0
- package/dist/examples/run-toolcalling-agent.js.map +1 -0
- package/dist/src/helpers/getSerializedObjectSafe.d.ts.map +1 -1
- package/dist/src/helpers/getSerializedObjectSafe.js +128 -121
- package/dist/src/helpers/getSerializedObjectSafe.js.map +1 -1
- package/dist/src/middleware.d.ts.map +1 -1
- package/dist/src/middleware.js +103 -71
- package/dist/src/middleware.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/helpers/getSerializedObjectSafe.ts +222 -210
- package/src/middleware.ts +140 -98
- package/dist/examples/run-agent.d.ts +0 -2
- package/dist/examples/run-agent.d.ts.map +0 -1
- package/dist/examples/run-agent.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-react-agent.d.ts","sourceRoot":"","sources":["../../examples/run-react-agent.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-react-agent.js","sourceRoot":"","sources":["../../examples/run-react-agent.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA2B;AAC3B,8DAAgE;AAChE,uEAA+E;AAC/E,oEAAiE;AACjE,oFAAqF;AACrF,uEAAwE;AAExE,MAAM,GAAG,GAAG,IAAI,sBAAe,CAAC,UAAU,CAAC,CAAC,CAAC,+DAA+D;AAC5G,MAAM,KAAK,GAAG,IAAI,kBAAU,CAAC;IAC3B,GAAG,EAAE,8CAA8C;IACnD,MAAM,EAAE,IAAI,yBAAW,EAAE,EAAE,4CAA4C;IACvE,KAAK,EAAE,CAAC,IAAI,uCAAoB,EAAE,EAAE,IAAI,yBAAa,EAAE,CAAC,EAAE,2CAA2C;CACtG,CAAC,CAAC;AAEH,SAAe,IAAI;;QACjB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC;YAC/B,MAAM,EAAE,0CAA0C;SACnD,CAAC,CAAC;QACH,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;CAAA;AAED,sCAAsC;AACtC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-toolcalling-agent.d.ts","sourceRoot":"","sources":["../../examples/run-toolcalling-agent.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
require("./instrumentation");
|
|
13
|
+
const tokenMemory_1 = require("beeai-framework/memory/tokenMemory");
|
|
14
|
+
const openMeteo_1 = require("beeai-framework/tools/weather/openMeteo");
|
|
15
|
+
const chat_1 = require("beeai-framework/adapters/ollama/backend/chat");
|
|
16
|
+
const agent_1 = require("beeai-framework/agents/toolCalling/agent");
|
|
17
|
+
const duckDuckGoSearch_1 = require("beeai-framework/tools/search/duckDuckGoSearch");
|
|
18
|
+
const llm = new chat_1.OllamaChatModel("llama3.1");
|
|
19
|
+
const agent = new agent_1.ToolCallingAgent({
|
|
20
|
+
llm,
|
|
21
|
+
memory: new tokenMemory_1.TokenMemory(),
|
|
22
|
+
tools: [
|
|
23
|
+
new duckDuckGoSearch_1.DuckDuckGoSearchTool(),
|
|
24
|
+
new openMeteo_1.OpenMeteoTool(), // weather tool
|
|
25
|
+
],
|
|
26
|
+
});
|
|
27
|
+
function main() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const response = yield agent.run({ prompt: "How are you?" });
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
console.log(`Agent 🤖 : `, response.result.text);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// eslint-disable-next-line no-console
|
|
35
|
+
main().catch(console.error);
|
|
36
|
+
//# sourceMappingURL=run-toolcalling-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-toolcalling-agent.js","sourceRoot":"","sources":["../../examples/run-toolcalling-agent.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6BAA2B;AAC3B,oEAAiE;AACjE,uEAAwE;AACxE,uEAA+E;AAC/E,oEAA4E;AAC5E,oFAAqF;AAErF,MAAM,GAAG,GAAG,IAAI,sBAAe,CAAC,UAAU,CAAC,CAAC;AAC5C,MAAM,KAAK,GAAG,IAAI,wBAAgB,CAAC;IACjC,GAAG;IACH,MAAM,EAAE,IAAI,yBAAW,EAAE;IACzB,KAAK,EAAE;QACL,IAAI,uCAAoB,EAAE;QAC1B,IAAI,yBAAa,EAAE,EAAE,eAAe;KACrC;CACF,CAAC,CAAC;AAEH,SAAe,IAAI;;QACjB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC;QAC7D,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;CAAA;AAED,sCAAsC;AACtC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSerializedObjectSafe.d.ts","sourceRoot":"","sources":["../../../src/helpers/getSerializedObjectSafe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,SAAS,EAAsB,MAAM,+BAA+B,CAAC;AAyE9E,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,OAAO,EACnB,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"getSerializedObjectSafe.d.ts","sourceRoot":"","sources":["../../../src/helpers/getSerializedObjectSafe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,SAAS,EAAsB,MAAM,+BAA+B,CAAC;AAyE9E,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,OAAO,EACnB,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,OAgPzB"}
|
|
@@ -37,132 +37,139 @@ function parseLLMOutputMessages(messages) {
|
|
|
37
37
|
.join("") })), {});
|
|
38
38
|
}
|
|
39
39
|
function getSerializedObjectSafe(dataObject, meta) {
|
|
40
|
-
var _a, _b, _c, _d, _e, _f;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
[openinference_semantic_conventions_1.SemanticConventions.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (
|
|
40
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
41
|
+
try {
|
|
42
|
+
// agent events
|
|
43
|
+
if ([
|
|
44
|
+
config_1.startEventName,
|
|
45
|
+
config_1.successEventName,
|
|
46
|
+
config_1.errorEventName,
|
|
47
|
+
config_1.retryEventName,
|
|
48
|
+
].includes(meta.name) &&
|
|
49
|
+
meta.creator instanceof base_1.BaseAgent) {
|
|
50
|
+
const { meta, tools, memory, error, data } = dataObject;
|
|
51
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({ [openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND]: openinference_semantic_conventions_1.OpenInferenceSpanKind.AGENT, iteration: meta === null || meta === void 0 ? void 0 : meta.iteration }, ((tools === null || tools === void 0 ? void 0 : tools.length) > 0 && {
|
|
52
|
+
[openinference_semantic_conventions_1.SemanticConventions.LLM_TOOLS]: tools.map((tool) => ({
|
|
53
|
+
[openinference_semantic_conventions_1.SemanticConventions.TOOL_NAME]: tool.name,
|
|
54
|
+
[openinference_semantic_conventions_1.SemanticConventions.TOOL_DESCRIPTION]: tool.description,
|
|
55
|
+
"tool.options": tool.options,
|
|
56
|
+
})),
|
|
57
|
+
})), ((memory === null || memory === void 0 ? void 0 : memory.messages.length) > 0 && {
|
|
58
|
+
[openinference_semantic_conventions_1.SemanticConventions.INPUT_MIME_TYPE]: openinference_semantic_conventions_1.MimeType.JSON,
|
|
59
|
+
[openinference_semantic_conventions_1.SemanticConventions.INPUT_VALUE]: JSON.stringify(memory.messages),
|
|
60
|
+
})), (error && {
|
|
61
|
+
"exception.message": error.message,
|
|
62
|
+
"exception.stacktrace": error.stack,
|
|
63
|
+
"exception.type": error.name,
|
|
64
|
+
})), (data && {
|
|
65
|
+
[openinference_semantic_conventions_1.SemanticConventions.OUTPUT_MIME_TYPE]: openinference_semantic_conventions_1.MimeType.JSON,
|
|
66
|
+
[openinference_semantic_conventions_1.SemanticConventions.OUTPUT_VALUE]: JSON.stringify(data),
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
// update events
|
|
70
|
+
if ([config_1.updateEventName, config_1.partialUpdateEventName].includes(meta.name)) {
|
|
71
|
+
const { data } = dataObject;
|
|
72
|
+
const output = (data === null || data === void 0 ? void 0 : data.final_answer) || (data === null || data === void 0 ? void 0 : data.tool_output);
|
|
73
|
+
return Object.assign(Object.assign(Object.assign({ [openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND]: openinference_semantic_conventions_1.OpenInferenceSpanKind.AGENT, thought: data.thought }, ((data === null || data === void 0 ? void 0 : data.tool_name) && {
|
|
74
|
+
[openinference_semantic_conventions_1.SemanticConventions.TOOL_NAME]: data.tool_name,
|
|
75
|
+
})), ((data === null || data === void 0 ? void 0 : data.tool_input) && {
|
|
76
|
+
[openinference_semantic_conventions_1.SemanticConventions.TOOL_PARAMETERS]: JSON.stringify(data.tool_input),
|
|
77
|
+
})), (output && {
|
|
78
|
+
[openinference_semantic_conventions_1.SemanticConventions.OUTPUT_MIME_TYPE]: openinference_semantic_conventions_1.MimeType.JSON,
|
|
79
|
+
[openinference_semantic_conventions_1.SemanticConventions.OUTPUT_VALUE]: output,
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
// tool events (from agent)
|
|
83
|
+
if ([config_1.toolErrorEventName, config_1.toolStartEventName, config_1.toolSuccessEventName].includes(meta.name)) {
|
|
84
|
+
const { data } = dataObject;
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
+
const output = (data === null || data === void 0 ? void 0 : data.result) && data.result.createSnapshot();
|
|
87
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ [openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND]: openinference_semantic_conventions_1.OpenInferenceSpanKind.TOOL, thought: (_a = data === null || data === void 0 ? void 0 : data.iteration) === null || _a === void 0 ? void 0 : _a.thought }, ((data === null || data === void 0 ? void 0 : data.input)
|
|
88
|
+
? {
|
|
89
|
+
[openinference_semantic_conventions_1.SemanticConventions.TOOL_PARAMETERS]: JSON.stringify(data.input),
|
|
90
|
+
}
|
|
91
|
+
: {})), ((data === null || data === void 0 ? void 0 : data.tool.description) && {
|
|
92
|
+
[openinference_semantic_conventions_1.SemanticConventions.TOOL_DESCRIPTION]: data.tool.description,
|
|
93
|
+
})), ((data === null || data === void 0 ? void 0 : data.tool.name) && {
|
|
94
|
+
[openinference_semantic_conventions_1.SemanticConventions.TOOL_NAME]: data.tool.name,
|
|
95
|
+
})), ((data === null || data === void 0 ? void 0 : data.error) && {
|
|
96
|
+
"exception.message": data.error.message,
|
|
97
|
+
"exception.stacktrace": data.error.stack,
|
|
98
|
+
"exception.type": data.error.name,
|
|
99
|
+
})), (output && {
|
|
100
|
+
[openinference_semantic_conventions_1.SemanticConventions.OUTPUT_VALUE]: JSON.stringify(output),
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
// tool events native
|
|
104
|
+
if ([
|
|
105
|
+
config_1.startToolEventName,
|
|
106
|
+
config_1.successToolEventName,
|
|
107
|
+
config_1.finishToolEventName,
|
|
108
|
+
config_1.errorToolEventName,
|
|
109
|
+
config_1.retryToolEventName,
|
|
110
|
+
].includes(meta.name) &&
|
|
111
|
+
meta.creator instanceof base_2.Tool) {
|
|
112
|
+
if (!dataObject) {
|
|
113
|
+
return {
|
|
114
|
+
[openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND]: openinference_semantic_conventions_1.OpenInferenceSpanKind.TOOL,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const { input, output, error } = dataObject;
|
|
118
|
+
return Object.assign(Object.assign(Object.assign({ [openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND]: openinference_semantic_conventions_1.OpenInferenceSpanKind.TOOL }, (input
|
|
119
|
+
? { [openinference_semantic_conventions_1.SemanticConventions.TOOL_PARAMETERS]: JSON.stringify(input) }
|
|
120
|
+
: {})), (output && {
|
|
121
|
+
[openinference_semantic_conventions_1.SemanticConventions.OUTPUT_VALUE]: JSON.stringify(output),
|
|
122
|
+
})), (error && {
|
|
123
|
+
"exception.message": error.message,
|
|
124
|
+
"exception.stacktrace": error.stack,
|
|
125
|
+
"exception.type": error.name,
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
// llm events
|
|
129
|
+
if ([
|
|
130
|
+
config_1.successLLMEventName,
|
|
131
|
+
config_1.startLLMEventName,
|
|
132
|
+
config_1.errorLLMEventName,
|
|
133
|
+
config_1.newTokenLLMEventName,
|
|
134
|
+
].includes(meta.name) &&
|
|
135
|
+
meta.creator instanceof chat_1.ChatModel) {
|
|
136
|
+
const { value, input, error } = dataObject;
|
|
137
|
+
const creator = meta.creator.createSnapshot();
|
|
138
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ [openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND]: openinference_semantic_conventions_1.OpenInferenceSpanKind.LLM }, (((_b = value === null || value === void 0 ? void 0 : value.usage) === null || _b === void 0 ? void 0 : _b.completionTokens) && {
|
|
139
|
+
[openinference_semantic_conventions_1.SemanticConventions.LLM_TOKEN_COUNT_COMPLETION]: (_c = value === null || value === void 0 ? void 0 : value.usage) === null || _c === void 0 ? void 0 : _c.completionTokens,
|
|
140
|
+
})), (((_d = value === null || value === void 0 ? void 0 : value.usage) === null || _d === void 0 ? void 0 : _d.promptTokens) && {
|
|
141
|
+
[openinference_semantic_conventions_1.SemanticConventions.LLM_TOKEN_COUNT_PROMPT]: (_e = value === null || value === void 0 ? void 0 : value.usage) === null || _e === void 0 ? void 0 : _e.promptTokens,
|
|
142
|
+
})), (((_f = value === null || value === void 0 ? void 0 : value.usage) === null || _f === void 0 ? void 0 : _f.totalTokens) && {
|
|
143
|
+
[openinference_semantic_conventions_1.SemanticConventions.LLM_TOKEN_COUNT_TOTAL]: (_g = value === null || value === void 0 ? void 0 : value.usage) === null || _g === void 0 ? void 0 : _g.totalTokens,
|
|
144
|
+
})), ((input === null || input === void 0 ? void 0 : input.messages.length) > 0 && Object.assign({ [openinference_semantic_conventions_1.SemanticConventions.INPUT_MIME_TYPE]: openinference_semantic_conventions_1.MimeType.JSON, [openinference_semantic_conventions_1.SemanticConventions.INPUT_VALUE]: JSON.stringify(input.messages) }, parserLLMInputMessages(input.messages)))), ((value === null || value === void 0 ? void 0 : value.messages.length) > 0 && Object.assign({ [openinference_semantic_conventions_1.SemanticConventions.OUTPUT_MIME_TYPE]: openinference_semantic_conventions_1.MimeType.JSON, [openinference_semantic_conventions_1.SemanticConventions.OUTPUT_VALUE]: JSON.stringify(value.messages) }, parseLLMOutputMessages(value.messages)))), (error && {
|
|
145
|
+
"exception.message": error.message,
|
|
146
|
+
"exception.stacktrace": error.stack,
|
|
147
|
+
"exception.type": error.name,
|
|
148
|
+
})), ("providerId" in creator && {
|
|
149
|
+
[openinference_semantic_conventions_1.SemanticConventions.LLM_PROVIDER]: creator.providerId,
|
|
150
|
+
[`${openinference_semantic_conventions_1.SemanticAttributePrefixes.metadata}.${openinference_semantic_conventions_1.LLMAttributePostfixes.provider}`]: creator.providerId,
|
|
151
|
+
})), ("modelId" in creator && {
|
|
152
|
+
[openinference_semantic_conventions_1.SemanticConventions.LLM_MODEL_NAME]: creator.modelId,
|
|
153
|
+
[`${openinference_semantic_conventions_1.SemanticAttributePrefixes.metadata}.${openinference_semantic_conventions_1.LLMAttributePostfixes.model_name}`]: creator.modelId,
|
|
154
|
+
})), ((creator === null || creator === void 0 ? void 0 : creator.parameters) && {
|
|
155
|
+
[openinference_semantic_conventions_1.SemanticConventions.LLM_INVOCATION_PARAMETERS]: JSON.stringify(creator.parameters),
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
if (meta.name === config_1.finishLLMEventName && meta.creator instanceof chat_1.ChatModel) {
|
|
105
159
|
return {
|
|
106
|
-
[openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND]: openinference_semantic_conventions_1.OpenInferenceSpanKind.
|
|
160
|
+
[openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND]: openinference_semantic_conventions_1.OpenInferenceSpanKind.LLM,
|
|
107
161
|
};
|
|
108
162
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
: {})), (output && {
|
|
113
|
-
[openinference_semantic_conventions_1.SemanticConventions.OUTPUT_VALUE]: JSON.stringify(output),
|
|
114
|
-
})), (error && {
|
|
115
|
-
"exception.message": error.message,
|
|
116
|
-
"exception.stacktrace": error.stack,
|
|
117
|
-
"exception.type": error.name,
|
|
118
|
-
}));
|
|
119
|
-
}
|
|
120
|
-
// llm events
|
|
121
|
-
if ([
|
|
122
|
-
config_1.successLLMEventName,
|
|
123
|
-
config_1.startLLMEventName,
|
|
124
|
-
config_1.errorLLMEventName,
|
|
125
|
-
config_1.newTokenLLMEventName,
|
|
126
|
-
].includes(meta.name) &&
|
|
127
|
-
meta.creator instanceof chat_1.ChatModel) {
|
|
128
|
-
const { value, input, error } = dataObject;
|
|
129
|
-
const creator = meta.creator.createSnapshot();
|
|
130
|
-
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ [openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND]: openinference_semantic_conventions_1.OpenInferenceSpanKind.LLM }, (((_a = value === null || value === void 0 ? void 0 : value.usage) === null || _a === void 0 ? void 0 : _a.completionTokens) && {
|
|
131
|
-
[openinference_semantic_conventions_1.SemanticConventions.LLM_TOKEN_COUNT_COMPLETION]: (_b = value === null || value === void 0 ? void 0 : value.usage) === null || _b === void 0 ? void 0 : _b.completionTokens,
|
|
132
|
-
})), (((_c = value === null || value === void 0 ? void 0 : value.usage) === null || _c === void 0 ? void 0 : _c.promptTokens) && {
|
|
133
|
-
[openinference_semantic_conventions_1.SemanticConventions.LLM_TOKEN_COUNT_PROMPT]: (_d = value === null || value === void 0 ? void 0 : value.usage) === null || _d === void 0 ? void 0 : _d.promptTokens,
|
|
134
|
-
})), (((_e = value === null || value === void 0 ? void 0 : value.usage) === null || _e === void 0 ? void 0 : _e.totalTokens) && {
|
|
135
|
-
[openinference_semantic_conventions_1.SemanticConventions.LLM_TOKEN_COUNT_TOTAL]: (_f = value === null || value === void 0 ? void 0 : value.usage) === null || _f === void 0 ? void 0 : _f.totalTokens,
|
|
136
|
-
})), ((input === null || input === void 0 ? void 0 : input.messages.length) > 0 && Object.assign({ [openinference_semantic_conventions_1.SemanticConventions.INPUT_MIME_TYPE]: openinference_semantic_conventions_1.MimeType.JSON, [openinference_semantic_conventions_1.SemanticConventions.INPUT_VALUE]: JSON.stringify(input.messages) }, parserLLMInputMessages(input.messages)))), ((value === null || value === void 0 ? void 0 : value.messages.length) > 0 && Object.assign({ [openinference_semantic_conventions_1.SemanticConventions.OUTPUT_MIME_TYPE]: openinference_semantic_conventions_1.MimeType.JSON, [openinference_semantic_conventions_1.SemanticConventions.OUTPUT_VALUE]: JSON.stringify(value.messages) }, parseLLMOutputMessages(value.messages)))), (error && {
|
|
137
|
-
"exception.message": error.message,
|
|
138
|
-
"exception.stacktrace": error.stack,
|
|
139
|
-
"exception.type": error.name,
|
|
140
|
-
})), ("providerId" in creator && {
|
|
141
|
-
[openinference_semantic_conventions_1.SemanticConventions.LLM_PROVIDER]: creator.providerId,
|
|
142
|
-
[`${openinference_semantic_conventions_1.SemanticAttributePrefixes.metadata}.${openinference_semantic_conventions_1.LLMAttributePostfixes.provider}`]: creator.providerId,
|
|
143
|
-
})), ("modelId" in creator && {
|
|
144
|
-
[openinference_semantic_conventions_1.SemanticConventions.LLM_MODEL_NAME]: creator.modelId,
|
|
145
|
-
[`${openinference_semantic_conventions_1.SemanticAttributePrefixes.metadata}.${openinference_semantic_conventions_1.LLMAttributePostfixes.model_name}`]: creator.modelId,
|
|
146
|
-
})), (creator.parameters && {
|
|
147
|
-
[openinference_semantic_conventions_1.SemanticConventions.LLM_INVOCATION_PARAMETERS]: JSON.stringify(creator.parameters),
|
|
148
|
-
}));
|
|
149
|
-
}
|
|
150
|
-
if (meta.name === config_1.finishLLMEventName && meta.creator instanceof chat_1.ChatModel) {
|
|
151
|
-
return {
|
|
152
|
-
[openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND]: openinference_semantic_conventions_1.OpenInferenceSpanKind.LLM,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
// other events
|
|
156
|
-
const data = (0, object_1.getProp)(dataObject, ["data"], dataObject);
|
|
157
|
-
if (data instanceof serializable_1.Serializable) {
|
|
158
|
-
try {
|
|
163
|
+
// other events
|
|
164
|
+
const data = (0, object_1.getProp)(dataObject, ["data"], dataObject);
|
|
165
|
+
if (data instanceof serializable_1.Serializable) {
|
|
159
166
|
return { data: JSON.stringify(data.createSnapshot()), test: "hallo" };
|
|
160
167
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
168
|
+
return { data: JSON.stringify(data) };
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
api_1.diag.warn("Failed to parse event data", e);
|
|
172
|
+
return null;
|
|
165
173
|
}
|
|
166
|
-
return { data: JSON.stringify(data) };
|
|
167
174
|
}
|
|
168
175
|
//# sourceMappingURL=getSerializedObjectSafe.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSerializedObjectSafe.js","sourceRoot":"","sources":["../../../src/helpers/getSerializedObjectSafe.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AA6EH,
|
|
1
|
+
{"version":3,"file":"getSerializedObjectSafe.js","sourceRoot":"","sources":["../../../src/helpers/getSerializedObjectSafe.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AA6EH,0DAkPC;AA7TD,yEAAsE;AACtE,qEAAmE;AAGnE,uDAA0E;AAC1E,sDAAwD;AAExD,sCAoBmB;AACnB,oGAOqD;AACrD,qDAA8D;AAC9D,4CAA0C;AAE1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O;gBACL,CAAC,wDAAmB,CAAC,uBAAuB,CAAC,EAC3C,0DAAqB,CAAC,GAAG;aAC5B,CAAC;QACJ,CAAC;QAED,eAAe;QACf,MAAM,IAAI,GAAG,IAAA,gBAAO,EAAC,UAAU,EAAE,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;QACvD,IAAI,IAAI,YAAY,2BAAY,EAAE,CAAC;YACjC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;QACxE,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;IACxC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,UAAI,CAAC,IAAI,CAAC,4BAA4B,EAAE,CAAC,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAWvD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAgB1E,OAAO,EACL,qBAAqB,EAEtB,MAAM,6CAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAWvD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAgB1E,OAAO,EACL,qBAAqB,EAEtB,MAAM,6CAA6C,CAAC;AAIrD,eAAO,MAAM,eAAe,qBAA4B,CAAC;AAEzD;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,QAAQ,EAChB,YAAY,EAAE,qBAAqB,aAElB,aAAa,CAAC,WAAW,EAAE,OAAO,CAAC,UA+SrD"}
|
package/dist/src/middleware.js
CHANGED
|
@@ -37,10 +37,12 @@ const message_1 = require("beeai-framework/backend/message");
|
|
|
37
37
|
const traceSerializer_1 = require("./helpers/traceSerializer");
|
|
38
38
|
const config_1 = require("./config");
|
|
39
39
|
const utils_1 = require("beeai-framework/emitter/utils");
|
|
40
|
+
const agent_1 = require("beeai-framework/agents/react/agent");
|
|
40
41
|
const base_1 = require("beeai-framework/agents/base");
|
|
41
42
|
const api_1 = require("@opentelemetry/api");
|
|
42
43
|
const buildTraceTree_1 = require("./helpers/buildTraceTree");
|
|
43
44
|
const openinference_semantic_conventions_1 = require("@arizeai/openinference-semantic-conventions");
|
|
45
|
+
const agent_2 = require("beeai-framework/agents/toolCalling/agent");
|
|
44
46
|
exports.activeTracesMap = new Map();
|
|
45
47
|
/**
|
|
46
48
|
* First we collect, filter and transform events from the beeai emitter to our internal framework spans in the `emitter.match("*.*"` block
|
|
@@ -171,84 +173,114 @@ function createTelemetryMiddleware(tracer, mainSpanKind) {
|
|
|
171
173
|
context,
|
|
172
174
|
});
|
|
173
175
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const { spanId, parentSpanId } = idNameManager.getIds({
|
|
193
|
-
path: meta.path,
|
|
194
|
-
id: meta.id,
|
|
195
|
-
runId: meta.trace.runId,
|
|
196
|
-
parentRunId: meta.trace.parentRunId,
|
|
197
|
-
groupId: meta.groupId,
|
|
198
|
-
});
|
|
199
|
-
const serializedData = (0, getSerializedObjectSafe_1.getSerializedObjectSafe)(data, meta);
|
|
200
|
-
// skip partialUpdate events with no data
|
|
201
|
-
if (meta.name === config_1.partialUpdateEventName && (0, remeda_1.isEmpty)(serializedData)) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
const span = (0, create_span_1.createSpan)(Object.assign(Object.assign({ id: spanId, name: meta.name, target: meta.path }, (parentSpanId && { parent: { id: parentSpanId } })), { ctx: meta.context, data: serializedData, error: (0, getErrorSafe_1.getErrorSafe)(data), startedAt: convertDateToPerformance(meta.createdAt) }));
|
|
205
|
-
const lastIteration = groupIterations[groupIterations.length - 1];
|
|
206
|
-
// delete the `partialUpdate` event if does not have nested spans
|
|
207
|
-
const lastIterationEventSpanId = (_b = eventsIterationsMap
|
|
208
|
-
.get(lastIteration)) === null || _b === void 0 ? void 0 : _b.get(meta.name);
|
|
209
|
-
if (lastIterationEventSpanId &&
|
|
210
|
-
config_1.partialUpdateEventName === meta.name &&
|
|
211
|
-
spansMap.has(lastIterationEventSpanId)) {
|
|
212
|
-
const { context } = spansMap.get(lastIterationEventSpanId);
|
|
213
|
-
if (parentIdsMap.has(context.span_id)) {
|
|
214
|
-
spansToDeleteMap.set(lastIterationEventSpanId, undefined);
|
|
176
|
+
try {
|
|
177
|
+
/**
|
|
178
|
+
* create groupId span level (id does not exist)
|
|
179
|
+
* I use only the top-level groups like iterations other nested groups like tokens would introduce unuseful complexity
|
|
180
|
+
*/
|
|
181
|
+
if (meta.groupId &&
|
|
182
|
+
!meta.trace.parentRunId &&
|
|
183
|
+
!groupIterations.includes(meta.groupId)) {
|
|
184
|
+
spansMap.set(meta.groupId, (0, create_span_1.createSpan)({
|
|
185
|
+
id: meta.groupId,
|
|
186
|
+
name: meta.groupId,
|
|
187
|
+
target: "groupId",
|
|
188
|
+
data: {
|
|
189
|
+
[openinference_semantic_conventions_1.SemanticConventions.OPENINFERENCE_SPAN_KIND]: "Chain",
|
|
190
|
+
},
|
|
191
|
+
startedAt: convertDateToPerformance(meta.createdAt),
|
|
192
|
+
}));
|
|
193
|
+
groupIterations.push(meta.groupId);
|
|
215
194
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
195
|
+
const { spanId, parentSpanId } = idNameManager.getIds({
|
|
196
|
+
path: meta.path,
|
|
197
|
+
id: meta.id,
|
|
198
|
+
runId: meta.trace.runId,
|
|
199
|
+
parentRunId: meta.trace.parentRunId,
|
|
200
|
+
groupId: meta.groupId,
|
|
201
|
+
});
|
|
202
|
+
const serializedData = (0, getSerializedObjectSafe_1.getSerializedObjectSafe)(data, meta);
|
|
203
|
+
// skip partialUpdate events with no data
|
|
204
|
+
if (meta.name === config_1.partialUpdateEventName && (0, remeda_1.isEmpty)(serializedData)) {
|
|
205
|
+
return;
|
|
220
206
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
207
|
+
const span = (0, create_span_1.createSpan)(Object.assign(Object.assign({ id: spanId, name: meta.name, target: meta.path }, (parentSpanId && { parent: { id: parentSpanId } })), { ctx: meta.context, data: serializedData, error: (0, getErrorSafe_1.getErrorSafe)(data), startedAt: convertDateToPerformance(meta.createdAt) }));
|
|
208
|
+
const lastIteration = groupIterations[groupIterations.length - 1];
|
|
209
|
+
// delete the `partialUpdate` event if does not have nested spans
|
|
210
|
+
const lastIterationEventSpanId = (_b = eventsIterationsMap
|
|
211
|
+
.get(lastIteration)) === null || _b === void 0 ? void 0 : _b.get(meta.name);
|
|
212
|
+
if (lastIterationEventSpanId &&
|
|
213
|
+
config_1.partialUpdateEventName === meta.name &&
|
|
214
|
+
spansMap.has(lastIterationEventSpanId)) {
|
|
215
|
+
const { context } = spansMap.get(lastIterationEventSpanId);
|
|
216
|
+
if (parentIdsMap.has(context.span_id)) {
|
|
217
|
+
spansToDeleteMap.set(lastIterationEventSpanId, undefined);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
// delete span
|
|
221
|
+
cleanSpanSources({ spanId: lastIterationEventSpanId });
|
|
222
|
+
spansMap.delete(lastIterationEventSpanId);
|
|
223
|
+
}
|
|
234
224
|
}
|
|
235
|
-
|
|
236
|
-
|
|
225
|
+
// create new span
|
|
226
|
+
spansMap.set(span.context.span_id, span);
|
|
227
|
+
// update number of nested spans for parent_id if exists
|
|
228
|
+
if (span.parent_id) {
|
|
229
|
+
parentIdsMap.set(span.parent_id, (parentIdsMap.get(span.parent_id) || 0) + 1);
|
|
230
|
+
}
|
|
231
|
+
// save the last event for each iteration
|
|
232
|
+
if (groupIterations.length > 0) {
|
|
233
|
+
if (eventsIterationsMap.has(lastIteration)) {
|
|
234
|
+
eventsIterationsMap
|
|
235
|
+
.get(lastIteration)
|
|
236
|
+
.set(meta.name, span.context.span_id);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
eventsIterationsMap.set(lastIteration, new Map().set(meta.name, span.context.span_id));
|
|
240
|
+
}
|
|
237
241
|
}
|
|
238
242
|
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
api_1.diag.warn("Instrumentation error", e);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
// The generated response and message history are collected from the `success` event generated by ReActAgent
|
|
248
|
+
emitter.match((event) => event.name === config_1.successLLMEventName &&
|
|
249
|
+
event.creator instanceof agent_1.ReActAgent, (data) => {
|
|
250
|
+
try {
|
|
251
|
+
const { data: dataObject, memory } = data;
|
|
252
|
+
generatedMessage = {
|
|
253
|
+
role: dataObject.role,
|
|
254
|
+
text: dataObject.text,
|
|
255
|
+
};
|
|
256
|
+
history = memory.messages.map((msg) => ({
|
|
257
|
+
text: msg.text,
|
|
258
|
+
role: msg.role,
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
catch (e) {
|
|
262
|
+
api_1.diag.warn("Instrumentation error. Unable to map messages to history for ReActAgent", e);
|
|
263
|
+
}
|
|
239
264
|
});
|
|
240
|
-
// The generated response and message history are collected from the `success`
|
|
265
|
+
// The generated response and message history are collected from the `success` event generated by ToolCallingAgentCallbacks
|
|
241
266
|
emitter.match((event) => event.name === config_1.successLLMEventName &&
|
|
242
|
-
event.creator instanceof
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
267
|
+
event.creator instanceof agent_2.ToolCallingAgent, (data) => {
|
|
268
|
+
try {
|
|
269
|
+
const { state } = data;
|
|
270
|
+
if (state.result) {
|
|
271
|
+
generatedMessage = {
|
|
272
|
+
role: state.result.role,
|
|
273
|
+
text: state.result.text,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
history = state.memory.messages.map((msg) => ({
|
|
277
|
+
text: msg.text,
|
|
278
|
+
role: msg.role,
|
|
279
|
+
}));
|
|
280
|
+
}
|
|
281
|
+
catch (e) {
|
|
282
|
+
api_1.diag.warn("Instrumentation error. Unable to map messages to history for ToolCallingAgent", e);
|
|
283
|
+
}
|
|
252
284
|
});
|
|
253
285
|
};
|
|
254
286
|
}
|