Skip to content

Commit cbc13b4

Browse files
google-genai-botcopybara-github
authored andcommitted
refactor: replacing uses of InvocationContext constructor with a builder
PiperOrigin-RevId: 856180952
1 parent ad951ba commit cbc13b4

File tree

2 files changed

+12
-64
lines changed

2 files changed

+12
-64
lines changed

a2a/src/test/java/com/google/adk/a2a/converters/EventConverterTest.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
import com.google.adk.agents.BaseAgent;
66
import com.google.adk.agents.InvocationContext;
7-
import com.google.adk.agents.RunConfig;
87
import com.google.adk.artifacts.InMemoryArtifactService;
98
import com.google.adk.events.Event;
10-
import com.google.adk.memory.BaseMemoryService;
119
import com.google.adk.plugins.PluginManager;
1210
import com.google.adk.sessions.InMemorySessionService;
1311
import com.google.adk.sessions.Session;
@@ -86,19 +84,14 @@ public void convertEventsToA2AMessage_preservesFunctionCallAndResponseParts() {
8684
Session.builder("session-1").appName("demo").userId("user").events(events).build();
8785

8886
InvocationContext context =
89-
new InvocationContext(
90-
new InMemorySessionService(),
91-
new InMemoryArtifactService(),
92-
(BaseMemoryService) null,
93-
new PluginManager(),
94-
Optional.empty(),
95-
Optional.empty(),
96-
"invocation-1",
97-
new TestAgent(),
98-
session,
99-
Optional.empty(),
100-
RunConfig.builder().build(),
101-
false);
87+
InvocationContext.builder()
88+
.sessionService(new InMemorySessionService())
89+
.artifactService(new InMemoryArtifactService())
90+
.pluginManager(new PluginManager())
91+
.invocationId("invocation-1")
92+
.agent(new TestAgent())
93+
.session(session)
94+
.build();
10295

10396
// Act
10497
Optional<Message> maybeMessage = EventConverter.convertEventsToA2AMessage(context);

core/src/test/java/com/google/adk/tools/retrieval/VertexAiRagRetrievalTest.java

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.google.genai.types.VertexRagStore;
2626
import com.google.genai.types.VertexRagStoreRagResource;
2727
import java.util.Map;
28-
import java.util.Optional;
2928
import org.junit.Rule;
3029
import org.junit.Test;
3130
import org.junit.runner.RunWith;
@@ -56,18 +55,7 @@ public void runAsync_withResults_returnsContexts() throws Exception {
5655
String query = "test query";
5756
ToolContext toolContext =
5857
ToolContext.builder(
59-
new InvocationContext(
60-
/* sessionService= */ null,
61-
/* artifactService= */ null,
62-
/* memoryService= */ null,
63-
/* liveRequestQueue= */ Optional.empty(),
64-
/* branch= */ Optional.empty(),
65-
/* invocationId= */ null,
66-
/* agent= */ null,
67-
Session.builder("123").build(),
68-
/* userContent= */ null,
69-
/* runConfig= */ null,
70-
/* endInvocation= */ false))
58+
InvocationContext.builder().session(Session.builder("123").build()).build())
7159
.functionCallId("functionCallId")
7260
.build();
7361
RetrieveContextsRequest expectedRequest =
@@ -111,18 +99,7 @@ public void runAsync_noResults_returnsNoResultFoundMessage() throws Exception {
11199
String query = "test query";
112100
ToolContext toolContext =
113101
ToolContext.builder(
114-
new InvocationContext(
115-
/* sessionService= */ null,
116-
/* artifactService= */ null,
117-
/* memoryService= */ null,
118-
/* liveRequestQueue= */ Optional.empty(),
119-
/* branch= */ Optional.empty(),
120-
/* invocationId= */ null,
121-
/* agent= */ null,
122-
Session.builder("123").build(),
123-
/* userContent= */ Optional.empty(),
124-
/* runConfig= */ null,
125-
/* endInvocation= */ false))
102+
InvocationContext.builder().session(Session.builder("123").build()).build())
126103
.functionCallId("functionCallId")
127104
.build();
128105
RetrieveContextsRequest expectedRequest =
@@ -168,18 +145,7 @@ public void processLlmRequest_gemini2Model_addVertexRagStoreToConfig() {
168145
LlmRequest.Builder llmRequestBuilder = LlmRequest.builder().model("gemini-2-pro");
169146
ToolContext toolContext =
170147
ToolContext.builder(
171-
new InvocationContext(
172-
/* sessionService= */ null,
173-
/* artifactService= */ null,
174-
/* memoryService= */ null,
175-
/* liveRequestQueue= */ Optional.empty(),
176-
/* branch= */ Optional.empty(),
177-
/* invocationId= */ null,
178-
/* agent= */ null,
179-
Session.builder("123").build(),
180-
/* userContent= */ Optional.empty(),
181-
/* runConfig= */ null,
182-
/* endInvocation= */ false))
148+
InvocationContext.builder().session(Session.builder("123").build()).build())
183149
.functionCallId("functionCallId")
184150
.build();
185151

@@ -245,18 +211,7 @@ public void processLlmRequest_otherModel_doNotAddVertexRagStoreToConfig() {
245211
LlmRequest.Builder llmRequestBuilder = LlmRequest.builder().model("gemini-1-pro");
246212
ToolContext toolContext =
247213
ToolContext.builder(
248-
new InvocationContext(
249-
/* sessionService= */ null,
250-
/* artifactService= */ null,
251-
/* memoryService= */ null,
252-
/* liveRequestQueue= */ Optional.empty(),
253-
/* branch= */ Optional.empty(),
254-
/* invocationId= */ null,
255-
/* agent= */ null,
256-
Session.builder("123").build(),
257-
/* userContent= */ Optional.empty(),
258-
/* runConfig= */ null,
259-
/* endInvocation= */ false))
214+
InvocationContext.builder().session(Session.builder("123").build()).build())
260215
.functionCallId("functionCallId")
261216
.build();
262217
GenerateContentConfig initialConfig = GenerateContentConfig.builder().build();

0 commit comments

Comments
 (0)