Class SpamDetectionAgent

java.lang.Object
com.example.adkspam.SpamDetectionAgent

public final class SpamDetectionAgent extends Object
ADK Issue Monitoring (Spam Detection) Agent for google/adk-java.

This is the Java port of the Python adk_issue_monitoring_agent/agent.py. The agent uses Gemini to audit issue threads (the original description plus non-maintainer comments) for SEO spam, unsolicited promotion, and other objectionable content. When spam is detected it applies a spam label and posts a single alert comment for human maintainers — nothing is ever deleted, the agent only flags.

Following the Python design, the model is given exactly one tool, flagIssueAsSpam(int, String). Cost-saving pre-filtering (skipping maintainer/bot authors, stripping code blocks, truncating, and idempotency) happens in SpamDetectionAgentRun before the model is ever invoked, so safe threads cost zero tokens.

All GitHub access goes through the shared GitHubTools (backed by the org.kohsuke:github-api client) that this sample reuses with the ADK Triaging Agent and the ADK Docs Release Analyzer. The tool is exposed as a FunctionTool and uses snake_case via Annotations.Schema so the function declaration seen by the model matches the Python implementation. It returns an ImmutableMap envelope — {"status": "success", ...} on success, {"status": "error", "message": "..."} on failure — matching the Python contract.

  • Field Details

    • ROOT_AGENT

      public static final LlmAgent ROOT_AGENT
      Exposed for adk web / dev-UI agent loaders that look up a public static final BaseAgent ROOT_AGENT field on the class.
  • Method Details

    • rootAgent

      public static LlmAgent rootAgent()
      Builds the LlmAgent. Safe to call at class-init time: it only reads Settings accessors that never throw (no GITHUB_TOKEN is required to construct the agent), so the ROOT_AGENT field and adk web agent loaders work without a token configured.
    • flagIssueAsSpam

      public static com.google.common.collect.ImmutableMap<String,Object> flagIssueAsSpam(int itemNumber, String detectionReason)
      Flags an issue as spam by applying the configured spam label and posting one alert comment for maintainers. Mirrors flag_issue_as_spam in the Python sample, including the idempotency checks that avoid duplicate labels/comments on re-runs.