Skip to content

feat: make AgentExecutor a functional interface with default cancel m… - #1028

Open
malladinagarjuna2 wants to merge 2 commits into
a2aproject:mainfrom
malladinagarjuna2:feat-agentexecutor-lambda
Open

feat: make AgentExecutor a functional interface with default cancel m…#1028
malladinagarjuna2 wants to merge 2 commits into
a2aproject:mainfrom
malladinagarjuna2:feat-agentexecutor-lambda

Conversation

@malladinagarjuna2

Copy link
Copy Markdown

Overview

This PR converts the AgentExecutor interface into a @FunctionalInterface by providing a default implementation for the cancel method, allowing developers to define simple agents using lambda expressions.

Fixes #1009

The Problem

Previously, AgentExecutor required developers to implement two methods: execute and cancel. Because there were two abstract methods, it was impossible to use a lambda expression (e.g. (context, emitter) -> { ... }) to implement an agent. This forced developers to write verbose boilerplate even for simple fire-and-forget agents that do not require cancellation logic.

The Solution

  1. Added @FunctionalInterface: Explicitly marked AgentExecutor as a functional interface.
  2. Default cancel Implementation: Converted the cancel method to a default method. If an agent developer does not override it, it now correctly throws a TaskNotCancelableError("Agent execution is not cancelable.") by default, conforming to the existing A2A error specification.

*/
void cancel(RequestContext context, AgentEmitter emitter) throws A2AError;
default void cancel(RequestContext context, AgentEmitter emitter) throws A2AError {
throw new org.a2aproject.sdk.spec.TaskNotCancelableError("Agent execution is not cancelable.");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use an import rather than a FQN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat]: Makes cancel method of AgentExecutor default

2 participants