@agentica/core 0.41.0 → 0.41.2
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/lib/constants/AgenticaSystemPrompt.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +0 -3
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +21 -21
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/call.js +10 -10
- package/lib/orchestrate/call.js.map +1 -1
- package/lib/orchestrate/cancel.js +4 -4
- package/lib/orchestrate/cancel.js.map +1 -1
- package/lib/orchestrate/describe.js +2 -2
- package/lib/orchestrate/describe.js.map +1 -1
- package/lib/orchestrate/initialize.js +3 -3
- package/lib/orchestrate/initialize.js.map +1 -1
- package/lib/orchestrate/select.js +13 -13
- package/lib/orchestrate/select.js.map +1 -1
- package/lib/utils/ChatGptCompletionMessageUtil.js +5 -3
- package/lib/utils/ChatGptCompletionMessageUtil.js.map +1 -1
- package/lib/utils/ChatGptCompletionStreamingUtil.js +3 -2
- package/lib/utils/ChatGptCompletionStreamingUtil.js.map +1 -1
- package/package.json +1 -1
- package/prompts/json_parse_error.md +2 -2
- package/src/constants/AgenticaSystemPrompt.ts +1 -1
- package/src/index.ts +0 -3
- package/src/orchestrate/call.ts +6 -4
- package/src/orchestrate/cancel.ts +2 -2
- package/src/orchestrate/describe.ts +1 -1
- package/src/orchestrate/initialize.ts +2 -2
- package/src/orchestrate/select.ts +6 -6
- package/src/utils/ChatGptCompletionMessageUtil.ts +3 -3
- package/src/utils/ChatGptCompletionStreamingUtil.ts +2 -2
|
@@ -193,9 +193,9 @@ async function step(
|
|
|
193
193
|
|
|
194
194
|
if (result.type === "none-stream") {
|
|
195
195
|
const completion = result.value;
|
|
196
|
-
const allAssistantMessagesEmpty = completion.choices
|
|
196
|
+
const allAssistantMessagesEmpty = !!completion.choices?.every(v => v.message.tool_calls == null && v.message.content === "");
|
|
197
197
|
if (allAssistantMessagesEmpty) {
|
|
198
|
-
const firstChoice = completion.choices
|
|
198
|
+
const firstChoice = completion.choices?.at(0);
|
|
199
199
|
if ((firstChoice?.message as { reasoning?: string })?.reasoning != null) {
|
|
200
200
|
throw new AssistantMessageEmptyWithReasoningError((firstChoice?.message as { reasoning?: string })?.reasoning ?? "");
|
|
201
201
|
}
|
|
@@ -208,9 +208,9 @@ async function step(
|
|
|
208
208
|
const event: AgenticaAssistantMessageEvent = createAssistantMessageEvent(props);
|
|
209
209
|
void ctx.dispatch(event).catch(() => {});
|
|
210
210
|
}, ctx.abortSignal);
|
|
211
|
-
const allAssistantMessagesEmpty = completion.choices
|
|
211
|
+
const allAssistantMessagesEmpty = !!completion.choices?.every(v => v.message.tool_calls == null && v.message.content === "");
|
|
212
212
|
if (allAssistantMessagesEmpty) {
|
|
213
|
-
const firstChoice = completion.choices
|
|
213
|
+
const firstChoice = completion.choices?.at(0);
|
|
214
214
|
if ((firstChoice?.message as { reasoning?: string })?.reasoning != null) {
|
|
215
215
|
throw new AssistantMessageEmptyWithReasoningError((firstChoice?.message as { reasoning?: string })?.reasoning ?? "");
|
|
216
216
|
}
|
|
@@ -236,7 +236,7 @@ async function step(
|
|
|
236
236
|
// ----
|
|
237
237
|
if (retry++ < (ctx.config?.retry ?? AgenticaConstant.RETRY)) {
|
|
238
238
|
const failures: IFailure[] = [];
|
|
239
|
-
for (const choice of completion.choices) {
|
|
239
|
+
for (const choice of (completion.choices ?? [])) {
|
|
240
240
|
for (const tc of choice.message.tool_calls ?? []) {
|
|
241
241
|
if (tc.type !== "function" || tc.function.name !== "selectFunctions") {
|
|
242
242
|
continue;
|
|
@@ -261,7 +261,7 @@ async function step(
|
|
|
261
261
|
// ----
|
|
262
262
|
// PROCESS COMPLETION
|
|
263
263
|
// ----
|
|
264
|
-
for (const choice of completion.choices) {
|
|
264
|
+
for (const choice of (completion.choices ?? [])) {
|
|
265
265
|
// FUNCTION CALLING
|
|
266
266
|
if (choice.message.tool_calls != null) {
|
|
267
267
|
for (const tc of choice.message.tool_calls) {
|
|
@@ -23,8 +23,8 @@ function transformCompletionChunk(source: string | Uint8Array): ChatCompletionCh
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
function accumulate(origin: ChatCompletion, chunk: ChatCompletionChunk): ChatCompletion {
|
|
26
|
-
const choices = origin.choices;
|
|
27
|
-
chunk.choices.forEach((choice) => {
|
|
26
|
+
const choices = origin.choices ?? [];
|
|
27
|
+
(chunk.choices ?? []).forEach((choice) => {
|
|
28
28
|
const accChoice = choices[choice.index];
|
|
29
29
|
if (accChoice != null) {
|
|
30
30
|
choices[choice.index] = mergeChoice(accChoice, choice);
|
|
@@ -101,7 +101,7 @@ function merge(chunks: ChatCompletionChunk[]): ChatCompletion {
|
|
|
101
101
|
} as ChatCompletion);
|
|
102
102
|
|
|
103
103
|
// post-process
|
|
104
|
-
result.choices
|
|
104
|
+
result.choices?.forEach((choice) => {
|
|
105
105
|
choice.message.tool_calls?.filter(tc => tc.type === "function").forEach((toolCall) => {
|
|
106
106
|
if (toolCall.function.arguments === "") {
|
|
107
107
|
toolCall.function.arguments = "{}";
|
|
@@ -55,10 +55,10 @@ async function reduceStreamingWithDispatch(stream: ReadableStream<ChatCompletion
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
if (acc.object === "chat.completion.chunk") {
|
|
58
|
-
registerContext([acc, chunk].flatMap(v => v.choices));
|
|
58
|
+
registerContext([acc, chunk].flatMap(v => v.choices ?? []));
|
|
59
59
|
return ChatGptCompletionMessageUtil.merge([acc, chunk]);
|
|
60
60
|
}
|
|
61
|
-
registerContext(chunk.choices);
|
|
61
|
+
registerContext(chunk.choices ?? []);
|
|
62
62
|
return ChatGptCompletionMessageUtil.accumulate(acc, chunk);
|
|
63
63
|
}, { abortSignal });
|
|
64
64
|
|