From fa58a8d1d7c31ea93a61dce1e854663fcd257332 Mon Sep 17 00:00:00 2001 From: Koichi Shiraishi Date: Fri, 20 Feb 2026 00:14:42 +0900 Subject: [PATCH] chore: add interface assertion for readability Add interface assertion for readability. Signed-off-by: Koichi Shiraishi --- agent/agent.go | 6 ++++-- agent/agent_test.go | 2 ++ agent/llmagent/llmagent.go | 2 ++ agent/llmagent/state_agent_test.go | 2 ++ agent/loader.go | 16 ++++++++++------ agent/loader_test.go | 4 ++-- agent/remoteagent/a2a_e2e_test.go | 2 ++ agent/workflowagents/loopagent/agent_test.go | 2 ++ .../sequentialagent/agent_test.go | 2 ++ artifact/gcsartifact/gcs_client.go | 18 ++++++++++-------- artifact/gcsartifact/gcs_test.go | 18 ++++++++++-------- artifact/gcsartifact/service.go | 4 +++- artifact/inmemory.go | 4 ++-- internal/agent/state.go | 12 +++++++----- internal/context/invocation_context.go | 4 ++-- internal/llminternal/agent.go | 6 ++++-- internal/llminternal/agent_transfer.go | 18 +++++++++++------- internal/llminternal/base_flow.go | 4 ++-- .../llminternal/base_flow_telemetry_test.go | 2 ++ internal/llminternal/base_flow_test.go | 5 +++++ .../llminternal/contents_processor_test.go | 12 +++++++----- internal/llminternal/functions_test.go | 2 ++ internal/llminternal/googlellm/variant_test.go | 4 ++-- internal/llminternal/outputschema_processor.go | 10 +++++++++- .../llminternal/outputschema_processor_test.go | 7 +++++++ .../request_confirmation_processor_test.go | 3 +++ internal/testutil/test_agent_runner.go | 6 +++--- memory/inmemory.go | 2 ++ memory/inmemory_test.go | 2 ++ model/gemini/gemini.go | 2 ++ plugin/functioncallmodifier/plugin_test.go | 2 ++ plugin/retryandreflect/plugin_test.go | 2 ++ server/adka2a/executor_context.go | 2 ++ server/adka2a/executor_test.go | 2 ++ .../internal/fakes/testsessionservice.go | 6 ++++-- server/adkrest/internal/routers/apps.go | 2 ++ server/adkrest/internal/routers/artifacts.go | 2 ++ server/adkrest/internal/routers/debug.go | 2 ++ server/adkrest/internal/routers/eval.go | 2 ++ server/adkrest/internal/routers/runtime.go | 2 ++ server/adkrest/internal/routers/sessions.go | 2 ++ .../services/agentgraphgenerator_test.go | 4 ++++ session/database/service.go | 4 +++- session/database/session.go | 13 +++++++------ session/inmemory.go | 8 +++++--- session/vertexai/session.go | 13 +++++++------ session/vertexai/vertexai.go | 2 ++ tool/agenttool/agent_tool.go | 18 +++++++++++++++--- tool/functiontool/function.go | 6 ++++++ tool/geminitool/google_search.go | 16 ++++++++++++---- tool/geminitool/tool.go | 6 ++++++ tool/loadartifactstool/load_artifacts_tool.go | 6 ++++++ tool/loadmemorytool/tool.go | 5 +++++ tool/mcptoolset/client.go | 4 ++-- tool/mcptoolset/tool.go | 10 +++++----- tool/preloadmemorytool/tool.go | 6 ++++++ 56 files changed, 240 insertions(+), 90 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index a8d3d0e30..acdf6bf6b 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -145,6 +145,8 @@ type agent struct { afterAgentCallbacks []AfterAgentCallback } +var _ Agent = (*agent)(nil) + func (a *agent) Name() string { return a.name } @@ -440,6 +442,8 @@ type invocationContext struct { endInvocation bool } +var _ InvocationContext = (*invocationContext)(nil) + func (c *invocationContext) Agent() Agent { return c.agent } @@ -499,5 +503,3 @@ type pluginManager interface { RunBeforeAgentCallback(cctx CallbackContext) (*genai.Content, error) RunAfterAgentCallback(cctx CallbackContext) (*genai.Content, error) } - -var _ InvocationContext = (*invocationContext)(nil) diff --git a/agent/agent_test.go b/agent/agent_test.go index 0524cad71..4aa35c2ed 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -277,4 +277,6 @@ type mockSession struct { sessionID string } +var _ session.Session = (*mockSession)(nil) + func (m *mockSession) ID() string { return m.sessionID } diff --git a/agent/llmagent/llmagent.go b/agent/llmagent/llmagent.go index c6ebb6778..b7c65c869 100644 --- a/agent/llmagent/llmagent.go +++ b/agent/llmagent/llmagent.go @@ -342,6 +342,8 @@ type llmAgent struct { outputSchema *genai.Schema } +var _ agentinternal.Agent = (*llmAgent)(nil) + type agentState = agentinternal.State func (a *llmAgent) run(ctx agent.InvocationContext) iter.Seq2[*session.Event, error] { diff --git a/agent/llmagent/state_agent_test.go b/agent/llmagent/state_agent_test.go index d8370a2b9..42856a931 100644 --- a/agent/llmagent/state_agent_test.go +++ b/agent/llmagent/state_agent_test.go @@ -41,6 +41,8 @@ type FakeLLM struct { GenerateContentFunc func(ctx context.Context, req *model.LLMRequest, stream bool) (model.LLMResponse, error) } +var _ model.LLM = (*FakeLLM)(nil) + func (f *FakeLLM) Name() string { return "fake-llm" } diff --git a/agent/loader.go b/agent/loader.go index 96cc5462e..082cda792 100644 --- a/agent/loader.go +++ b/agent/loader.go @@ -28,17 +28,13 @@ type Loader interface { RootAgent() Agent } -// multiLoader should be used when you have multiple agents -type multiLoader struct { - agentMap map[string]Agent - root Agent -} - // singleLoader should be used when you have only one agent type singleLoader struct { root Agent } +var _ Loader = (*singleLoader)(nil) + // NewSingleLoader returns a loader with only one agent, which becomes the root agent func NewSingleLoader(a Agent) Loader { return &singleLoader{root: a} @@ -65,6 +61,14 @@ func (s *singleLoader) RootAgent() Agent { return s.root } +// multiLoader should be used when you have multiple agents +type multiLoader struct { + agentMap map[string]Agent + root Agent +} + +var _ Loader = (*multiLoader)(nil) + // NewMultiLoader returns a new AgentLoader with the given root Agent and other agents. // Returns an error if more than one agent (including root) shares the same name func NewMultiLoader(root Agent, agents ...Agent) (Loader, error) { diff --git a/agent/loader_test.go b/agent/loader_test.go index b2cc3e768..3af538fb9 100644 --- a/agent/loader_test.go +++ b/agent/loader_test.go @@ -21,12 +21,12 @@ import ( "google.golang.org/adk/session" ) -var _ Agent = (*testAgent)(nil) - type testAgent struct { name string } +var _ Agent = (*testAgent)(nil) + func (a *testAgent) Name() string { return a.name } diff --git a/agent/remoteagent/a2a_e2e_test.go b/agent/remoteagent/a2a_e2e_test.go index 004a9d4b2..f48afe541 100644 --- a/agent/remoteagent/a2a_e2e_test.go +++ b/agent/remoteagent/a2a_e2e_test.go @@ -737,6 +737,8 @@ type llmStub struct { generateContent func(ctx context.Context, req *model.LLMRequest, stream bool) iter.Seq2[*model.LLMResponse, error] } +var _ model.LLM = (*llmStub)(nil) + func (d *llmStub) Name() string { return d.name } diff --git a/agent/workflowagents/loopagent/agent_test.go b/agent/workflowagents/loopagent/agent_test.go index ee38334cf..9a47c98a0 100644 --- a/agent/workflowagents/loopagent/agent_test.go +++ b/agent/workflowagents/loopagent/agent_test.go @@ -334,6 +334,8 @@ type FakeLLM struct { skipSummarization bool } +var _ model.LLM = (*FakeLLM)(nil) + func (f *FakeLLM) Name() string { return "fake-llm" } diff --git a/agent/workflowagents/sequentialagent/agent_test.go b/agent/workflowagents/sequentialagent/agent_test.go index 58641ada2..016960dc5 100644 --- a/agent/workflowagents/sequentialagent/agent_test.go +++ b/agent/workflowagents/sequentialagent/agent_test.go @@ -299,6 +299,8 @@ type FakeLLM struct { callCounter int } +var _ model.LLM = (*FakeLLM)(nil) + func (f *FakeLLM) Name() string { return "fake-llm" } diff --git a/artifact/gcsartifact/gcs_client.go b/artifact/gcsartifact/gcs_client.go index bf36435c6..b5abd1797 100644 --- a/artifact/gcsartifact/gcs_client.go +++ b/artifact/gcsartifact/gcs_client.go @@ -59,6 +59,8 @@ type gcsClientWrapper struct { client *storage.Client } +var _ gcsClient = (*gcsClientWrapper)(nil) + // Bucket returns a gcsBucketWrapper that satisfies the gcsBucket interface. func (w *gcsClientWrapper) bucket(name string) gcsBucket { return &gcsBucketWrapper{ @@ -71,6 +73,8 @@ type gcsBucketWrapper struct { bucket *storage.BucketHandle } +var _ gcsBucket = (*gcsBucketWrapper)(nil) + // Object returns a gcsObjectWrapper that satisfies the gcsObject interface. func (w *gcsBucketWrapper) object(name string) gcsObject { objectHandle := w.bucket.Object(name) @@ -92,6 +96,8 @@ type gcsObjectWrapper struct { object *storage.ObjectHandle } +var _ gcsObject = (*gcsObjectWrapper)(nil) + // NewWriter implements the gcsObject interface for gcsObjectWrapper. func (w *gcsObjectWrapper) newWriter(ctx context.Context) gcsWriter { return &gcsWriterWrapper{w: w.object.NewWriter(ctx)} @@ -117,6 +123,8 @@ type gcsObjectIteratorWrapper struct { iter *storage.ObjectIterator } +var _ gcsObjectIterator = (*gcsObjectIteratorWrapper)(nil) + func (w *gcsObjectIteratorWrapper) next() (*storage.ObjectAttrs, error) { return w.iter.Next() } @@ -126,6 +134,8 @@ type gcsWriterWrapper struct { w *storage.Writer } +var _ gcsWriter = (*gcsWriterWrapper)(nil) + func (g *gcsWriterWrapper) Write(p []byte) (n int, err error) { return g.w.Write(p) } @@ -137,11 +147,3 @@ func (g *gcsWriterWrapper) Close() error { func (g *gcsWriterWrapper) SetContentType(cType string) { g.w.ContentType = cType } - -var ( - _ gcsClient = (*gcsClientWrapper)(nil) - _ gcsBucket = (*gcsBucketWrapper)(nil) - _ gcsObject = (*gcsObjectWrapper)(nil) - _ gcsObjectIterator = (*gcsObjectIteratorWrapper)(nil) - _ gcsWriter = (*gcsWriterWrapper)(nil) -) diff --git a/artifact/gcsartifact/gcs_test.go b/artifact/gcsartifact/gcs_test.go index b5b89d57a..0b9f666e4 100644 --- a/artifact/gcsartifact/gcs_test.go +++ b/artifact/gcsartifact/gcs_test.go @@ -55,6 +55,8 @@ type fakeClient struct { inMemoryBucket gcsBucket } +var _ gcsClient = (*fakeClient)(nil) + func newFakeClient() gcsClient { return &fakeClient{ inMemoryBucket: &fakeBucket{ @@ -74,6 +76,8 @@ type fakeBucket struct { objectsMap map[string]*fakeObject } +var _ gcsBucket = (*fakeBucket)(nil) + // Object returns a fake object from the in-memory store. func (f *fakeBucket) object(name string) gcsObject { f.mu.Lock() @@ -116,6 +120,8 @@ type fakeObject struct { contentType string } +var _ gcsObject = (*fakeObject)(nil) + // NewWriter returns a fake writer that stores data in memory. func (f *fakeObject) newWriter(ctx context.Context) gcsWriter { f.mu.Lock() @@ -160,6 +166,8 @@ type fakeWriter struct { contentType string } +var _ gcsWriter = (*fakeWriter)(nil) + func (w *fakeWriter) Write(p []byte) (n int, err error) { return w.buffer.Write(p) } @@ -184,6 +192,8 @@ type fakeObjectIterator struct { index int } +var _ gcsObjectIterator = (*fakeObjectIterator)(nil) + // Next implements the iterator pattern. // It returns the next object in the slice or an iterator.Done error. func (i *fakeObjectIterator) next() (*storage.ObjectAttrs, error) { @@ -194,11 +204,3 @@ func (i *fakeObjectIterator) next() (*storage.ObjectAttrs, error) { i.index++ return &storage.ObjectAttrs{Name: obj.name, ContentType: obj.contentType}, nil } - -var ( - _ gcsClient = (*fakeClient)(nil) - _ gcsBucket = (*fakeBucket)(nil) - _ gcsObject = (*fakeObject)(nil) - _ gcsObjectIterator = (*fakeObjectIterator)(nil) - _ gcsWriter = (*fakeWriter)(nil) -) diff --git a/artifact/gcsartifact/service.go b/artifact/gcsartifact/service.go index f60ad0bfc..325ccbebf 100644 --- a/artifact/gcsartifact/service.go +++ b/artifact/gcsartifact/service.go @@ -39,13 +39,15 @@ import ( "google.golang.org/adk/artifact" ) -// gcsService is a google cloud storage implementation of the Service. +// gcsService is a google cloud storage implementation of the [artifact.Service]. type gcsService struct { bucketName string storageClient gcsClient bucket gcsBucket } +var _ artifact.Service = (*gcsService)(nil) + // NewService creates a Google Cloud Storage service for the specified bucket. func NewService(ctx context.Context, bucketName string, opts ...option.ClientOption) (artifact.Service, error) { storageClient, err := storage.NewClient(ctx, opts...) diff --git a/artifact/inmemory.go b/artifact/inmemory.go index 66d73b5a4..3882661a1 100644 --- a/artifact/inmemory.go +++ b/artifact/inmemory.go @@ -39,6 +39,8 @@ type inMemoryService struct { artifacts omap.Map[string, *genai.Part] } +var _ Service = (*inMemoryService)(nil) + // InMemoryService returns a new in-memory artifact service. func InMemoryService() Service { return &inMemoryService{} @@ -284,5 +286,3 @@ func (s *inMemoryService) Versions(ctx context.Context, req *VersionsRequest) (* } return &VersionsResponse{Versions: versions}, nil } - -var _ Service = (*inMemoryService)(nil) diff --git a/internal/agent/state.go b/internal/agent/state.go index b23172631..43c82f2fc 100644 --- a/internal/agent/state.go +++ b/internal/agent/state.go @@ -14,7 +14,7 @@ package agent -// holds Agent internal state +// Agent holds agent internal state. type Agent interface { internal() *State } @@ -24,6 +24,12 @@ type State struct { Config any } +var _ Agent = (*State)(nil) + +func (s *State) internal() *State { return s } + +func Reveal(a Agent) *State { return a.internal() } + type Type string const ( @@ -33,7 +39,3 @@ const ( TypeParallelAgent Type = "ParallelAgent" TypeCustomAgent Type = "CustomAgent" ) - -func (s *State) internal() *State { return s } - -func Reveal(a Agent) *State { return a.internal() } diff --git a/internal/context/invocation_context.go b/internal/context/invocation_context.go index c050fc11a..abf8b5b2e 100644 --- a/internal/context/invocation_context.go +++ b/internal/context/invocation_context.go @@ -54,6 +54,8 @@ type InvocationContext struct { params InvocationContextParams } +var _ agent.InvocationContext = (*InvocationContext)(nil) + func (c *InvocationContext) Artifacts() agent.Artifacts { return c.params.Artifacts } @@ -99,5 +101,3 @@ func (c *InvocationContext) WithContext(ctx context.Context) agent.InvocationCon newCtx.Context = ctx return &newCtx } - -var _ agent.InvocationContext = (*InvocationContext)(nil) diff --git a/internal/llminternal/agent.go b/internal/llminternal/agent.go index b3239ce1e..ce047afae 100644 --- a/internal/llminternal/agent.go +++ b/internal/llminternal/agent.go @@ -22,11 +22,13 @@ import ( "google.golang.org/adk/tool" ) -// holds LLMAgent internal state +// Agent holds LLMAgent internal state. type Agent interface { internal() *State } +type InstructionProvider func(ctx agent.ReadonlyContext) (string, error) + type State struct { Model model.LLM @@ -51,7 +53,7 @@ type State struct { OutputKey string } -type InstructionProvider func(ctx agent.ReadonlyContext) (string, error) +var _ Agent = (*State)(nil) func (s *State) internal() *State { return s } diff --git a/internal/llminternal/agent_transfer.go b/internal/llminternal/agent_transfer.go index 877cf4f63..69674c48a 100644 --- a/internal/llminternal/agent_transfer.go +++ b/internal/llminternal/agent_transfer.go @@ -97,22 +97,28 @@ func AgentTransferRequestProcessor(ctx agent.InvocationContext, req *model.LLMRe type TransferToAgentTool struct{} -// Description implements tool.Tool. +var ( + _ toolinternal.FunctionTool = (*TransferToAgentTool)(nil) + _ toolinternal.RequestProcessor = (*TransferToAgentTool)(nil) +) + +// Description implements [toolinternal.FunctionTool]. func (t *TransferToAgentTool) Description() string { return `Transfer the question to another agent. This tool hands off control to another agent when it's more suitable to answer the user's question according to the agent's description.` } -// Name implements tool.Tool. +// Name implements [toolinternal.FunctionTool]. func (t *TransferToAgentTool) Name() string { return "transfer_to_agent" } -// IsLongRunning implements tool.Tool. +// IsLongRunning implements [toolinternal.FunctionTool]. func (t *TransferToAgentTool) IsLongRunning() bool { return false } +// Declaration implements [toolinternal.FunctionTool]. func (t *TransferToAgentTool) Declaration() *genai.FunctionDeclaration { return &genai.FunctionDeclaration{ Name: t.Name(), @@ -130,12 +136,12 @@ func (t *TransferToAgentTool) Declaration() *genai.FunctionDeclaration { } } -// ProcessRequest implements types.Tool. +// ProcessRequest implements [toolinternal.RequestProcessor]. func (t *TransferToAgentTool) ProcessRequest(ctx tool.Context, req *model.LLMRequest) error { return appendTools(req, t) } -// Run implements types.Tool. +// Run implements [toolinternal.FunctionTool]. func (t *TransferToAgentTool) Run(ctx tool.Context, args any) (map[string]any, error) { if args == nil { return nil, fmt.Errorf("missing argument") @@ -152,8 +158,6 @@ func (t *TransferToAgentTool) Run(ctx tool.Context, args any) (map[string]any, e return map[string]any{}, nil } -var _ tool.Tool = (*TransferToAgentTool)(nil) - func transferTargets(agent, parent agent.Agent) []agent.Agent { targets := slices.Clone(agent.SubAgents()) diff --git a/internal/llminternal/base_flow.go b/internal/llminternal/base_flow.go index b10a232e9..f2230b87f 100644 --- a/internal/llminternal/base_flow.go +++ b/internal/llminternal/base_flow.go @@ -507,12 +507,12 @@ type fakeTool struct { name string } +var _ tool.Tool = (*fakeTool)(nil) + func (f *fakeTool) Name() string { return f.name } func (*fakeTool) Description() string { return "Tool not found" } func (*fakeTool) IsLongRunning() bool { return false } -var _ tool.Tool = (*fakeTool)(nil) - // newToolNotFoundError creates an error matching the specific Python format func newToolNotFoundError(toolName string, availableTools []string) error { joinedTools := strings.Join(availableTools, ", ") diff --git a/internal/llminternal/base_flow_telemetry_test.go b/internal/llminternal/base_flow_telemetry_test.go index 8381a8406..7c709fde3 100644 --- a/internal/llminternal/base_flow_telemetry_test.go +++ b/internal/llminternal/base_flow_telemetry_test.go @@ -41,6 +41,8 @@ type mockModelForTest struct { generateContent func(ctx context.Context, req *model.LLMRequest, stream bool) iter.Seq2[*model.LLMResponse, error] } +var _ model.LLM = (*mockModelForTest)(nil) + func (m *mockModelForTest) Name() string { return m.name } diff --git a/internal/llminternal/base_flow_test.go b/internal/llminternal/base_flow_test.go index 9a8f2ec64..777733678 100644 --- a/internal/llminternal/base_flow_test.go +++ b/internal/llminternal/base_flow_test.go @@ -33,6 +33,11 @@ type mockFunctionTool struct { runFunc func(tool.Context, map[string]any) (map[string]any, error) } +var ( + _ toolinternal.FunctionTool = (*mockFunctionTool)(nil) + _ toolinternal.RequestProcessor = (*mockFunctionTool)(nil) +) + func (m *mockFunctionTool) Name() string { return m.name } diff --git a/internal/llminternal/contents_processor_test.go b/internal/llminternal/contents_processor_test.go index bdb3adf81..b11a8808f 100644 --- a/internal/llminternal/contents_processor_test.go +++ b/internal/llminternal/contents_processor_test.go @@ -37,6 +37,8 @@ type testModel struct { model.LLM } +var _ model.LLM = (*testModel)(nil) + // Test behavior around Agent's IncludeContents. func TestContentsRequestProcessor_IncludeContents(t *testing.T) { const agentName = "testAgent" @@ -931,6 +933,11 @@ type fakeSession struct { events []*session.Event } +var ( + _ session.Session = (*fakeSession)(nil) + _ session.Events = (*fakeSession)(nil) +) + func (s *fakeSession) State() session.State { return nil } @@ -966,8 +973,3 @@ func (s *fakeSession) Len() int { func (s *fakeSession) At(i int) *session.Event { return s.events[i] } - -var ( - _ session.Session = (*fakeSession)(nil) - _ session.Events = (*fakeSession)(nil) -) diff --git a/internal/llminternal/functions_test.go b/internal/llminternal/functions_test.go index 63aa27169..8ea203c5e 100644 --- a/internal/llminternal/functions_test.go +++ b/internal/llminternal/functions_test.go @@ -32,6 +32,8 @@ type mockAgent struct { name string } +var _ agent.Agent = (*mockAgent)(nil) + func (m *mockAgent) Name() string { return m.name } diff --git a/internal/llminternal/googlellm/variant_test.go b/internal/llminternal/googlellm/variant_test.go index 6c418de77..8b8190300 100644 --- a/internal/llminternal/googlellm/variant_test.go +++ b/internal/llminternal/googlellm/variant_test.go @@ -101,6 +101,8 @@ type mockGoogleLLM struct { nameVal string } +var _ GoogleLLM = (*mockGoogleLLM)(nil) + func (m *mockGoogleLLM) GetGoogleLLMVariant() genai.Backend { return m.variant } @@ -108,5 +110,3 @@ func (m *mockGoogleLLM) GetGoogleLLMVariant() genai.Backend { func (m *mockGoogleLLM) Name() string { return m.nameVal } - -var _ GoogleLLM = (*mockGoogleLLM)(nil) diff --git a/internal/llminternal/outputschema_processor.go b/internal/llminternal/outputschema_processor.go index e64847532..075181a74 100644 --- a/internal/llminternal/outputschema_processor.go +++ b/internal/llminternal/outputschema_processor.go @@ -23,6 +23,7 @@ import ( "google.golang.org/adk/agent" "google.golang.org/adk/internal/llminternal/googlellm" + "google.golang.org/adk/internal/toolinternal" "google.golang.org/adk/internal/toolinternal/toolutils" "google.golang.org/adk/internal/utils" "google.golang.org/adk/model" @@ -104,23 +105,29 @@ func needOutputSchemaProcessor(state *State) bool { return hasTools && googlellm.NeedsOutputSchemaProcessor(state.Model) } -// setModelResponseTool implements tool.Tool and toolinternal.FunctionTool. +// setModelResponseTool implements [tool.Tool] and [toolinternal.FunctionTool]. type setModelResponseTool struct { schema *genai.Schema } +var _ toolinternal.FunctionTool = (*setModelResponseTool)(nil) + +// Name implements [toolinternal.FunctionTool]. func (t *setModelResponseTool) Name() string { return "set_model_response" } +// Description implements [toolinternal.FunctionTool]. func (t *setModelResponseTool) Description() string { return "Set your final response using the required output schema. Use this tool to provide your final structured answer instead of outputting text directly." } +// IsLongRunning implements [toolinternal.FunctionTool]. func (t *setModelResponseTool) IsLongRunning() bool { return false } +// Declaration implements [toolinternal.FunctionTool]. func (t *setModelResponseTool) Declaration() *genai.FunctionDeclaration { return &genai.FunctionDeclaration{ Name: t.Name(), @@ -129,6 +136,7 @@ func (t *setModelResponseTool) Declaration() *genai.FunctionDeclaration { } } +// Run implements [toolinternal.FunctionTool]. func (t *setModelResponseTool) Run(ctx tool.Context, args any) (map[string]any, error) { m, ok := args.(map[string]any) if !ok { diff --git a/internal/llminternal/outputschema_processor_test.go b/internal/llminternal/outputschema_processor_test.go index a4f4b38fc..bc356925d 100644 --- a/internal/llminternal/outputschema_processor_test.go +++ b/internal/llminternal/outputschema_processor_test.go @@ -25,6 +25,7 @@ import ( "google.golang.org/adk/agent" icontext "google.golang.org/adk/internal/context" + "google.golang.org/adk/internal/llminternal/googlellm" "google.golang.org/adk/internal/toolinternal" "google.golang.org/adk/internal/utils" "google.golang.org/adk/model" @@ -36,6 +37,8 @@ type mockTool struct { name string } +var _ toolinternal.FunctionTool = (*mockTool)(nil) + func (m *mockTool) Name() string { return m.name } func (m *mockTool) Description() string { return "mock tool" } func (m *mockTool) IsLongRunning() bool { return false } @@ -50,6 +53,8 @@ type mockLLM struct { variant *genai.Backend } +var _ googlellm.GoogleLLM = (*mockLLM)(nil) + func (m *mockLLM) Name() string { return m.name } func (m *mockLLM) GetGoogleLLMVariant() genai.Backend { @@ -65,6 +70,8 @@ type mockLLMAgent struct { s *State } +var _ Agent = (*mockLLMAgent)(nil) + func (m *mockLLMAgent) internal() *State { return m.s } diff --git a/internal/llminternal/request_confirmation_processor_test.go b/internal/llminternal/request_confirmation_processor_test.go index 979cdf9d8..d1fdd588c 100644 --- a/internal/llminternal/request_confirmation_processor_test.go +++ b/internal/llminternal/request_confirmation_processor_test.go @@ -28,6 +28,7 @@ import ( "google.golang.org/adk/agent/llmagent" icontext "google.golang.org/adk/internal/context" "google.golang.org/adk/internal/llminternal" + "google.golang.org/adk/internal/toolinternal" "google.golang.org/adk/model" "google.golang.org/adk/session" "google.golang.org/adk/tool" @@ -44,6 +45,8 @@ type mockTool struct { name string } +var _ toolinternal.FunctionTool = (*mockTool)(nil) + func (m *mockTool) Name() string { return m.name } func (m *mockTool) Description() string { return "mock tool" } func (m *mockTool) IsLongRunning() bool { return false } diff --git a/internal/testutil/test_agent_runner.go b/internal/testutil/test_agent_runner.go index 1e4168e23..eef731680 100644 --- a/internal/testutil/test_agent_runner.go +++ b/internal/testutil/test_agent_runner.go @@ -147,6 +147,8 @@ type MockModel struct { StreamResponsesCount int } +var _ model.LLM = (*MockModel)(nil) + var errNoModelData = errors.New("no data") func (m *MockModel) GenerateContent(ctx context.Context, req *model.LLMRequest, stream bool) iter.Seq2[*model.LLMResponse, error] { @@ -159,7 +161,7 @@ func (m *MockModel) GenerateContent(ctx context.Context, req *model.LLMRequest, } } -// GenerateContent implements llm.Model. +// Generate implements [model.LLM]. func (m *MockModel) Generate(ctx context.Context, req *model.LLMRequest) (*model.LLMResponse, error) { m.Requests = append(m.Requests, req) if len(m.Responses) == 0 { @@ -205,8 +207,6 @@ func (m *MockModel) Name() string { return "mock" } -var _ model.LLM = (*MockModel)(nil) - // CollectEvents collects all event from the llm response until encountering an error. // It returns all collected events and the last error. func CollectEvents(stream iter.Seq2[*session.Event, error]) ([]*session.Event, error) { diff --git a/memory/inmemory.go b/memory/inmemory.go index 0d9274855..89a9805e4 100644 --- a/memory/inmemory.go +++ b/memory/inmemory.go @@ -54,6 +54,8 @@ type inMemoryService struct { store map[key]map[sessionID][]value } +var _ Service = (*inMemoryService)(nil) + func (s *inMemoryService) AddSession(ctx context.Context, curSession session.Session) error { var values []value diff --git a/memory/inmemory_test.go b/memory/inmemory_test.go index 279e260e3..ce88f6d2e 100644 --- a/memory/inmemory_test.go +++ b/memory/inmemory_test.go @@ -180,6 +180,8 @@ type testSession struct { events []*session.Event } +var _ session.Session = (*testSession)(nil) + func (s *testSession) ID() string { return s.sessionID } diff --git a/model/gemini/gemini.go b/model/gemini/gemini.go index 23726c348..8798042bb 100644 --- a/model/gemini/gemini.go +++ b/model/gemini/gemini.go @@ -39,6 +39,8 @@ type geminiModel struct { versionHeaderValue string } +var _ model.LLM = (*geminiModel)(nil) + // NewModel returns [model.LLM], backed by the Gemini API. // // It uses the provided context and configuration to initialize the underlying diff --git a/plugin/functioncallmodifier/plugin_test.go b/plugin/functioncallmodifier/plugin_test.go index 5ab515209..a092b1a8d 100644 --- a/plugin/functioncallmodifier/plugin_test.go +++ b/plugin/functioncallmodifier/plugin_test.go @@ -342,6 +342,8 @@ type mockAgent struct { inputSchema *genai.Schema } +var _ agent.Agent = (*mockAgent)(nil) + func (m *mockAgent) Name() string { return m.name } func (m *mockAgent) Description() string { return m.description } func (m *mockAgent) InputSchema() *genai.Schema { return m.inputSchema } diff --git a/plugin/retryandreflect/plugin_test.go b/plugin/retryandreflect/plugin_test.go index 8fd4ec13d..91346468c 100644 --- a/plugin/retryandreflect/plugin_test.go +++ b/plugin/retryandreflect/plugin_test.go @@ -26,6 +26,8 @@ type mockTool struct { name string } +var _ tool.Tool = (*mockTool)(nil) + func (m *mockTool) Name() string { return m.name } func (m *mockTool) Description() string { return "" } func (m *mockTool) IsLongRunning() bool { return false } diff --git a/server/adka2a/executor_context.go b/server/adka2a/executor_context.go index 33a54b207..f8a927c14 100644 --- a/server/adka2a/executor_context.go +++ b/server/adka2a/executor_context.go @@ -53,6 +53,8 @@ type executorContext struct { userContent *genai.Content } +var _ ExecutorContext = (*executorContext)(nil) + func newExecutorContext(ctx context.Context, meta invocationMeta, plugin *executorPlugin, userContent *genai.Content) ExecutorContext { return &executorContext{ Context: ctx, diff --git a/server/adka2a/executor_test.go b/server/adka2a/executor_test.go index 7bcbb3c47..bc21030a7 100644 --- a/server/adka2a/executor_test.go +++ b/server/adka2a/executor_test.go @@ -55,6 +55,8 @@ type testSessionService struct { createErr bool } +var _ session.Service = (*testSessionService)(nil) + func (s *testSessionService) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error) { if s.createErr { return nil, fmt.Errorf("session creation failed") diff --git a/server/adkrest/internal/fakes/testsessionservice.go b/server/adkrest/internal/fakes/testsessionservice.go index 2abd4f64a..7dcaba32b 100644 --- a/server/adkrest/internal/fakes/testsessionservice.go +++ b/server/adkrest/internal/fakes/testsessionservice.go @@ -73,6 +73,8 @@ type TestSession struct { UpdatedAt time.Time } +var _ session.Session = (*TestSession)(nil) + func (s TestSession) ID() string { return s.Id.SessionID } @@ -101,6 +103,8 @@ type FakeSessionService struct { Sessions map[SessionKey]TestSession } +var _ session.Service = (*FakeSessionService)(nil) + type SessionKey struct { AppName string UserID string @@ -184,5 +188,3 @@ func (s *FakeSessionService) AppendEvent(ctx context.Context, curSession session s.Sessions[testSession.Id] = *testSession return nil } - -var _ session.Service = (*FakeSessionService)(nil) diff --git a/server/adkrest/internal/routers/apps.go b/server/adkrest/internal/routers/apps.go index 3271de9ed..66e5c7475 100644 --- a/server/adkrest/internal/routers/apps.go +++ b/server/adkrest/internal/routers/apps.go @@ -25,6 +25,8 @@ type AppsAPIRouter struct { appsController *controllers.AppsAPIController } +var _ Router = (*AppsAPIRouter)(nil) + // NewAppsAPIRouter creates a new AppsAPIRouter. func NewAppsAPIRouter(controller *controllers.AppsAPIController) *AppsAPIRouter { return &AppsAPIRouter{appsController: controller} diff --git a/server/adkrest/internal/routers/artifacts.go b/server/adkrest/internal/routers/artifacts.go index 967470d42..9d5be8977 100644 --- a/server/adkrest/internal/routers/artifacts.go +++ b/server/adkrest/internal/routers/artifacts.go @@ -25,6 +25,8 @@ type ArtifactsAPIRouter struct { artifactsController *controllers.ArtifactsAPIController } +var _ Router = (*ArtifactsAPIRouter)(nil) + // NewArtifactsAPIRouter creates a new ArtifactsAPIRouter. func NewArtifactsAPIRouter(controller *controllers.ArtifactsAPIController) *ArtifactsAPIRouter { return &ArtifactsAPIRouter{artifactsController: controller} diff --git a/server/adkrest/internal/routers/debug.go b/server/adkrest/internal/routers/debug.go index ad6c03c20..afbcc1152 100644 --- a/server/adkrest/internal/routers/debug.go +++ b/server/adkrest/internal/routers/debug.go @@ -25,6 +25,8 @@ type DebugAPIRouter struct { runtimeController *controllers.DebugAPIController } +var _ Router = (*DebugAPIRouter)(nil) + // NewDebugAPIRouter creates a new DebugAPIRouter. func NewDebugAPIRouter(controller *controllers.DebugAPIController) *DebugAPIRouter { return &DebugAPIRouter{runtimeController: controller} diff --git a/server/adkrest/internal/routers/eval.go b/server/adkrest/internal/routers/eval.go index 2c6c2dfc4..61380efb3 100644 --- a/server/adkrest/internal/routers/eval.go +++ b/server/adkrest/internal/routers/eval.go @@ -23,6 +23,8 @@ import ( // EvalAPIRouter defines the routes for the Eval API. type EvalAPIRouter struct{} +var _ Router = (*EvalAPIRouter)(nil) + // Routes returns the routes for the Apps API. func (r *EvalAPIRouter) Routes() Routes { return Routes{ diff --git a/server/adkrest/internal/routers/runtime.go b/server/adkrest/internal/routers/runtime.go index e27bc79e2..9c3841d17 100644 --- a/server/adkrest/internal/routers/runtime.go +++ b/server/adkrest/internal/routers/runtime.go @@ -25,6 +25,8 @@ type RuntimeAPIRouter struct { runtimeController *controllers.RuntimeAPIController } +var _ Router = (*RuntimeAPIRouter)(nil) + // NewRuntimeAPIRouter creates a new RuntimeAPIRouter. func NewRuntimeAPIRouter(controller *controllers.RuntimeAPIController) *RuntimeAPIRouter { return &RuntimeAPIRouter{runtimeController: controller} diff --git a/server/adkrest/internal/routers/sessions.go b/server/adkrest/internal/routers/sessions.go index 7d38b1013..17dac1740 100644 --- a/server/adkrest/internal/routers/sessions.go +++ b/server/adkrest/internal/routers/sessions.go @@ -25,6 +25,8 @@ type SessionsAPIRouter struct { sessionController *controllers.SessionsAPIController } +var _ Router = (*SessionsAPIRouter)(nil) + // NewSessionsAPIRouter creates a new SessionsAPIRouter. func NewSessionsAPIRouter(controller *controllers.SessionsAPIController) *SessionsAPIRouter { return &SessionsAPIRouter{sessionController: controller} diff --git a/server/adkrest/internal/services/agentgraphgenerator_test.go b/server/adkrest/internal/services/agentgraphgenerator_test.go index 269d3a4db..7f6663ec2 100644 --- a/server/adkrest/internal/services/agentgraphgenerator_test.go +++ b/server/adkrest/internal/services/agentgraphgenerator_test.go @@ -37,6 +37,8 @@ type dummyLLM struct { name string } +var _ model.LLM = (*dummyLLM)(nil) + func (d *dummyLLM) Name() string { return d.name } @@ -105,6 +107,8 @@ type mockTool struct { name string } +var _ tool.Tool = (*mockTool)(nil) + func (m *mockTool) Name() string { return m.name } func (m *mockTool) Description() string { return "" } diff --git a/session/database/service.go b/session/database/service.go index ec64808f1..c3179a282 100644 --- a/session/database/service.go +++ b/session/database/service.go @@ -28,11 +28,13 @@ import ( "google.golang.org/adk/session" ) -// databaseService is an database implementation of sessionService.Service. +// databaseService is an database implementation of [session.Service]. type databaseService struct { db *gorm.DB } +var _ session.Service = (*databaseService)(nil) + // NewSessionService creates a new [session.Service] implementation that uses a // relational database (e.g., PostgreSQL, Spanner, SQLite) via the GORM library. // diff --git a/session/database/session.go b/session/database/session.go index d444ec4af..73a25d0ec 100644 --- a/session/database/session.go +++ b/session/database/session.go @@ -38,6 +38,8 @@ type localSession struct { updatedAt time.Time } +var _ session.Session = (*localSession)(nil) + func (s *localSession) ID() string { return s.sessionID } @@ -87,6 +89,11 @@ func (s *localSession) appendEvent(event *session.Event) error { type events []*session.Event +var ( + _ session.Events = (*events)(nil) + _ session.State = (*state)(nil) +) + func (e events) All() iter.Seq[*session.Event] { return func(yield func(*session.Event) bool) { for _, event := range e { @@ -184,9 +191,3 @@ func updateSessionState(sess *localSession, event *session.Event) error { return nil } - -var ( - _ session.Session = (*localSession)(nil) - _ session.Events = (*events)(nil) - _ session.State = (*state)(nil) -) diff --git a/session/inmemory.go b/session/inmemory.go index 8f48896fc..8a82d712b 100644 --- a/session/inmemory.go +++ b/session/inmemory.go @@ -34,7 +34,7 @@ import ( type stateMap map[string]any -// inMemoryService is an in-memory implementation of sessionService.Service. +// inMemoryService is an in-memory implementation of [Service]. // Thread-safe. type inMemoryService struct { mu sync.RWMutex @@ -43,6 +43,8 @@ type inMemoryService struct { appState map[string]stateMap } +var _ Service = (*inMemoryService)(nil) + func (s *inMemoryService) Create(ctx context.Context, req *CreateRequest) (*CreateResponse, error) { if req.AppName == "" || req.UserID == "" { return nil, fmt.Errorf("app_name and user_id are required, got app_name: %q, user_id: %q", req.AppName, req.UserID) @@ -294,6 +296,8 @@ type session struct { updatedAt time.Time } +var _ Session = (*session)(nil) + func (s *session) ID() string { return s.id.sessionID } @@ -454,5 +458,3 @@ func copySessionWithoutStateAndEvents(sess *session) *session { updatedAt: sess.updatedAt, } } - -var _ Service = (*inMemoryService)(nil) diff --git a/session/vertexai/session.go b/session/vertexai/session.go index 5f4f8fa73..2c6eb14d8 100644 --- a/session/vertexai/session.go +++ b/session/vertexai/session.go @@ -38,6 +38,8 @@ type localSession struct { updatedAt time.Time } +var _ session.Session = (*localSession)(nil) + func (s *localSession) ID() string { return s.sessionID } @@ -87,6 +89,11 @@ func (s *localSession) appendEvent(event *session.Event) error { type events []*session.Event +var ( + _ session.Events = (*events)(nil) + _ session.State = (*state)(nil) +) + func (e events) All() iter.Seq[*session.Event] { return func(yield func(*session.Event) bool) { for _, event := range e { @@ -183,9 +190,3 @@ func updateSessionState(sess *localSession, event *session.Event) error { return nil } - -var ( - _ session.Session = (*localSession)(nil) - _ session.Events = (*events)(nil) - _ session.State = (*state)(nil) -) diff --git a/session/vertexai/vertexai.go b/session/vertexai/vertexai.go index b7b0bb523..a57de74da 100644 --- a/session/vertexai/vertexai.go +++ b/session/vertexai/vertexai.go @@ -29,6 +29,8 @@ type vertexAiService struct { client *vertexAiClient } +var _ session.Service = (*vertexAiService)(nil) + type VertexAIServiceConfig struct { // ProjectID with VertexAI API enabled. ProjectID string diff --git a/tool/agenttool/agent_tool.go b/tool/agenttool/agent_tool.go index 2cfe1a890..6297a7f51 100644 --- a/tool/agenttool/agent_tool.go +++ b/tool/agenttool/agent_tool.go @@ -27,6 +27,7 @@ import ( "google.golang.org/adk/agent" "google.golang.org/adk/artifact" "google.golang.org/adk/internal/llminternal" + "google.golang.org/adk/internal/toolinternal" "google.golang.org/adk/internal/utils" "google.golang.org/adk/memory" "google.golang.org/adk/model" @@ -41,6 +42,11 @@ type agentTool struct { skipSummarization bool } +var ( + _ toolinternal.FunctionTool = (*agentTool)(nil) + _ toolinternal.RequestProcessor = (*agentTool)(nil) +) + // Config holds the configuration for an agent tool. type Config struct { // SkipSummarization, if true, will cause the agent to skip summarization @@ -63,17 +69,17 @@ func New(agent agent.Agent, cfg *Config) tool.Tool { } } -// Name implements tool.Tool. +// Name implements [toolinternal.FunctionTool]. func (t *agentTool) Name() string { return t.agent.Name() } -// Description implements tool.Tool. +// Description implements [toolinternal.FunctionTool]. func (t *agentTool) Description() string { return t.agent.Description() } -// IsLongRunning implements tool.Tool. +// IsLongRunning implements [toolinternal.FunctionTool]. func (t *agentTool) IsLongRunning() bool { return false } @@ -82,6 +88,8 @@ func (t *agentTool) IsLongRunning() bool { // It generates a function declaration based on the agent's input schema. // If the agent does not have an input schema, a default schema with a // "request" string parameter is used. +// +// Declaration implements [toolinternal.FunctionTool]. func (t *agentTool) Declaration() *genai.FunctionDeclaration { decl := &genai.FunctionDeclaration{ Name: t.Name(), @@ -117,6 +125,8 @@ func (t *agentTool) Declaration() *genai.FunctionDeclaration { // Run executes the wrapped agent with the provided arguments. // It creates a new session for the sub-agent, runs the agent, and returns // the final result. +// +// Run implements [toolinternal.FunctionTool]. func (t *agentTool) Run(toolCtx tool.Context, args any) (map[string]any, error) { margs, ok := args.(map[string]any) if !ok { @@ -250,6 +260,8 @@ func (t *agentTool) Run(toolCtx tool.Context, args any) (map[string]any, error) } // ProcessRequest adds the agent tool's function declaration to the LLM request. +// +// ProcessRequest implements [toolinternal.RequestProcessor]. func (t *agentTool) ProcessRequest(ctx tool.Context, req *model.LLMRequest) error { // TODO extract this function somewhere else, simillar operations are done for // other tools with function declaration. diff --git a/tool/functiontool/function.go b/tool/functiontool/function.go index 42f417509..20887acc4 100644 --- a/tool/functiontool/function.go +++ b/tool/functiontool/function.go @@ -24,6 +24,7 @@ import ( "github.com/google/jsonschema-go/jsonschema" "google.golang.org/genai" + "google.golang.org/adk/internal/toolinternal" "google.golang.org/adk/internal/toolinternal/toolutils" "google.golang.org/adk/internal/typeutil" "google.golang.org/adk/model" @@ -135,6 +136,11 @@ type functionTool[TArgs, TResults any] struct { requireConfirmationProvider func(TArgs) bool } +var ( + _ toolinternal.FunctionTool = (*functionTool[any, any])(nil) + _ toolinternal.RequestProcessor = (*functionTool[any, any])(nil) +) + // Description implements tool.Tool. func (f *functionTool[TArgs, TResults]) Description() string { return f.cfg.Description diff --git a/tool/geminitool/google_search.go b/tool/geminitool/google_search.go index df6d1fc84..d1699b413 100644 --- a/tool/geminitool/google_search.go +++ b/tool/geminitool/google_search.go @@ -17,6 +17,7 @@ package geminitool import ( "google.golang.org/genai" + "google.golang.org/adk/internal/toolinternal" "google.golang.org/adk/model" "google.golang.org/adk/tool" ) @@ -27,24 +28,31 @@ import ( // perform local code execution. type GoogleSearch struct{} -// Name implements tool.Tool. +var ( + _ tool.Tool = (*GoogleSearch)(nil) + _ toolinternal.RequestProcessor = (*GoogleSearch)(nil) +) + +// Name implements [tool.Tool]. func (s GoogleSearch) Name() string { return "google_search" } -// Description implements tool.Tool. +// Description implements [tool.Tool]. func (s GoogleSearch) Description() string { return "Performs a Google search to retrieve information from the web." } // ProcessRequest adds the GoogleSearch tool to the LLM request. +// +// ProcessRequest implements [toolinternal.RequestProcessor]. func (s GoogleSearch) ProcessRequest(ctx tool.Context, req *model.LLMRequest) error { return setTool(req, &genai.Tool{ GoogleSearch: &genai.GoogleSearch{}, }) } -// IsLongRunning implements tool.Tool. -func (t GoogleSearch) IsLongRunning() bool { +// IsLongRunning implements [tool.Tool]. +func (s GoogleSearch) IsLongRunning() bool { return false } diff --git a/tool/geminitool/tool.go b/tool/geminitool/tool.go index 76e84bafc..66d14791e 100644 --- a/tool/geminitool/tool.go +++ b/tool/geminitool/tool.go @@ -34,6 +34,7 @@ import ( "google.golang.org/genai" + "google.golang.org/adk/internal/toolinternal" "google.golang.org/adk/model" "google.golang.org/adk/tool" ) @@ -52,6 +53,11 @@ type geminiTool struct { value *genai.Tool } +var ( + _ tool.Tool = (*geminiTool)(nil) + _ toolinternal.RequestProcessor = (*geminiTool)(nil) +) + // ProcessRequest adds the Gemini tool to the LLM request. func (t *geminiTool) ProcessRequest(ctx tool.Context, req *model.LLMRequest) error { return setTool(req, t.value) diff --git a/tool/loadartifactstool/load_artifacts_tool.go b/tool/loadartifactstool/load_artifacts_tool.go index 80b034777..4ad84bd7e 100644 --- a/tool/loadartifactstool/load_artifacts_tool.go +++ b/tool/loadartifactstool/load_artifacts_tool.go @@ -26,6 +26,7 @@ import ( "google.golang.org/genai" "google.golang.org/adk/agent" + "google.golang.org/adk/internal/toolinternal" "google.golang.org/adk/internal/toolinternal/toolutils" "google.golang.org/adk/internal/utils" "google.golang.org/adk/model" @@ -38,6 +39,11 @@ type artifactsTool struct { description string } +var ( + _ toolinternal.FunctionTool = (*artifactsTool)(nil) + _ toolinternal.RequestProcessor = (*artifactsTool)(nil) +) + // New creates a new loadArtifactsTool. func New() tool.Tool { return &artifactsTool{ diff --git a/tool/loadmemorytool/tool.go b/tool/loadmemorytool/tool.go index 6e29c143f..274c52fee 100644 --- a/tool/loadmemorytool/tool.go +++ b/tool/loadmemorytool/tool.go @@ -38,6 +38,11 @@ type loadMemoryTool struct { description string } +var ( + _ toolinternal.FunctionTool = (*loadMemoryTool)(nil) + _ toolinternal.RequestProcessor = (*loadMemoryTool)(nil) +) + // New creates a new loadMemoryTool. func New() toolinternal.FunctionTool { return &loadMemoryTool{ diff --git a/tool/mcptoolset/client.go b/tool/mcptoolset/client.go index 5f53e0e0c..37f3690c7 100644 --- a/tool/mcptoolset/client.go +++ b/tool/mcptoolset/client.go @@ -45,6 +45,8 @@ type connectionRefresher struct { session *mcp.ClientSession } +var _ MCPClient = (*connectionRefresher)(nil) + // refreshableErrors is a list of errors that should trigger a connection refresh. var refreshableErrors = []error{ mcp.ErrConnectionClosed, @@ -190,5 +192,3 @@ func (c *connectionRefresher) refreshConnection(ctx context.Context) (*mcp.Clien c.session = session return c.session, nil } - -var _ MCPClient = (*connectionRefresher)(nil) diff --git a/tool/mcptoolset/tool.go b/tool/mcptoolset/tool.go index 640c0cfc3..e70655bcd 100644 --- a/tool/mcptoolset/tool.go +++ b/tool/mcptoolset/tool.go @@ -67,6 +67,11 @@ type mcpTool struct { requireConfirmationProvider ConfirmationProvider } +var ( + _ toolinternal.FunctionTool = (*mcpTool)(nil) + _ toolinternal.RequestProcessor = (*mcpTool)(nil) +) + // Name implements the tool.Tool. func (t *mcpTool) Name() string { return t.name @@ -172,8 +177,3 @@ func (t *mcpTool) Run(ctx tool.Context, args any) (map[string]any, error) { "output": textResponse.String(), }, nil } - -var ( - _ toolinternal.FunctionTool = (*mcpTool)(nil) - _ toolinternal.RequestProcessor = (*mcpTool)(nil) -) diff --git a/tool/preloadmemorytool/tool.go b/tool/preloadmemorytool/tool.go index ab5866d85..538d51e35 100644 --- a/tool/preloadmemorytool/tool.go +++ b/tool/preloadmemorytool/tool.go @@ -26,6 +26,7 @@ import ( "strings" "time" + "google.golang.org/adk/internal/toolinternal" "google.golang.org/adk/internal/utils" "google.golang.org/adk/memory" "google.golang.org/adk/model" @@ -46,6 +47,11 @@ type preloadMemoryTool struct { description string } +var ( + _ tool.Tool = (*preloadMemoryTool)(nil) + _ toolinternal.RequestProcessor = (*preloadMemoryTool)(nil) +) + // New creates a new preloadMemoryTool. func New() *preloadMemoryTool { return &preloadMemoryTool{