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:
*
- * - {@link PreCallEvent} - Notified when agent starts
* - {@link ReasoningChunkEvent} - Streaming reasoning chunks
* - {@link ActingChunkEvent} - Streaming tool execution chunks
* - {@link ErrorEvent} - Errors during execution
diff --git a/agentscope-core/src/main/java/io/agentscope/core/hook/PreCallEvent.java b/agentscope-core/src/main/java/io/agentscope/core/hook/PreCallEvent.java
index a81bf978a..aba975512 100644
--- a/agentscope-core/src/main/java/io/agentscope/core/hook/PreCallEvent.java
+++ b/agentscope-core/src/main/java/io/agentscope/core/hook/PreCallEvent.java
@@ -17,17 +17,20 @@
import io.agentscope.core.agent.Agent;
import io.agentscope.core.message.Msg;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/**
* Event fired before agent starts processing.
*
- * Modifiable: No (notification-only)
+ *
Modifiable: Yes - {@link #setInputMessages(List)}
*
*
Context:
*
* - {@link #getAgent()} - The agent instance
- * - {@link #getMemory()} - Agent's memory (includes input messages already added)
+ * - {@link #getMemory()} - Agent's existing memory or conversation history prior to processing this call
+ * - {@link #getInputMessages()} - Messages input to the agent (modifiable)
*
*
* Use Cases:
@@ -35,6 +38,7 @@
*
- Log the start of agent execution
* - Initialize execution-specific resources
* - Track agent invocation metrics
+ * - Filter or modify input messages before agent processing
*
*/
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());