Skip to content

Commit 88153c8

Browse files
tilgalascopybara-github
authored andcommitted
feat!: remove deprecated methods accepting Optional params in InvocationContext
PiperOrigin-RevId: 879073419
1 parent d2f1145 commit 88153c8

2 files changed

Lines changed: 3 additions & 209 deletions

File tree

core/src/main/java/com/google/adk/agents/InvocationContext.java

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -78,70 +78,6 @@ protected InvocationContext(Builder builder) {
7878
this.callbackContextData = new ConcurrentHashMap<>(builder.callbackContextData);
7979
}
8080

81-
/**
82-
* @deprecated Use {@link #builder()} instead.
83-
*/
84-
@Deprecated(forRemoval = true)
85-
public InvocationContext(
86-
BaseSessionService sessionService,
87-
BaseArtifactService artifactService,
88-
BaseMemoryService memoryService,
89-
Plugin pluginManager,
90-
Optional<LiveRequestQueue> liveRequestQueue,
91-
Optional<String> branch,
92-
String invocationId,
93-
BaseAgent agent,
94-
Session session,
95-
Optional<Content> userContent,
96-
RunConfig runConfig,
97-
boolean endInvocation) {
98-
this(
99-
builder()
100-
.sessionService(sessionService)
101-
.artifactService(artifactService)
102-
.memoryService(memoryService)
103-
.pluginManager(pluginManager)
104-
.liveRequestQueue(liveRequestQueue)
105-
.branch(branch)
106-
.invocationId(invocationId)
107-
.agent(agent)
108-
.session(session)
109-
.userContent(userContent)
110-
.runConfig(runConfig)
111-
.endInvocation(endInvocation));
112-
}
113-
114-
/**
115-
* @deprecated Use {@link #builder()} instead.
116-
*/
117-
@Deprecated(forRemoval = true)
118-
public InvocationContext(
119-
BaseSessionService sessionService,
120-
BaseArtifactService artifactService,
121-
BaseMemoryService memoryService,
122-
Optional<LiveRequestQueue> liveRequestQueue,
123-
Optional<String> branch,
124-
String invocationId,
125-
BaseAgent agent,
126-
Session session,
127-
Optional<Content> userContent,
128-
RunConfig runConfig,
129-
boolean endInvocation) {
130-
this(
131-
builder()
132-
.sessionService(sessionService)
133-
.artifactService(artifactService)
134-
.memoryService(memoryService)
135-
.liveRequestQueue(liveRequestQueue)
136-
.branch(branch)
137-
.invocationId(invocationId)
138-
.agent(agent)
139-
.session(session)
140-
.userContent(userContent)
141-
.runConfig(runConfig)
142-
.endInvocation(endInvocation));
143-
}
144-
14581
/**
14682
* @deprecated Use {@link #builder()} instead.
14783
*/
@@ -478,21 +414,6 @@ public Builder pluginManager(Plugin pluginManager) {
478414
return this;
479415
}
480416

