Skip to content

Commit 81cba3b

Browse files
feat: make AgentExecutor a functional interface with default cancel m… (a2aproject#1028)
* feat: make AgentExecutor a functional interface with default cancel method This fixes a2aproject#1009 * fix: use an import for TaskNotCancelableError instead of a FQN Also drop the unused EventQueue import in the same file.
1 parent 24c83b0 commit 81cba3b

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎server-common/src/main/java/org/a2aproject/sdk/server/agentexecution/AgentExecutor.java‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.a2aproject.sdk.server.agentexecution;
22

3-
import org.a2aproject.sdk.server.events.EventQueue;
43
import org.a2aproject.sdk.server.tasks.AgentEmitter;
54
import org.a2aproject.sdk.spec.A2AError;
5+
import org.a2aproject.sdk.spec.TaskNotCancelableError;
66

77
/**
88
* Core business logic interface for implementing A2A agent functionality.
@@ -97,6 +97,7 @@
9797
* @see org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler
9898
* @see org.a2aproject.sdk.spec.AgentCard
9999
*/
100+
@FunctionalInterface
100101
public interface AgentExecutor {
101102
/**
102103
* Executes the agent's business logic for a message.
@@ -135,7 +136,7 @@ public interface AgentExecutor {
135136
* <p>
136137
* <b>Error Handling:</b>
137138
* <ul>
138-
* <li>Throw {@link org.a2aproject.sdk.spec.TaskNotCancelableError} if your agent does not support
139+
* <li>Throw {@link TaskNotCancelableError} if your agent does not support
139140
* cancellation at all (e.g., fire-and-forget agents)</li>
140141
* <li>Throw {@link A2AError} if cancellation is supported but failed to execute
141142
* (e.g., unable to interrupt running operation)</li>
@@ -144,8 +145,10 @@ public interface AgentExecutor {
144145
*
145146
* @param context the request context for the task being canceled
146147
* @param emitter the agent emitter for sending the cancellation event
147-
* @throws org.a2aproject.sdk.spec.TaskNotCancelableError if this agent does not support cancellation
148+
* @throws TaskNotCancelableError if this agent does not support cancellation
148149
* @throws A2AError if cancellation is supported but failed to execute
149150
*/
150-
void cancel(RequestContext context, AgentEmitter emitter) throws A2AError;
151+
default void cancel(RequestContext context, AgentEmitter emitter) throws A2AError {
152+
throw new TaskNotCancelableError("Agent execution is not cancelable.");
153+
}
151154
}

0 commit comments

Comments
 (0)