Agent Development Kit (ADK) for Java

repository·main·Indexed 23 days ago

https://github.com/google/adk-java

A code-first toolkit for building, evaluating, and deploying AI agents integrated with Google Cloud. It features an A2A (Agent-to-Agent) runtime and Spring Boot webservice for JSON-RPC communication, a Firestore session service for scalable user session management, and integrations with LangChain4j for wrapping ChatModels and StreamingChatModels. The kit also includes pluggable planner implementations for orchestrating sub-agents via PlannerAgent.

Tokens
33.3K
Snippets
80
Records
139
Agent score
82%

What's inside google-adk-java

  1. Overview of the Agent Development Kit (ADK) for Java

    main
    The Agent Development Kit (ADK) for Java is a core library designed to facilitate the development, evaluation, and deployment of AI agents. It provides a familiar interface for developers transitioning from the Python ADK and includes features for building agentic workflows, utilizing a development UI, and evaluating agent performance. It also supports A2A (Agent-to-Agent) and ADK integration.
  2. Overview of ADK development utilities

    main
    The ADK (Agent Development Kit) for Java provides development utilities to assist in building and testing agents. One primary utility is a Spring REST server designed to host an agent, allowing for interaction and testing via standard HTTP requests.
  3. Overview of Agent Development Kit (ADK) for Java

    main

    The Agent Development Kit (ADK) for Java is an open-source, code-first toolkit designed for building, evaluating, and deploying sophisticated AI agents. It is optimized for developers who need fine-grained control and tight integration with Google Cloud services.

    Key capabilities include:

    • Code-First Development: Define logic, tools, and orchestration directly in Java.
    • Rich Tool Ecosystem: Use pre-built tools, custom functions, or OpenAPI specs.
    • Modular Multi-Agent Systems: Compose specialized agents into hierarchical structures.
    • Development UI: A built-in interface to test, evaluate, and debug agents.
    • A2A Integration: Support for remote agent-to-agent communication via the A2A protocol.
  4. Overview of ADK Planner strategies

    main

    The google-adk-planners module provides several strategies for orchestrating sub-agent execution:

    PlannerPackageExecution ModelLLM RequiredPrimary Use Case
    SequentialPlannerplannerOne at a time, in orderNoFixed pipelines, ETL steps
    ParallelPlannerplannerAll at onceNoIndependent fan-out tasks
    LoopPlannerplannerCyclic, repeatingNoReview/revision cycles
    SupervisorPlannerplannerLLM selects next agent(s)YesOpen-ended task delegation
    GoalOrientedPlannerplanner.goapDependency-resolved groupsNoWorkflows with input/output contracts
    P2PPlannerplanner.p2pReactive dynamic activationNoCollaborative refinement loops
  5. Understand the A2A Basic Sample implementation

    main

    The A2A Basic Sample consists of several key components that illustrate the integration between local tools and remote agents:

    • A2AAgent.java: This file builds a root agent. The root agent is configured with a local dice-rolling tool and a RemoteA2AAgent which acts as a sub-agent for remote prime-checking.
    • A2AAgentRun.java: A minimal driver class used to execute a single SendMessage turn, demonstrating how the remote call is triggered and handled.
    • pom.xml: The standalone Maven configuration required to build and run this specific sample.
  6. Use the Peer-to-Peer (P2P) Planner for iterative refinement

    main

    The P2P planner (com.google.adk.planner.p2p) is designed for collaborative, iterative workflows where agents react to changes in session state. Unlike GOAP, it does not compute a plan upfront. Instead, agents activate dynamically when their required inputKeys appear in the state.

    Key behaviors:

    • Parallel activation: Multiple agents can run simultaneously if their dependencies are met.
    • Iterative refinement: If an agent produces a new or changed output (detected via Objects.equals()), downstream agents that depend on that key are re-activated.
    • Value-change detection: To prevent infinite loops or wasted compute, agents only re-execute if the output value actually changes.

    Use this planner when you need a 'research collaboration' pattern where a critic's feedback triggers a re-run of a hypothesis agent.

    List<AgentMetadata> metadata = List.of(
        new AgentMetadata("literature",  ImmutableList.of("topic"), "researchFindings"),
        new AgentMetadata("hypothesis",  ImmutableList.of("topic", "researchFindings"), "hypothesis"),
        new AgentMetadata("critic",      ImmutableList.of("topic", "hypothesis"), "critique"),
        new AgentMetadata("scorer",      ImmutableList.of("topic", "hypothesis", "critique"), "score")
    );
    
    // Exit when score is high enough
    P2PPlanner planner = new P2PPlanner(metadata, 20,
        (state, count) -> {
            Object score = state.get("score");
            return score instanceof Number && ((Number) score).doubleValue() >= 0.85;
        });
    
    PlannerAgent agent = PlannerAgent.builder()
        .name("research")
        .subAgents(literatureAgent, hypothesisAgent, criticAgent, scorerAgent)
        .planner(planner)
        .build();
  7. Use Goal-Oriented Action Planning (GOAP) for agent orchestration

    main

    The GOAP subsystem (com.google.adk.planner.goap) resolves agent execution order by analyzing input/output dependencies. Instead of manual sequencing, you define what state keys each agent reads (inputKeys) and writes (outputKey). The planner then computes a dependency graph to determine which agents can run in parallel and in what order to reach a target goal.

    To use GOAP, you must define AgentMetadata for each sub-agent and then initialize a GoalOrientedPlanner with your target goal and the metadata list.

    List<AgentMetadata> metadata = List.of(
        new AgentMetadata("personExtractor", ImmutableList.of("prompt"), "person"),
        new AgentMetadata("signExtractor",   ImmutableList.of("prompt"), "sign"),
        new AgentMetadata("horoscopeGen",    ImmutableList.of("person", "sign"), "horoscope"),
        new AgentMetadata("writer",          ImmutableList.of("person", "horoscope"), "writeup")
    );
    
    // Goal is to produce "writeup"
    GoalOrientedPlanner planner = new GoalOrientedPlanner("writeup", metadata);
    
    PlannerAgent agent = PlannerAgent.builder()
        .name("horoscope")
        .subAgents(personExtractor, signExtractor, horoscopeGen, writer)
        .planner(planner)
        .build();
  8. Understand the compatibility policy for contributions

    main

    Code located in the contrib/ directory does not have backwards API compatibility guarantees. This applies even across minor (patch) releases.

    Maintainers may merge changes to both implementations and interfaces without concern for API stability. This policy is intended to allow contributors to raise PRs and incrementally improve code without the overhead of maintaining strict API stability.

  9. Understand the Trace Hierarchy for Nested Agents

    main

    ADK produces a hierarchical trace structure. A standard interaction follows this pattern:

    invocation
    └── invoke_agent my_agent
        ├── call_llm
        │   ├── tool_call [search_flights]
        │   └── tool_response [search_flights]
        └── call_llm

    When using Nested Agents (where one agent uses the transfer_to_agent tool to call another), the sub-agent's invocation appears as a child of the parent agent's invocation:

    invocation
    └── invoke_agent AgentA
        ├── call_llm
        │   ├── tool_call [transfer_to_agent]
        │   └── tool_response [transfer_to_agent]
        └── invoke_agent AgentB
            ├── call_llm
            └── ...
  10. How the ADK Stale Issue Auditor decides to act

    main

    The agent uses a Unified History Trace (reconstructed via GraphQL) to classify the last actor of an issue as an author, maintainer, or other_user. It then follows this decision logic:

    Last actorVerdict & Action
    Author / other userACTIVE: Remove stale label. If the author silently edited the description, post a one-time maintainer alert.
    Maintainer (asked question)STALE: If days_since_activity > threshold, comment + add stale label (and request clarification if missing).
    Issue already staleCLOSE: If days_since_stale_label > close threshold, comment + close as not planned.
    Maintainer (status update)ACTIVE: No action.

    Thresholds default to 7 days for both stale and close actions but are configurable via environment variables.