481-
/**
482-
* Sets the queue for managing live requests.
483-
*
484-
* @param liveRequestQueue the queue for managing live requests.
485-
* @return this builder instance for chaining.
486-
* @deprecated Use {@link #liveRequestQueue(LiveRequestQueue)} instead.
487-
*/
488-
// TODO: b/462140921 - Builders should not accept Optional parameters.
489-
@Deprecated(forRemoval = true)
490-
@CanIgnoreReturnValue
491-
public Builder liveRequestQueue(Optional<LiveRequestQueue> liveRequestQueue) {
492-
this.liveRequestQueue = liveRequestQueue.orElse(null);
493-
return this;
494-
}
495-
496417
/**
497418
* Sets the queue for managing live requests.
498419
*
@@ -505,21 +426,6 @@ public Builder liveRequestQueue(@Nullable LiveRequestQueue liveRequestQueue) {
505426
return this;
506427
}
507428

508-
/**
509-
* Sets the branch ID for the invocation.
510-
*
511-
* @param branch the branch ID for the invocation.
512-
* @return this builder instance for chaining.
513-
* @deprecated Use {@link #branch(String)} instead.
514-
*/
515-
// TODO: b/462140921 - Builders should not accept Optional parameters.
516-
@Deprecated(forRemoval = true)
517-
@CanIgnoreReturnValue
518-
public Builder branch(Optional<String> branch) {
519-
this.branch = branch.orElse(null);
520-
return this;
521-
}
522-
523429
/**
524430
* Sets the branch ID for the invocation.
525431
*
@@ -568,16 +474,6 @@ public Builder session(Session session) {
568474
return this;
569475
}
570476

571-
/**
572-
* @deprecated Use {@link #userContent(Content)} instead.
573-
*/
574-
@CanIgnoreReturnValue
575-
@Deprecated
576-
public Builder userContent(Optional<Content> userContent) {
577-
this.userContent = userContent.orElse(null);
578-
return this;
579-
}
580-
581477
/**
582478
* Sets the user content that triggered this invocation.
583479
*

core/src/test/java/com/google/adk/agents/InvocationContextTest.java

Lines changed: 3 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.google.genai.types.Content;
3232
import java.util.HashMap;
3333
import java.util.Map;
34-
import java.util.Optional;
3534
import java.util.concurrent.ConcurrentHashMap;
3635
import org.junit.Assert;
3736
import org.junit.Before;
@@ -607,45 +606,6 @@ public void testBranch() {
607606
assertThat(context.branch()).isEmpty();
608607
}
609608

610-
@Test
611-
// Testing deprecated methods.
612-
public void testDeprecatedCreateMethods() {
613-
InvocationContext context1 =
614-
InvocationContext.builder()
615-
.sessionService(mockSessionService)
616-
.artifactService(mockArtifactService)
617-
.invocationId(testInvocationId)
618-
.agent(mockAgent)
619-
.session(session)
620-
.userContent(Optional.ofNullable(userContent))
621-
.runConfig(runConfig)
622-
.build();
623-
624-
assertThat(context1.sessionService()).isEqualTo(mockSessionService);
625-
assertThat(context1.artifactService()).isEqualTo(mockArtifactService);
626-
assertThat(context1.invocationId()).isEqualTo(testInvocationId);
627-
assertThat(context1.agent()).isEqualTo(mockAgent);
628-
assertThat(context1.session()).isEqualTo(session);
629-
assertThat(context1.userContent()).hasValue(userContent);
630-
assertThat(context1.runConfig()).isEqualTo(runConfig);
631-
632-
InvocationContext context2 =
633-
InvocationContext.create(
634-
mockSessionService,
635-
mockArtifactService,
636-
mockAgent,
637-
session,
638-
liveRequestQueue,
639-
runConfig);
640-
641-
assertThat(context2.sessionService()).isEqualTo(mockSessionService);
642-
assertThat(context2.artifactService()).isEqualTo(mockArtifactService);
643-
assertThat(context2.agent()).isEqualTo(mockAgent);
644-
assertThat(context2.session()).isEqualTo(session);
645-
assertThat(context2.liveRequestQueue()).hasValue(liveRequestQueue);
646-
assertThat(context2.runConfig()).isEqualTo(runConfig);
647-
}
648-
649609
@Test
650610
public void testActiveStreamingTools() {
651611
InvocationContext context =
@@ -686,78 +646,16 @@ public void testBuilderOptionalParameters() {
686646
.artifactService(mockArtifactService)
687647
.agent(mockAgent)
688648
.session(session)
689-
.liveRequestQueue(Optional.of(liveRequestQueue))
690-
.branch(Optional.of("test-branch"))
691-
.userContent(Optional.of(userContent))
649+
.liveRequestQueue(liveRequestQueue)
650+
.branch("test-branch")
651+
.userContent(userContent)
692652
.build();
693653

694654
assertThat(context.liveRequestQueue()).hasValue(liveRequestQueue);
695655
assertThat(context.branch()).hasValue("test-branch");
696656
assertThat(context.userContent()).hasValue(userContent);
697657
}
698658

699-
@Test
700-
// Testing deprecated methods.
701-
public void testDeprecatedConstructor() {
702-
InvocationContext context =
703-
new InvocationContext(
704-
mockSessionService,
705-
mockArtifactService,
706-
mockMemoryService,
707-
pluginManager,
708-
Optional.of(liveRequestQueue),
709-
Optional.of("test-branch"),
710-
testInvocationId,
711-
mockAgent,
712-
session,
713-
Optional.of(userContent),
714-
runConfig,
715-
true);
716-
717-
assertThat(context.sessionService()).isEqualTo(mockSessionService);
718-
assertThat(context.artifactService()).isEqualTo(mockArtifactService);
719-
assertThat(context.memoryService()).isEqualTo(mockMemoryService);
720-
assertThat(context.pluginManager()).isEqualTo(pluginManager);
721-
assertThat(context.liveRequestQueue()).hasValue(liveRequestQueue);
722-
assertThat(context.branch()).hasValue("test-branch");
723-
assertThat(context.invocationId()).isEqualTo(testInvocationId);
724-
assertThat(context.agent()).isEqualTo(mockAgent);
725-
assertThat(context.session()).isEqualTo(session);
726-
assertThat(context.userContent()).hasValue(userContent);
727-
assertThat(context.runConfig()).isEqualTo(runConfig);
728-
assertThat(context.endInvocation()).isTrue();
729-
}
730-
731-
@Test
732-
// Testing deprecated methods.
733-
public void testDeprecatedConstructor_11params() {
734-
InvocationContext context =
735-
new InvocationContext(
736-
mockSessionService,
737-
mockArtifactService,
738-
mockMemoryService,
739-
Optional.of(liveRequestQueue),
740-
Optional.of("test-branch"),
741-
testInvocationId,
742-
mockAgent,
743-
session,
744-
Optional.of(userContent),
745-
runConfig,
746-
true);
747-
748-
assertThat(context.sessionService()).isEqualTo(mockSessionService);
749-
assertThat(context.artifactService()).isEqualTo(mockArtifactService);
750-
assertThat(context.memoryService()).isEqualTo(mockMemoryService);
751-
assertThat(context.liveRequestQueue()).hasValue(liveRequestQueue);
752-
assertThat(context.branch()).hasValue("test-branch");
753-
assertThat(context.invocationId()).isEqualTo(testInvocationId);
754-
assertThat(context.agent()).isEqualTo(mockAgent);
755-
assertThat(context.session()).isEqualTo(session);
756-
assertThat(context.userContent()).hasValue(userContent);
757-
assertThat(context.runConfig()).isEqualTo(runConfig);
758-
assertThat(context.endInvocation()).isTrue();
759-
}
760-
761659
@Test
762660
public void build_missingInvocationId_null_throwsException() {
763661
InvocationContext.Builder builder =

0 commit comments

Comments
 (0)