diff --git a/agentscope-core/src/main/java/io/agentscope/core/hook/Hook.java b/agentscope-core/src/main/java/io/agentscope/core/hook/Hook.java index a48465be5..7cdaf939d 100644 --- a/agentscope-core/src/main/java/io/agentscope/core/hook/Hook.java +++ b/agentscope-core/src/main/java/io/agentscope/core/hook/Hook.java @@ -124,12 +124,12 @@ public interface Hook { *
  • {@link PostReasoningEvent} - Modify reasoning results
  • *
  • {@link PreActingEvent} - Modify tool parameters before execution
  • *
  • {@link PostActingEvent} - Modify tool results
  • + *
  • {@link PreCallEvent} - Modify messages before agent starts
  • *
  • {@link PostCallEvent} - Modify final agent response
  • * * *

    Notification Events: Events without setters are read-only: *

    */ public final class PreCallEvent extends HookEvent { @@ -45,18 +49,32 @@ public final class PreCallEvent extends HookEvent { * Constructor for PreCallEvent. * * @param agent The agent instance (must not be null) - * @throws NullPointerException if agent is null + * @param inputMessages The messages input to the agent (must not be null) + * @throws NullPointerException if agent or inputMessages is null */ public PreCallEvent(Agent agent, List inputMessages) { super(HookEventType.PRE_CALL, agent); - this.inputMessages = inputMessages; + this.inputMessages = + new ArrayList<>( + Objects.requireNonNull(inputMessages, "inputMessages cannot be null")); } + /** + * Get the input messages for the agent call. + * + * @return The input messages + */ public List getInputMessages() { return inputMessages; } + /** + * Modify the input messages for the agent call. + * + * @param inputMessages The new message list (must not be null) + * @throws NullPointerException if inputMessages is null + */ public void setInputMessages(List inputMessages) { - this.inputMessages = inputMessages; + this.inputMessages = Objects.requireNonNull(inputMessages, "inputMessages cannot be null"); } } diff --git a/agentscope-core/src/test/java/io/agentscope/core/hook/HookEventTest.java b/agentscope-core/src/test/java/io/agentscope/core/hook/HookEventTest.java index b229f612d..958023215 100644 --- a/agentscope-core/src/test/java/io/agentscope/core/hook/HookEventTest.java +++ b/agentscope-core/src/test/java/io/agentscope/core/hook/HookEventTest.java @@ -30,6 +30,7 @@ import io.agentscope.core.message.ToolUseBlock; import io.agentscope.core.model.GenerateOptions; import io.agentscope.core.tool.Toolkit; +import java.util.ArrayList; import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; @@ -102,7 +103,7 @@ class PreCallEventTests { @Test @DisplayName("Should create and access event") void testCreationAndAccess() { - PreCallEvent event = new PreCallEvent(testAgent, null); + PreCallEvent event = new PreCallEvent(testAgent, new ArrayList<>()); assertEquals(HookEventType.PRE_CALL, event.getType()); assertEquals(testAgent, event.getAgent());