a2aproject / a2aproject/a2a-go

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

未關閉
#129 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Go
星號
460
分支
93
平均合併
2 天 21 小時
30 天內合併 PR
9

描述

### 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

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。