diff --git a/java/src/main/java/com/genexus/GXProcedure.java b/java/src/main/java/com/genexus/GXProcedure.java index 0f597bbc5..346b40fff 100644 --- a/java/src/main/java/com/genexus/GXProcedure.java +++ b/java/src/main/java/com/genexus/GXProcedure.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.Date; -import com.fasterxml.jackson.databind.ObjectMapper; import com.genexus.db.Namespace; import com.genexus.db.UserInformation; import com.genexus.diagnostics.GXDebugInfo; @@ -18,8 +17,8 @@ import com.genexus.util.*; import com.genexus.util.saia.OpenAIRequest; import com.genexus.util.saia.OpenAIResponse; +import com.genexus.util.saia.SaiaEvents; import com.genexus.util.saia.SaiaService; -import org.json.JSONObject; public abstract class GXProcedure implements IErrorHandler, ISubmitteable { public abstract void initialize(); @@ -286,9 +285,9 @@ protected ChatResult chatAgent(String agent, GXProperties properties, ArrayList< context.setThreadModelContext(context); callAgent(agent, true, properties, messages, result, chatResult); } finally { - chatResult.markDone(); if (history != null) history.setExternalInstance(messages); + chatResult.markDone(); } }).start(); @@ -327,16 +326,18 @@ protected String callAgent(String agent, boolean stream, GXProperties properties public String processNotChunkedResponse(String agent, boolean stream, GXProperties properties, ArrayList messages, CallResult result, ChatResult chatResult, ArrayList toolCalls) { for (OpenAIResponse.ToolCall tollCall : toolCalls) { - processToolCall(tollCall, messages); + processToolCall(tollCall, messages, chatResult); } return callAgent(agent, stream, properties, messages, result, chatResult); } - private void processToolCall(OpenAIResponse.ToolCall toolCall, ArrayList messages) { + private void processToolCall(OpenAIResponse.ToolCall toolCall, ArrayList messages, ChatResult chatResult) { String result; String functionName = toolCall.getFunction().getName(); try { + addToolCallChunk(chatResult, toolCall, "saia.metadata.tool.started", "started", null); result = callTool(functionName, toolCall.getFunction().getArguments()); + addToolCallChunk(chatResult, toolCall, "saia.metadata.tool.finished", "finished_successfully", result); } catch (Throwable e) { result = String.format("Error calling tool %s", functionName); @@ -347,4 +348,13 @@ private void processToolCall(OpenAIResponse.ToolCall toolCall, ArrayList