Skip to content

[Feature] Support Method Extensions (Extended Skills) - RequestHandler to handle custom RPC methods #129

@mashiike

Description

@mashiike

Is your feature request related to a problem? Please describe.

a2a-go does not support method extensions (extension skills) as outlined in the A2A protocol document.
https://a2a-protocol.org/latest/topics/extensions/

Method Extensions (Extended Skills): Adding entirely new RPC methods beyond the core set defined by the protocol. An Extended Skill refers to a capability or function an agent gains or exposes specifically through the implementation of an extension that defines new RPC methods. For example, a task-history extension might add a tasks/search RPC method to retrieve a list of previous tasks, effectively providing the agent with a new, extended skill.

https://github.com/a2aproject/a2a-go/blob/main/a2asrv/jsonrpc.go#L109

The JSON-RPC handler uses a fixed switch statement that returns ErrMethodNotFound for methods outside the core set, and the RequestHandler interface does not provide a mechanism for implementing custom RPC methods defined by extensions. This makes it difficult for developers to implement the extensions outlined in the protocol specification.

Describe the solution you'd like

To support custom RPC methods defined by extensions, we propose adding a new optional interface that RequestHandler implementations can optionally implement. For example:

// Handler for arbitrary RPC methods defined by extensions.
// Receives the method name and params, and returns a result or error.
// Returns ErrMethodNotFound if the method is not supported.
// Does not affect existing RequestHandler implementations.
type ExtendedMethodHandler interface {
    OnExtendedMethod(ctx context.Context, method string, params json.RawMessage) (any, error)
}

Modify the default clause in jsonrpcHandler.handleRequest as follows, so that if the registered RequestHandler implements ExtendedMethodHandler, its method will be called:

   default:
        if ext, ok := h.handler.(ExtendedMethodHandler); ok {
            result, err = ext.OnExtendedMethod(ctx, req.Method, req.Params)
        } else {
            err = a2a.ErrMethodNotFound
        }

This change enables handling of extension methods without any breaking changes to existing developer. If necessary, similar hooks can be added to the gRPC transport layer to ensure all transports support extension methods.

Describe alternatives you've considered

No response

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions