Skip to content

Commit f3eb936

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: Using App conformant agent names
PiperOrigin-RevId: 886764077
1 parent 4ab1a51 commit f3eb936

4 files changed

Lines changed: 27 additions & 28 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public final class AgentWithMemoryTest {
4141
@Test
4242
public void agentRemembersUserNameWithMemoryTool() throws Exception {
4343
String userId = "test-user";
44-
String agentName = "test-agent";
44+
String agentName = "test_agent";
4545

4646
Part functionCall =
4747
Part.builder()
@@ -101,7 +101,7 @@ public void agentRemembersUserNameWithMemoryTool() throws Exception {
101101
Session updatedSession =
102102
runner
103103
.sessionService()
104-
.getSession("test-agent", userId, sessionId, Optional.empty())
104+
.getSession("test_agent", userId, sessionId, Optional.empty())
105105
.blockingGet();
106106

107107
// Save the updated session to memory so we can bring it up on the next request.

core/src/test/java/com/google/adk/telemetry/ContextPropagationTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.google.adk.runner.Runner;
3333
import com.google.adk.sessions.InMemorySessionService;
3434
import com.google.adk.sessions.Session;
35-
import com.google.adk.sessions.SessionKey;
3635
import com.google.adk.testing.TestLlm;
3736
import com.google.adk.testing.TestUtils;
3837
import com.google.adk.tools.BaseTool;
@@ -653,13 +652,13 @@ public void runnerRunAsync_propagatesContext() throws InterruptedException {
653652
@Test
654653
public void runnerRunLive_propagatesContext() throws InterruptedException {
655654
BaseAgent agent = new TestAgent();
656-
Runner runner = Runner.builder().agent(agent).appName("test-app").build();
655+
Runner runner =
656+
Runner.builder().agent(agent).appName("test_app").sessionService(sessionService).build();
657657
Span parentSpan = tracer.spanBuilder("parent").startSpan();
658658
try (Scope s = parentSpan.makeCurrent()) {
659659
Session session =
660-
runner
661-
.sessionService()
662-
.createSession("test-app", "test-user", (Map<String, Object>) null, "test-session")
660+
sessionService
661+
.createSession("test_app", "test-user", (Map<String, Object>) null, "test-session")
663662
.blockingGet();
664663
Content newMessage = Content.fromParts(Part.fromText("hi"));
665664
RunConfig runConfig = RunConfig.builder().build();
@@ -800,12 +799,10 @@ public void testNestedAgentTraceHierarchy() throws InterruptedException {
800799
}
801800

802801
private void runAgent(BaseAgent agent) throws InterruptedException {
803-
Runner runner = Runner.builder().agent(agent).appName("test-app").build();
802+
Runner runner =
803+
Runner.builder().agent(agent).appName("test_app").sessionService(sessionService).build();
804804
Session session =
805-
runner
806-
.sessionService()
807-
.createSession(new SessionKey("test-app", "test-user", "test-session"))
808-
.blockingGet();
805+
sessionService.createSession("test_app", "test-user", null, "test-session").blockingGet();
809806
Content newMessage = Content.fromParts(Part.fromText("hi"));
810807
RunConfig runConfig = RunConfig.builder().build();
811808
runner
@@ -871,7 +868,9 @@ private SpanData findSpanByName(String name) {
871868

872869
private InvocationContext buildInvocationContext() {
873870
Session session =
874-
sessionService.createSession("test-app", "test-user", null, "test-session").blockingGet();
871+
sessionService
872+
.createSession("test_app", "test-user", (Map<String, Object>) null, "test-session")
873+
.blockingGet();
875874
return InvocationContext.builder()
876875
.sessionService(sessionService)
877876
.session(session)

core/src/test/java/com/google/adk/testing/TestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static InvocationContext createInvocationContext(BaseAgent agent, RunConf
6161
.artifactService(new InMemoryArtifactService())
6262
.invocationId("invocationId")
6363
.agent(agent)
64-
.session(sessionService.createSession("test-app", "test-user").blockingGet())
64+
.session(sessionService.createSession("test_app", "test-user").blockingGet())
6565
.userContent(Content.fromParts(Part.fromText("user content")))
6666
.runConfig(runConfig)
6767
.build();

core/src/test/java/com/google/adk/tools/AgentToolTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void declaration_withInputSchema_returnsDeclarationWithSchema() {
143143
AgentTool agentTool =
144144
AgentTool.create(
145145
createTestAgentBuilder(createTestLlm(LlmResponse.builder().build()))
146-
.name("agent name")
146+
.name("agent_name")
147147
.description("agent description")
148148
.inputSchema(inputSchema)
149149
.build());
@@ -153,7 +153,7 @@ public void declaration_withInputSchema_returnsDeclarationWithSchema() {
153153
assertThat(declaration)
154154
.isEqualTo(
155155
FunctionDeclaration.builder()
156-
.name("agent name")
156+
.name("agent_name")
157157
.description("agent description")
158158
.parameters(inputSchema)
159159
.build());
@@ -164,7 +164,7 @@ public void declaration_withoutInputSchema_returnsDeclarationWithRequestParamete
164164
AgentTool agentTool =
165165
AgentTool.create(
166166
createTestAgentBuilder(createTestLlm(LlmResponse.builder().build()))
167-
.name("agent name")
167+
.name("agent_name")
168168
.description("agent description")
169169
.build());
170170

@@ -173,7 +173,7 @@ public void declaration_withoutInputSchema_returnsDeclarationWithRequestParamete
173173
assertThat(declaration)
174174
.isEqualTo(
175175
FunctionDeclaration.builder()
176-
.name("agent name")
176+
.name("agent_name")
177177
.description("agent description")
178178
.parameters(
179179
Schema.builder()
@@ -200,7 +200,7 @@ public void call_withInputSchema_invalidInput_throwsException() throws Exception
200200
.build();
201201
LlmAgent testAgent =
202202
createTestAgentBuilder(createTestLlm(LlmResponse.builder().build()))
203-
.name("agent name")
203+
.name("agent_name")
204204
.description("agent description")
205205
.inputSchema(inputSchema)
206206
.build();
@@ -256,7 +256,7 @@ public void call_withOutputSchema_invalidOutput_throwsException() throws Excepti
256256
"{\"is_valid\": \"invalid type\", "
257257
+ "\"message\": \"success\"}")))
258258
.build()))
259-
.name("agent name")
259+
.name("agent_name")
260260
.description("agent description")
261261
.outputSchema(outputSchema)
262262
.build();
@@ -301,7 +301,7 @@ public void call_withInputAndOutputSchema_successful() throws Exception {
301301
Part.fromText(
302302
"{\"is_valid\": true, " + "\"message\": \"success\"}")))
303303
.build()))
304-
.name("agent name")
304+
.name("agent_name")
305305
.description("agent description")
306306
.inputSchema(inputSchema)
307307
.outputSchema(outputSchema)
@@ -332,7 +332,7 @@ public void call_withoutSchema_returnsConcatenatedTextFromLastEvent() throws Exc
332332
Part.fromText("First text part. "),
333333
Part.fromText("Second text part.")))
334334
.build())))
335-
.name("agent name")
335+
.name("agent_name")
336336
.description("agent description")
337337
.build();
338338
AgentTool agentTool = AgentTool.create(testAgent);
@@ -358,7 +358,7 @@ public void call_withThoughts_returnsOnlyNonThoughtText() throws Exception {
358358
.build())
359359
.build());
360360
LlmAgent testAgent =
361-
createTestAgentBuilder(testLlm).name("agent name").description("agent description").build();
361+
createTestAgentBuilder(testLlm).name("agent_name").description("agent description").build();
362362
AgentTool agentTool = AgentTool.create(testAgent);
363363
ToolContext toolContext = createToolContext(testAgent);
364364

