From d93bfd40e607d07c6f211377ccbae6dbb6a3c1cc Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Wed, 18 Mar 2026 07:48:52 -0700 Subject: [PATCH] fix: Using App conformant agent names PiperOrigin-RevId: 885590771 --- .../adk/agents/AgentWithMemoryTest.java | 4 +-- .../adk/telemetry/ContextPropagationTest.java | 12 ++++---- .../com/google/adk/testing/TestUtils.java | 2 +- .../com/google/adk/tools/AgentToolTest.java | 28 +++++++++---------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/core/src/test/java/com/google/adk/agents/AgentWithMemoryTest.java b/core/src/test/java/com/google/adk/agents/AgentWithMemoryTest.java index d5edfc876..361c5eb6b 100644 --- a/core/src/test/java/com/google/adk/agents/AgentWithMemoryTest.java +++ b/core/src/test/java/com/google/adk/agents/AgentWithMemoryTest.java @@ -41,7 +41,7 @@ public final class AgentWithMemoryTest { @Test public void agentRemembersUserNameWithMemoryTool() throws Exception { String userId = "test-user"; - String agentName = "test-agent"; + String agentName = "test_agent"; Part functionCall = Part.builder() @@ -101,7 +101,7 @@ public void agentRemembersUserNameWithMemoryTool() throws Exception { Session updatedSession = runner .sessionService() - .getSession("test-agent", userId, sessionId, Optional.empty()) + .getSession("test_agent", userId, sessionId, Optional.empty()) .blockingGet(); // Save the updated session to memory so we can bring it up on the next request. diff --git a/core/src/test/java/com/google/adk/telemetry/ContextPropagationTest.java b/core/src/test/java/com/google/adk/telemetry/ContextPropagationTest.java index e5795d61f..15785ebc8 100644 --- a/core/src/test/java/com/google/adk/telemetry/ContextPropagationTest.java +++ b/core/src/test/java/com/google/adk/telemetry/ContextPropagationTest.java @@ -659,13 +659,13 @@ public void baseAgentRunAsync_propagatesContext() throws InterruptedException { @Test public void runnerRunAsync_propagatesContext() throws InterruptedException { BaseAgent agent = new TestAgent(); - Runner runner = Runner.builder().agent(agent).appName("test-app").build(); + Runner runner = Runner.builder().agent(agent).appName("test_app").build(); Span parentSpan = tracer.spanBuilder("parent").startSpan(); try (Scope s = parentSpan.makeCurrent()) { Session session = runner .sessionService() - .createSession(new SessionKey("test-app", "test-user", "test-session")) + .createSession(new SessionKey("test_app", "test-user", "test-session")) .blockingGet(); Content newMessage = Content.fromParts(Part.fromText("hi")); RunConfig runConfig = RunConfig.builder().build(); @@ -689,13 +689,13 @@ public void runnerRunAsync_propagatesContext() throws InterruptedException { @Test public void runnerRunLive_propagatesContext() throws InterruptedException { BaseAgent agent = new TestAgent(); - Runner runner = Runner.builder().agent(agent).appName("test-app").build(); + Runner runner = Runner.builder().agent(agent).appName("test_app").build(); Span parentSpan = tracer.spanBuilder("parent").startSpan(); try (Scope s = parentSpan.makeCurrent()) { Session session = runner .sessionService() - .createSession("test-app", "test-user", (Map) null, "test-session") + .createSession("test_app", "test-user", (Map) null, "test-session") .blockingGet(); Content newMessage = Content.fromParts(Part.fromText("hi")); RunConfig runConfig = RunConfig.builder().build(); @@ -744,7 +744,9 @@ private SpanData findSpanByName(String name) { private InvocationContext buildInvocationContext() { Session session = - sessionService.createSession("test-app", "test-user", null, "test-session").blockingGet(); + sessionService + .createSession("test_app", "test-user", (Map) null, "test-session") + .blockingGet(); return InvocationContext.builder() .sessionService(sessionService) .session(session) diff --git a/core/src/test/java/com/google/adk/testing/TestUtils.java b/core/src/test/java/com/google/adk/testing/TestUtils.java index 70ae14bf1..daed8d2e4 100644 --- a/core/src/test/java/com/google/adk/testing/TestUtils.java +++ b/core/src/test/java/com/google/adk/testing/TestUtils.java @@ -61,7 +61,7 @@ public static InvocationContext createInvocationContext(BaseAgent agent, RunConf .artifactService(new InMemoryArtifactService()) .invocationId("invocationId") .agent(agent) - .session(sessionService.createSession("test-app", "test-user").blockingGet()) + .session(sessionService.createSession("test_app", "test-user").blockingGet()) .userContent(Content.fromParts(Part.fromText("user content"))) .runConfig(runConfig) .build(); diff --git a/core/src/test/java/com/google/adk/tools/AgentToolTest.java b/core/src/test/java/com/google/adk/tools/AgentToolTest.java index 3a5390027..0f168c5df 100644 --- a/core/src/test/java/com/google/adk/tools/AgentToolTest.java +++ b/core/src/test/java/com/google/adk/tools/AgentToolTest.java @@ -143,7 +143,7 @@ public void declaration_withInputSchema_returnsDeclarationWithSchema() { AgentTool agentTool = AgentTool.create( createTestAgentBuilder(createTestLlm(LlmResponse.builder().build())) - .name("agent name") + .name("agent_name") .description("agent description") .inputSchema(inputSchema) .build()); @@ -153,7 +153,7 @@ public void declaration_withInputSchema_returnsDeclarationWithSchema() { assertThat(declaration) .isEqualTo( FunctionDeclaration.builder() - .name("agent name") + .name("agent_name") .description("agent description") .parameters(inputSchema) .build()); @@ -164,7 +164,7 @@ public void declaration_withoutInputSchema_returnsDeclarationWithRequestParamete AgentTool agentTool = AgentTool.create( createTestAgentBuilder(createTestLlm(LlmResponse.builder().build())) - .name("agent name") + .name("agent_name") .description("agent description") .build()); @@ -173,7 +173,7 @@ public void declaration_withoutInputSchema_returnsDeclarationWithRequestParamete assertThat(declaration) .isEqualTo( FunctionDeclaration.builder() - .name("agent name") + .name("agent_name") .description("agent description") .parameters( Schema.builder() @@ -200,7 +200,7 @@ public void call_withInputSchema_invalidInput_throwsException() throws Exception .build(); LlmAgent testAgent = createTestAgentBuilder(createTestLlm(LlmResponse.builder().build())) - .name("agent name") + .name("agent_name") .description("agent description") .inputSchema(inputSchema) .build(); @@ -256,7 +256,7 @@ public void call_withOutputSchema_invalidOutput_throwsException() throws Excepti "{\"is_valid\": \"invalid type\", " + "\"message\": \"success\"}"))) .build())) - .name("agent name") + .name("agent_name") .description("agent description") .outputSchema(outputSchema) .build(); @@ -301,7 +301,7 @@ public void call_withInputAndOutputSchema_successful() throws Exception { Part.fromText( "{\"is_valid\": true, " + "\"message\": \"success\"}"))) .build())) - .name("agent name") + .name("agent_name") .description("agent description") .inputSchema(inputSchema) .outputSchema(outputSchema) @@ -332,7 +332,7 @@ public void call_withoutSchema_returnsConcatenatedTextFromLastEvent() throws Exc Part.fromText("First text part. "), Part.fromText("Second text part."))) .build()))) - .name("agent name") + .name("agent_name") .description("agent description") .build(); AgentTool agentTool = AgentTool.create(testAgent); @@ -358,7 +358,7 @@ public void call_withThoughts_returnsOnlyNonThoughtText() throws Exception { .build()) .build()); LlmAgent testAgent = - createTestAgentBuilder(testLlm).name("agent name").description("agent description").build(); + createTestAgentBuilder(testLlm).name("agent_name").description("agent description").build(); AgentTool agentTool = AgentTool.create(testAgent); ToolContext toolContext = createToolContext(testAgent); @@ -373,7 +373,7 @@ public void call_emptyModelResponse_returnsEmptyMap() throws Exception { LlmAgent testAgent = createTestAgentBuilder( createTestLlm(LlmResponse.builder().content(Content.builder().build()).build())) - .name("agent name") + .name("agent_name") .description("agent description") .build(); AgentTool agentTool = AgentTool.create(testAgent); @@ -394,7 +394,7 @@ public void call_withInputSchema_argsAreSentToAgent() throws Exception { .build()); LlmAgent testAgent = createTestAgentBuilder(testLlm) - .name("agent name") + .name("agent_name") .description("agent description") .inputSchema( Schema.builder() @@ -422,7 +422,7 @@ public void call_withoutInputSchema_requestIsSentToAgent() throws Exception { .content(Content.fromParts(Part.fromText("test response"))) .build()); LlmAgent testAgent = - createTestAgentBuilder(testLlm).name("agent name").description("agent description").build(); + createTestAgentBuilder(testLlm).name("agent_name").description("agent description").build(); AgentTool agentTool = AgentTool.create(testAgent); ToolContext toolContext = createToolContext(testAgent); @@ -447,7 +447,7 @@ public void call_withStateDeltaInResponse_propagatesStateDelta() throws Exceptio .build()); LlmAgent testAgent = createTestAgentBuilder(testLlm) - .name("agent name") + .name("agent_name") .description("agent description") .afterAgentCallback(afterAgentCallback) .build(); @@ -477,7 +477,7 @@ public void call_withSkipSummarizationAndStateDelta_propagatesStateAndSetsSkipSu .build()); LlmAgent testAgent = createTestAgentBuilder(testLlm) - .name("agent name") + .name("agent_name") .description("agent description") .afterAgentCallback(afterAgentCallback) .build();