Skip to content

Commit 1cafc0a

Browse files
onematchfoxclaude
andcommitted
refactor(a2a): inject AgentClientRegistry as a dependency
Construct AgentClientRegistry outside of A2ARegistrar and pass it into both NewA2ARegistrar and NewMCPHandler, making the shared dependency explicit. NewA2ARegistrar now returns an error if a nil registry is provided. Removes the ClientRegistry() getter. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: Brian Fox <[email protected]>
1 parent 5802b33 commit 1cafc0a

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

‎go/core/internal/a2a/a2a_registrar.go‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,21 @@ var _ manager.Runnable = (*A2ARegistrar)(nil)
3838
func NewA2ARegistrar(
3939
cache crcache.Cache,
4040
mux A2AHandlerMux,
41+
clientRegistry *AgentClientRegistry,
4142
a2aBaseUrl string,
4243
sandboxA2ABaseURL string,
4344
authenticator auth.AuthProvider,
4445
streamingMaxBuf int,
4546
streamingInitialBuf int,
4647
streamingTimeout time.Duration,
47-
) *A2ARegistrar {
48+
) (*A2ARegistrar, error) {
49+
if clientRegistry == nil {
50+
return nil, fmt.Errorf("clientRegistry must not be nil")
51+
}
4852
reg := &A2ARegistrar{
4953
cache: cache,
5054
handlerMux: mux,
51-
clientRegistry: NewAgentClientRegistry(),
55+
clientRegistry: clientRegistry,
5256
a2aBaseURL: a2aBaseUrl,
5357
sandboxA2AURL: sandboxA2ABaseURL,
5458
authenticator: authenticator,
@@ -59,13 +63,7 @@ func NewA2ARegistrar(
5963
},
6064
}
6165

62-
return reg
63-
}
64-
65-
// ClientRegistry returns the registry of A2A clients for direct agent
66-
// invocation, populated as agents are registered and deregistered.
67-
func (a *A2ARegistrar) ClientRegistry() *AgentClientRegistry {
68-
return a.clientRegistry
66+
return reg, nil
6967
}
7068

7169
func (a *A2ARegistrar) NeedLeaderElection() bool {

‎go/core/pkg/app/app.go‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,16 +613,22 @@ func Start(getExtensionConfig GetExtensionConfig, migrationRunner MigrationRunne
613613

614614
// Register A2A handlers on all replicas
615615
a2aHandler := a2a.NewA2AHttpMux(httpserver.APIPathA2A, httpserver.APIPathA2ASandboxes, extensionCfg.Authenticator)
616-
a2aRegistrar := a2a.NewA2ARegistrar(
616+
clientRegistry := a2a.NewAgentClientRegistry()
617+
a2aRegistrar, err := a2a.NewA2ARegistrar(
617618
mgr.GetCache(),
618619
a2aHandler,
620+
clientRegistry,
619621
cfg.A2ABaseUrl+httpserver.APIPathA2A,
620622
cfg.A2ABaseUrl+httpserver.APIPathA2ASandboxes,
621623
extensionCfg.Authenticator,
622624
int(cfg.Streaming.MaxBufSize.Value()),
623625
int(cfg.Streaming.InitialBufSize.Value()),
624626
cfg.Streaming.Timeout,
625627
)
628+
if err != nil {
629+
setupLog.Error(err, "unable to create a2a registrar")
630+
os.Exit(1)
631+
}
626632
if err := mgr.Add(a2aRegistrar); err != nil {
627633
setupLog.Error(err, "unable to set up a2a registrar")
628634
os.Exit(1)
@@ -632,7 +638,7 @@ func Start(getExtensionConfig GetExtensionConfig, migrationRunner MigrationRunne
632638
// bypassing the controller's own HTTP A2A listener.
633639
mcpHandler, err := mcp.NewMCPHandler(
634640
mgr.GetClient(),
635-
a2aRegistrar.ClientRegistry(),
641+
clientRegistry,
636642
extensionCfg.Authenticator,
637643
)
638644
if err != nil {

0 commit comments

Comments
 (0)