@looopy-ai/core 2.1.0 → 2.1.1
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.
|
@@ -74,20 +74,24 @@ export class AgentToolProvider {
|
|
|
74
74
|
return Promise.resolve(this.tools);
|
|
75
75
|
}
|
|
76
76
|
execute(toolCall, context) {
|
|
77
|
-
this.logger.
|
|
77
|
+
const logger = this.logger.child({
|
|
78
|
+
taskId: context.taskId,
|
|
79
|
+
toolCallId: toolCall.id,
|
|
80
|
+
});
|
|
81
|
+
logger.debug({ toolCallId: toolCall.id }, 'Executing agent tool call');
|
|
78
82
|
return new Observable((subscriber) => {
|
|
79
83
|
const abortController = new AbortController();
|
|
80
84
|
const run = async () => {
|
|
81
85
|
const tool = await this.getTool(toolCall.function.name);
|
|
82
86
|
if (!tool) {
|
|
83
|
-
|
|
87
|
+
logger.error({ toolName: toolCall.function.name }, 'Tool not found');
|
|
84
88
|
subscriber.next(toolErrorEvent(context, toolCall, `Tool not found: ${toolCall.function.name}`));
|
|
85
89
|
subscriber.complete();
|
|
86
90
|
return;
|
|
87
91
|
}
|
|
88
92
|
const prompt = toolCall.function.arguments.prompt;
|
|
89
93
|
if (!prompt || typeof prompt !== 'string') {
|
|
90
|
-
|
|
94
|
+
logger.error('Invalid tool call arguments');
|
|
91
95
|
subscriber.next(toolErrorEvent(context, toolCall, 'Tool argument must include "prompt" and it must be a string'));
|
|
92
96
|
subscriber.complete();
|
|
93
97
|
return;
|
|
@@ -103,47 +107,51 @@ export class AgentToolProvider {
|
|
|
103
107
|
signal: abortController.signal,
|
|
104
108
|
});
|
|
105
109
|
if (!res.ok) {
|
|
106
|
-
|
|
110
|
+
logger.error({ status: res.status, statusText: res.statusText }, 'Agent call failed');
|
|
107
111
|
subscriber.next(toolErrorEvent(context, toolCall, `Agent endpoint responded with ${res.status} ${res.statusText}`));
|
|
108
112
|
subscriber.complete();
|
|
109
113
|
return;
|
|
110
114
|
}
|
|
111
115
|
const body = res.body;
|
|
112
116
|
if (!body) {
|
|
113
|
-
|
|
117
|
+
logger.error('Agent response has no body');
|
|
114
118
|
subscriber.next(toolErrorEvent(context, toolCall, 'Agent returned no response body'));
|
|
115
119
|
subscriber.complete();
|
|
116
120
|
return;
|
|
117
121
|
}
|
|
122
|
+
let content = '';
|
|
118
123
|
await consumeSSEStream(body, (e) => {
|
|
119
124
|
if (subscriber.closed)
|
|
120
125
|
return;
|
|
126
|
+
const data = JSON.parse(e.data);
|
|
121
127
|
subscriber.next({
|
|
122
128
|
kind: e.event,
|
|
123
129
|
parentTaskId: context.taskId,
|
|
124
|
-
...
|
|
130
|
+
...data,
|
|
125
131
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (!subscriber.closed) {
|
|
129
|
-
const toolCompleteEvent = {
|
|
130
|
-
kind: 'tool-complete',
|
|
131
|
-
contextId: context.contextId,
|
|
132
|
-
taskId: context.taskId,
|
|
133
|
-
toolCallId: toolCall.id,
|
|
134
|
-
toolName: toolCall.function.name,
|
|
135
|
-
success: true,
|
|
136
|
-
result: 'Complete',
|
|
137
|
-
timestamp: new Date().toISOString(),
|
|
138
|
-
};
|
|
139
|
-
subscriber.next(toolCompleteEvent);
|
|
140
|
-
subscriber.complete();
|
|
141
|
-
this.logger.debug('Tool execution complete');
|
|
132
|
+
if (e.event === 'task-complete') {
|
|
133
|
+
content = data.content;
|
|
142
134
|
}
|
|
135
|
+
logger.debug({ event: e.event }, 'Received SSE event');
|
|
143
136
|
});
|
|
137
|
+
if (!subscriber.closed) {
|
|
138
|
+
const toolCompleteEvent = {
|
|
139
|
+
kind: 'tool-complete',
|
|
140
|
+
contextId: context.contextId,
|
|
141
|
+
taskId: context.taskId,
|
|
142
|
+
toolCallId: toolCall.id,
|
|
143
|
+
toolName: toolCall.function.name,
|
|
144
|
+
success: true,
|
|
145
|
+
result: content || 'Complete',
|
|
146
|
+
timestamp: new Date().toISOString(),
|
|
147
|
+
};
|
|
148
|
+
subscriber.next(toolCompleteEvent);
|
|
149
|
+
subscriber.complete();
|
|
150
|
+
logger.debug('Tool execution complete');
|
|
151
|
+
}
|
|
144
152
|
};
|
|
145
153
|
run().catch((err) => {
|
|
146
|
-
|
|
154
|
+
logger.error({ err }, 'Tool execution error');
|
|
147
155
|
if (!subscriber.closed) {
|
|
148
156
|
subscriber.error(err);
|
|
149
157
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@looopy-ai/core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "RxJS-based AI agent framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@geee-be/sse-stream-parser": "^1.0.
|
|
30
|
+
"@geee-be/sse-stream-parser": "^1.0.2",
|
|
31
31
|
"@opentelemetry/api": "^1.9.0",
|
|
32
32
|
"@opentelemetry/exporter-metrics-otlp-http": "^0.207.0",
|
|
33
33
|
"@opentelemetry/exporter-trace-otlp-http": "^0.207.0",
|