Optimize the agent tool execution loop
This commit is contained in:
1 parent
572371d7af
commit
4291adfdfb
7 files changed
+110
-7
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package run.webup.platform;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
@@ -374,12 +375,24 @@ public class TaskService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void tool(UUID id, String lease, ModelGateway.Call call, String output) {
|
||||
public boolean tool(UUID id, String lease, ModelGateway.Call call, String output)
|
||||
throws JsonProcessingException {
|
||||
locked(id, lease);
|
||||
message(
|
||||
id,
|
||||
Map.of("role", "tool", "tool_call_id", call.id(), "name", call.name(), "content", output));
|
||||
var result = json.readTree(output);
|
||||
boolean failed =
|
||||
result.hasNonNull("error")
|
||||
|| result.path("timedOut").asBoolean(false)
|
||||
|| result.path("exitCode").asInt(0) != 0;
|
||||
var payload =
|
||||
json.createObjectNode()
|
||||
.put("role", "tool")
|
||||
.put("tool_call_id", call.id())
|
||||
.put("name", call.name())
|
||||
.put("content", output);
|
||||
if (failed) payload.put("is_error", true);
|
||||
message(id, payload);
|
||||
event(id, "TOOL_RESULT", call.name() + ": " + output);
|
||||
return failed;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
||||
Reference in new issue
Block a user