@@ -373,7 +373,7 @@ public void call_emptyModelResponse_returnsEmptyMap() throws Exception {
373373
LlmAgent testAgent =
374374
createTestAgentBuilder(
375375
createTestLlm(LlmResponse.builder().content(Content.builder().build()).build()))
376-
.name("agent name")
376+
.name("agent_name")
377377
.description("agent description")
378378
.build();
379379
AgentTool agentTool = AgentTool.create(testAgent);
@@ -394,7 +394,7 @@ public void call_withInputSchema_argsAreSentToAgent() throws Exception {
394394
.build());
395395
LlmAgent testAgent =
396396
createTestAgentBuilder(testLlm)
397-
.name("agent name")
397+
.name("agent_name")
398398
.description("agent description")
399399
.inputSchema(
400400
Schema.builder()
@@ -422,7 +422,7 @@ public void call_withoutInputSchema_requestIsSentToAgent() throws Exception {
422422
.content(Content.fromParts(Part.fromText("test response")))
423423
.build());
424424
LlmAgent testAgent =
425-
createTestAgentBuilder(testLlm).name("agent name").description("agent description").build();
425+
createTestAgentBuilder(testLlm).name("agent_name").description("agent description").build();
426426
AgentTool agentTool = AgentTool.create(testAgent);
427427
ToolContext toolContext = createToolContext(testAgent);
428428

@@ -447,7 +447,7 @@ public void call_withStateDeltaInResponse_propagatesStateDelta() throws Exceptio
447447
.build());
448448
LlmAgent testAgent =
449449
createTestAgentBuilder(testLlm)
450-
.name("agent name")
450+
.name("agent_name")
451451
.description("agent description")
452452
.afterAgentCallback(afterAgentCallback)
453453
.build();
@@ -477,7 +477,7 @@ public void call_withSkipSummarizationAndStateDelta_propagatesStateAndSetsSkipSu
477477
.build());
478478
LlmAgent testAgent =
479479
createTestAgentBuilder(testLlm)
480-
.name("agent name")
480+
.name("agent_name")
481481
.description("agent description")
482482
.afterAgentCallback(afterAgentCallback)
483483
.build();

0 commit comments

Comments
 (0)