Class SpamDetectionAgent
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final LlmAgentExposed foradk web/ dev-UI agent loaders that look up apublic static final BaseAgent ROOT_AGENTfield on the class. -
Method Summary
Modifier and TypeMethodDescriptionflagIssueAsSpam(int itemNumber, String detectionReason) Flags an issue as spam by applying the configured spam label and posting one alert comment for maintainers.static LlmAgentBuilds theLlmAgent.
-
Field Details
-
ROOT_AGENT
Exposed foradk web/ dev-UI agent loaders that look up apublic static final BaseAgent ROOT_AGENTfield on the class.
-
-
Method Details
-
rootAgent
Builds theLlmAgent. Safe to call at class-init time: it only readsSettingsaccessors that never throw (noGITHUB_TOKENis required to construct the agent), so theROOT_AGENTfield andadk webagent 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. Mirrorsflag_issue_as_spamin the Python sample, including the idempotency checks that avoid duplicate labels/comments on re-runs.
-