Skip to content

Commit fc5123f

Browse files
committed
all controller changes combined into one commit for version 0.10.0
Signed-off-by: Jet Chiang <pokyuen.jetchiang-ext@solo.io>
1 parent 067c2fa commit fc5123f

72 files changed

Lines changed: 2209 additions & 887 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

go/api/client/agent.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,20 @@ package client
33
import (
44
"context"
55
"fmt"
6-
"net/url"
76

87
api "github.com/kagent-dev/kagent/go/api/httpapi"
98
"github.com/kagent-dev/kagent/go/api/v1alpha2"
109
)
1110

1211
// Agent defines the agent operations
1312
type Agent interface {
14-
ListAgents(ctx context.Context, opts ...ListAgentsOptions) (*api.StandardResponse[[]api.AgentResponse], error)
13+
ListAgents(ctx context.Context) (*api.StandardResponse[[]api.AgentResponse], error)
1514
CreateAgent(ctx context.Context, request *v1alpha2.Agent) (*api.StandardResponse[*v1alpha2.Agent], error)
1615
GetAgent(ctx context.Context, agentRef string) (*api.StandardResponse[*api.AgentResponse], error)
1716
UpdateAgent(ctx context.Context, request *v1alpha2.Agent) (*api.StandardResponse[*v1alpha2.Agent], error)
1817
DeleteAgent(ctx context.Context, agentRef string) error
1918
}
2019

