Created
May 21, 2025 15:49
-
-
Save glaforge/cec3ed7ff77d3581ec3428b8d73c9829 to your computer and use it in GitHub Desktop.
A science teacher agent written in Java, using ADK (Agent Development Kit)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package agents; | |
import static java.nio.charset.StandardCharsets.UTF_8; | |
import java.util.Scanner; | |
import com.google.adk.agents.BaseAgent; | |
import com.google.adk.agents.LlmAgent; | |
import com.google.adk.events.Event; | |
import com.google.adk.runner.InMemoryRunner; | |
import com.google.adk.sessions.Session; | |
import com.google.genai.types.Content; | |
import com.google.genai.types.Part; | |
import io.reactivex.rxjava3.core.Flowable; | |
/** Science teacher agent. */ | |
public class ScienceTeacherAgent { | |
public static BaseAgent ROOT_AGENT = initAgent(); | |
public static BaseAgent initAgent() { | |
return LlmAgent.builder() | |
.name("science-app") | |
.description("Science teacher agent") | |
.model("gemini-2.0-flash") | |
.instruction(""" | |
You are a helpful science teacher that explains | |
science concepts to kids and teenagers. | |
""") | |
.build(); | |
} | |
public static void main(String[] args) { | |
InMemoryRunner runner = new InMemoryRunner(ROOT_AGENT); | |
Session session = runner | |
.sessionService() | |
.createSession(runner.appName(), "student") | |
.blockingGet(); | |
try (Scanner scanner = new Scanner(System.in, UTF_8)) { | |
while (true) { | |
System.out.print("\nYou > "); | |
String userInput = scanner.nextLine(); | |
if ("quit".equalsIgnoreCase(userInput)) { | |
break; | |
} | |
Content userMsg = Content.fromParts(Part.fromText(userInput)); | |
Flowable<Event> events = | |
runner.runAsync(session.userId(), session.id(), userMsg); | |
System.out.print("\nAgent > "); | |
events.blockingForEach(event -> { | |
System.out.println(event.stringifyContent()); | |
}); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment