Skip to content

Commit e78f6d5

Browse files
authored
Merge branch 'main' into feat/tool-schema-support
2 parents 8e64653 + 63f7e92 commit e78f6d5

6 files changed

Lines changed: 344 additions & 13 deletions

File tree

agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,10 @@ protected Mono<Msg> summarizing() {
648648
postEvent -> {
649649
Msg finalMsg =
650650
postEvent
651-
.getSummaryMessage();
651+
.getSummaryMessage()
652+
.withGenerateReason(
653+
GenerateReason
654+
.MAX_ITERATIONS);
652655
memory.addMessage(finalMsg);
653656
return finalMsg;
654657
}));
@@ -747,12 +750,9 @@ private boolean isFinished(Msg msg) {
747750
List<ToolUseBlock> toolCalls = msg.getContentBlocks(ToolUseBlock.class);
748751

749752
// No tool calls - finished
750-
if (toolCalls.isEmpty()) {
751-
return true;
752-
}
753-
754-
// Has tool calls but none are in toolkit - finished
755-
return toolCalls.stream().noneMatch(tc -> toolkit.getTool(tc.getName()) != null);
753+
// If there are tool calls (even non-existent ones), continue to acting phase
754+
// where ToolExecutor will return "Tool not found" error for the model to see
755+
return toolCalls.isEmpty();
756756
}
757757

758758
/**

agentscope-core/src/main/java/io/agentscope/core/agent/AgentBase.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.agentscope.core.state.StateModule;
2727
import io.agentscope.core.tracing.TracerRegistry;
2828
import java.util.ArrayList;
29+
import java.util.Comparator;
2930
import java.util.List;
3031
import java.util.Map;
3132
import java.util.UUID;
@@ -98,6 +99,8 @@ public abstract class AgentBase implements StateModule, Agent {
9899
// Interrupt state management (available to all agents)
99100
private final AtomicBoolean interruptFlag = new AtomicBoolean(false);
100101
private final AtomicReference<Msg> userInterruptMessage = new AtomicReference<>(null);
102+
// Hook non-null
103+
private static final Comparator<Hook> HOOK_COMPARATOR = Comparator.comparingInt(Hook::priority);
101104

102105
/**
103106
* Constructor for AgentBase.
@@ -133,6 +136,7 @@ public AgentBase(String name, String description, boolean checkRunning, List<Hoo
133136
this.checkRunning = checkRunning;
134137
this.hooks = new CopyOnWriteArrayList<>(hooks != null ? hooks : List.of());
135138
this.hooks.addAll(systemHooks);
139+
sortHooks();
136140
}
137141

138142
@Override
@@ -474,9 +478,14 @@ public List<Hook> getHooks() {
474478
protected void addHook(Hook hook) {
475479
if (hook != null) {
476480
hooks.add(hook);
481+
sortHooks();
477482
}
478483
}
479484

485+
private void sortHooks() {
486+
this.hooks.sort(HOOK_COMPARATOR);
487+
}
488+
480489
/**
481490
* Remove a hook from this agent dynamically.
482491
*
@@ -498,7 +507,7 @@ protected void removeHook(Hook hook) {
498507
* @return Sorted list of hooks
499508
*/
500509
protected List<Hook> getSortedHooks() {
501-
return hooks.stream().sorted(java.util.Comparator.comparingInt(Hook::priority)).toList();
510+
return hooks;
502511
}
503512

504513
/**
@@ -692,7 +701,7 @@ private Flux<Event> createEventStream(StreamOptions options, Supplier<Mono<Msg>>
692701
new StreamingHook(sink, options);
693702

694703
// Add temporary hook
695-
hooks.add(streamingHook);
704+
addHook(streamingHook);
696705

697706
// Use Mono.defer to ensure trace context propagation
698707
// while maintaining streaming hook functionality

agentscope-core/src/main/java/io/agentscope/core/skill/repository/ClasspathSkillRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ protected ClasspathSkillRepository(String resourcePath, String source, ClassLoad
139139
if ("jar".equals(uri.getScheme())) {
140140
this.isJar = true;
141141
this.fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap());
142-
String actualResourcePath = uri.getSchemeSpecificPart().split("!")[1];
142+
String schemeSpecificUriPath = uri.getSchemeSpecificPart();
143+
String actualResourcePath =
144+
schemeSpecificUriPath.substring(schemeSpecificUriPath.lastIndexOf("!") + 1);
143145
logger.info("Actual resource path: {}", actualResourcePath);
144146
this.skillBasePath = fileSystem.getPath(actualResourcePath);
145147
} else {

agentscope-core/src/test/java/io/agentscope/core/agent/ReActAgentTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.agentscope.core.agent.test.TestUtils;
3030
import io.agentscope.core.memory.InMemoryMemory;
3131
import io.agentscope.core.message.ContentBlock;
32+
import io.agentscope.core.message.GenerateReason;
3233
import io.agentscope.core.message.Msg;
3334
import io.agentscope.core.message.MsgRole;
3435
import io.agentscope.core.message.TextBlock;
@@ -476,9 +477,13 @@ void testMaxIterations() {
476477

477478
// Get response with timeout
478479
// Verify it completes within reasonable time (not infinite loop)
479-
agent.call(userMsg)
480-
.timeout(Duration.ofMillis(TestConstants.DEFAULT_TEST_TIMEOUT_MS))
481-
.block(Duration.ofMillis(TestConstants.DEFAULT_TEST_TIMEOUT_MS));
480+
Msg response =
481+
agent.call(userMsg)
482+
.timeout(Duration.ofMillis(TestConstants.DEFAULT_TEST_TIMEOUT_MS))
483+
.block(Duration.ofMillis(TestConstants.DEFAULT_TEST_TIMEOUT_MS));
484+
485+
// Verify max iterations generate reason was respected
486+
assertEquals(GenerateReason.MAX_ITERATIONS, response.getGenerateReason());
482487

483488
// Verify max iterations was respected
484489
assertTrue(

0 commit comments

Comments
 (0)