21-
// ListAgentsOptions configures ListAgents requests.
22-
type ListAgentsOptions struct {
23-
Namespace string
24-
}
25-
2620
// agentClient handles agent-related requests
2721
type agentClient struct {
2822
client *BaseClient
@@ -33,23 +27,14 @@ func NewAgentClient(client *BaseClient) Agent {
3327
return &agentClient{client: client}
3428
}
3529

36-
// ListAgents lists all agents for a user. When Namespace is set, only agents in that namespace are returned.
37-
func (c *agentClient) ListAgents(ctx context.Context, opts ...ListAgentsOptions) (*api.StandardResponse[[]api.AgentResponse], error) {
38-
if len(opts) > 1 {
39-
return nil, fmt.Errorf("ListAgents accepts at most one options argument")
40-
}
41-
30+
// ListAgents lists all agents for a user
31+
func (c *agentClient) ListAgents(ctx context.Context) (*api.StandardResponse[[]api.AgentResponse], error) {
4232
userID := c.client.GetUserIDOrDefault("")
4333
if userID == "" {
4434
return nil, fmt.Errorf("userID is required")
4535
}
4636

47-
path := "/api/agents"
48-
if len(opts) > 0 && opts[0].Namespace != "" {
49-
path += "?namespace=" + url.QueryEscape(opts[0].Namespace)
50-
}
51-
52-
resp, err := c.client.Get(ctx, path, userID)
37+
resp, err := c.client.Get(ctx, "/api/agents", userID)
5338
if err != nil {
5439
return nil, err
5540
}

go/api/database/client.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"context"
55
"time"
66

7+
a2a "github.com/a2aproject/a2a-go/v2/a2a"
78
"github.com/kagent-dev/kagent/go/api/v1alpha2"
89
"github.com/pgvector/pgvector-go"
9-
"trpc.group/trpc-go/trpc-a2a-go/protocol"
1010
)
1111

1212
type QueryOptions struct {
@@ -24,8 +24,8 @@ type Client interface {
2424
StoreFeedback(ctx context.Context, feedback *Feedback) error
2525
StoreSession(ctx context.Context, session *Session) error
2626
StoreAgent(ctx context.Context, agent *Agent) error
27-
StoreTask(ctx context.Context, task *protocol.Task) error
28-
StorePushNotification(ctx context.Context, config *protocol.TaskPushNotificationConfig) error
27+
StoreTask(ctx context.Context, task *a2a.Task) error
28+
StorePushNotification(ctx context.Context, config *a2a.PushConfig) error
2929
StoreToolServer(ctx context.Context, toolServer *ToolServer) (*ToolServer, error)
3030
StoreEvents(ctx context.Context, messages ...*Event) error
3131

@@ -40,23 +40,23 @@ type Client interface {
4040
// Get methods
4141
GetSession(ctx context.Context, sessionID string, userID string) (*Session, error)
4242
GetAgent(ctx context.Context, name string) (*Agent, error)
43-
GetTask(ctx context.Context, id string) (*protocol.Task, error)
43+
GetTask(ctx context.Context, id string) (*a2a.Task, error)
4444
GetTool(ctx context.Context, name string) (*Tool, error)
4545
GetToolServer(ctx context.Context, name string) (*ToolServer, error)
46-
GetPushNotification(ctx context.Context, taskID string, configID string) (*protocol.TaskPushNotificationConfig, error)
46+
GetPushNotification(ctx context.Context, taskID string, configID string) (*a2a.PushConfig, error)
4747

4848
// List methods
4949
ListTools(ctx context.Context) ([]Tool, error)
5050
ListFeedback(ctx context.Context, userID string) ([]Feedback, error)
51-
ListTasksForSession(ctx context.Context, sessionID string) ([]*protocol.Task, error)
51+
ListTasksForSession(ctx context.Context, sessionID string) ([]*a2a.Task, error)
5252
ListSessions(ctx context.Context, userID string) ([]Session, error)
5353
ListSessionsForAgent(ctx context.Context, agentID string, userID string) ([]Session, error)
5454
ListSessionsForAgentAllUsers(ctx context.Context, agentID string) ([]Session, error)
5555
ListAgents(ctx context.Context) ([]Agent, error)
5656
ListToolServers(ctx context.Context) ([]ToolServer, error)
5757
ListToolsForServer(ctx context.Context, serverName string, groupKind string) ([]Tool, error)
5858
ListEventsForSession(ctx context.Context, sessionID, userID string, options QueryOptions) ([]*Event, error)
59-
ListPushNotifications(ctx context.Context, taskID string) ([]*protocol.TaskPushNotificationConfig, error)
59+
ListPushNotifications(ctx context.Context, taskID string) ([]*a2a.PushConfig, error)
6060

6161
// Helper methods
6262
RefreshToolsForServer(ctx context.Context, serverName string, groupKind string, tools ...*v1alpha2.MCPTool) error

go/api/database/models.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"encoding/json"
55
"time"
66

7+
a2a "github.com/a2aproject/a2a-go/v2/a2a"
78
"github.com/kagent-dev/kagent/go/api/adk"
89
"github.com/kagent-dev/kagent/go/api/v1alpha2"
910
"github.com/pgvector/pgvector-go"
10-
"trpc.group/trpc-go/trpc-a2a-go/protocol"
1111
)
1212

1313
type Agent struct {
@@ -32,16 +32,16 @@ type Event struct {
3232
Data string `json:"data"` // JSON-serialized protocol.Message
3333
}
3434

35-
func (m *Event) Parse() (protocol.Message, error) {
36-
var data protocol.Message
35+
func (m *Event) Parse() (a2a.Message, error) {
36+
var data a2a.Message
3737
if err := json.Unmarshal([]byte(m.Data), &data); err != nil {
38-
return protocol.Message{}, err
38+
return a2a.Message{}, err
3939
}
4040
return data, nil
4141
}
4242

43-
func ParseMessages(messages []Event) ([]*protocol.Message, error) {
44-
result := make([]*protocol.Message, 0, len(messages))
43+
func ParseMessages(messages []Event) ([]*a2a.Message, error) {
44+
result := make([]*a2a.Message, 0, len(messages))
4545
for _, message := range messages {
4646
parsed, err := message.Parse()
4747
if err != nil {
@@ -77,24 +77,25 @@ type Session struct {
7777
}
7878

7979
type Task struct {
80-
ID string `json:"id"`
81-
CreatedAt time.Time `json:"created_at"`
82-
UpdatedAt time.Time `json:"updated_at"`
83-
DeletedAt *time.Time `json:"deleted_at,omitempty"`
84-
Data string `json:"data"` // JSON-serialized task data
85-
SessionID string `json:"session_id"`
80+
ID string `json:"id"`
81+
CreatedAt time.Time `json:"created_at"`
82+
UpdatedAt time.Time `json:"updated_at"`
83+
DeletedAt *time.Time `json:"deleted_at,omitempty"`
84+
Data string `json:"data"` // JSON-serialized task data
85+
ProtocolVersion *string `json:"protocol_version,omitempty"`
86+
SessionID string `json:"session_id"`
8687
}
8788

88-
func (t *Task) Parse() (protocol.Task, error) {
89-
var data protocol.Task
89+
func (t *Task) Parse() (a2a.Task, error) {
90+
var data a2a.Task
9091
if err := json.Unmarshal([]byte(t.Data), &data); err != nil {
91-
return protocol.Task{}, err
92+
return a2a.Task{}, err
9293
}
9394
return data, nil
9495
}
9596

96-
func ParseTasks(tasks []Task) ([]*protocol.Task, error) {
97-
result := make([]*protocol.Task, 0, len(tasks))
97+
func ParseTasks(tasks []Task) ([]*a2a.Task, error) {
98+
result := make([]*a2a.Task, 0, len(tasks))
9899
for _, task := range tasks {
99100
parsed, err := task.Parse()
100101
if err != nil {
@@ -106,12 +107,13 @@ func ParseTasks(tasks []Task) ([]*protocol.Task, error) {
106107
}
107108

108109
type PushNotification struct {
109-
ID string `json:"id"`
110-
TaskID string `json:"task_id"`
111-
CreatedAt time.Time `json:"created_at"`
112-
UpdatedAt time.Time `json:"updated_at"`
113-
DeletedAt *time.Time `json:"deleted_at,omitempty"`
114-
Data string `json:"data"` // JSON-serialized push notification config
110+
ID string `json:"id"`
111+
TaskID string `json:"task_id"`
112+
CreatedAt time.Time `json:"created_at"`
113+
UpdatedAt time.Time `json:"updated_at"`
114+
DeletedAt *time.Time `json:"deleted_at,omitempty"`
115+
Data string `json:"data"` // JSON-serialized push notification config
116+
ProtocolVersion *string `json:"protocol_version,omitempty"`
115117
}
116118

117119
// FeedbackIssueType represents the category of feedback issue

go/core/internal/a2a/a2a_handler_mux.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@ import (
66
"strings"
77
"sync"
88

9+
a2atype "github.com/a2aproject/a2a-go/v2/a2a"
10+
a2aclient "github.com/a2aproject/a2a-go/v2/a2aclient"
11+
"github.com/a2aproject/a2a-go/v2/a2asrv"
912
"github.com/gorilla/mux"
1013
authimpl "github.com/kagent-dev/kagent/go/core/internal/httpserver/auth"
1114
common "github.com/kagent-dev/kagent/go/core/internal/utils"
1215
"github.com/kagent-dev/kagent/go/core/pkg/auth"
13-
"trpc.group/trpc-go/trpc-a2a-go/client"
14-
"trpc.group/trpc-go/trpc-a2a-go/server"
1516
)
1617

1718
// A2AHandlerMux is an interface that defines methods for adding, getting, and removing agentic task handlers.
1819
type A2AHandlerMux interface {
1920
SetAgentHandler(
2021
agentRef string,
21-
client *client.A2AClient,
22-
card server.AgentCard,
23-
tracing server.Middleware,
22+
client *a2aclient.Client,
23+
card a2atype.AgentCard,
24+
tracing middleware,
2425
) error
2526
RemoveAgentHandler(
2627
agentRef string,
@@ -38,6 +39,10 @@ type handlerMux struct {
3839

3940
var _ A2AHandlerMux = &handlerMux{}
4041

42+
type middleware interface {
43+
Wrap(next http.Handler) http.Handler
44+
}
45+
4146
func NewA2AHttpMux(agentPathPrefix, sandboxPathPrefix string, authenticator auth.AuthProvider) *handlerMux {
4247
return &handlerMux{
4348
handlers: make(map[string]http.Handler),
@@ -49,23 +54,34 @@ func NewA2AHttpMux(agentPathPrefix, sandboxPathPrefix string, authenticator auth
4954

5055
func (a *handlerMux) SetAgentHandler(
5156
agentRef string,
52-
client *client.A2AClient,
53-
card server.AgentCard,
54-
tracing server.Middleware,
57+
client *a2aclient.Client,
58+
card a2atype.AgentCard,
59+
tracing middleware,
5560
) error {
56-
middlewares := []server.Middleware{authimpl.NewA2AAuthenticator(a.authenticator)}
61+
requestHandler := a2asrv.NewHandler(NewPassthroughExecutor(client))
62+
jsonrpcHandler := a2asrv.NewJSONRPCHandler(requestHandler)
63+
cardHandler := a2asrv.NewStaticAgentCardHandler(&card)
64+
wellKnownPath := "/" + strings.TrimPrefix(a2asrv.WellKnownAgentCardPath, "/")
65+
66+
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
67+
if strings.HasSuffix(r.URL.Path, wellKnownPath) {
68+
cardHandler.ServeHTTP(w, r)
69+
return
70+
}
71+
jsonrpcHandler.ServeHTTP(w, r)
72+
})
73+
middlewares := []middleware{authimpl.NewA2AAuthenticator(a.authenticator)}
5774
if tracing != nil {
5875
middlewares = append(middlewares, tracing)
5976
}
60-
srv, err := server.NewA2AServer(card, NewPassthroughManager(client), server.WithMiddleWare(middlewares...))
61-
if err != nil {
62-
return fmt.Errorf("failed to create A2A server: %w", err)
77+
for i := len(middlewares) - 1; i >= 0; i-- {
78+
handler = middlewares[i].Wrap(handler)
6379
}
6480

6581
a.lock.Lock()
6682
defer a.lock.Unlock()
6783

68-
a.handlers[agentRef] = srv.Handler()
84+
a.handlers[agentRef] = handler
6985

7086
return nil
7187
}

0 commit comments

Comments
 (0)