a2aproject / a2aproject/a2a-go

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

Aperta
#129 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Go
Stelle
460
Fork
93
Merge medio
2g 21h
PR unite (30g)
9

Descrizione

### 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:
```go
// 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:
```go
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

- [x] I agree to follow this project's Code of Conduct

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.