Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions contrib/multi-agent-patterns/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Compiled class file
*.class
*.classpath
*.project
*.settings
*.factorypath
target/

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
94 changes: 94 additions & 0 deletions contrib/multi-agent-patterns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Multi-Agent Patterns

This repository demonstrates various multi-agent patterns using the ADK (Agent Development Kit) framework. It showcases how multiple AI agents can collaborate to perform complex tasks across different domains, including code generation, report writing, and travel planning.

## Overview

The project implements several key multi-agent patterns:

- **Sequential Pipeline**: Agents execute in a linear sequence, passing outputs from one to the next.
- **Coordinator/Dispatcher Pattern**: A central agent routes tasks to specialized sub-agents based on the request type.
- **Iterative Refinement Loop**: An agent iteratively improves content based on feedback until a satisfactory result is achieved.
- **Generator and Critic**: A generator creates initial content, and a critic reviews and provides feedback for improvement.
- **Hierarchical Decomposition (Russian Doll)**: Agents are organized in nested layers, with higher-level agents delegating to lower-level specialized agents.
- **Composite Patterns (Mix-and-Match)**: Combines sequential and parallel execution modes for flexible, efficient workflows.

## System Architecture

All patterns are hosted within a unified system accessible through a single web interface.

```text
[ Web Browser / UI ]
[ MultiAgentsSystem ] ◄── Entry Point
┌─────────┴─────────┐
▼ ▼
[ Dropdown ] ───► [ Select Pattern ] ───► [ Run Workflow ]
```

## Projects

The repository includes three main projects, each illustrating different patterns:

### 1. Code Workflow (`src/main/java/com/google/adk/agents/code/`)
Demonstrates Sequential Pipeline, Coordinator/Dispatcher, Iterative Refinement Loop, and Generator and Critic patterns for code generation, conversion, and refinement.

### 2. Report Writer (`src/main/java/com/google/adk/agents/report/`)
Showcases Hierarchical Decomposition pattern for generating comprehensive reports through nested agent coordination.

### 3. Trip Advisor (`src/main/java/com/google/adk/agents/traveler/`)
Illustrates Composite Patterns with a mix of sequential and parallel agents for personalized travel itinerary planning.

## Prerequisites

- Java 17+
- Maven 3+
- **GEMINI API Key**: All agents require a valid Gemini API key for LLM operations.
Ensure it's configured in your environment.

## Running the Project

To run the multi-agent system:

```bash
cd contrib/multi-agent-patterns
mvn compile exec:java -Dexec.mainClass=com.google.adk.agents.MultiAgentsSystem
```

The application starts a web server where you can interact with the respective agents.

## Project Structure

```
multiagent-patterns/
├── pom.xml
├── src/main/java/com/google/adk/agents/
│ ├── MultiAgentsSystem.java # Unified entry point for all agents
│ ├── code/ # Code workflow logic
│ │ ├── CodeRootAgent.java
│ │ └── ...
│ ├── report/ # Report writer logic
│ │ ├── ReportRootAgent.java
│ │ └── ...
│ └── traveler/ # Trip Advisor logic
│ ├── TravelerRootAgent.java
│ └── ...
└── src/main/resources/agent-configs/
├── code/ # Code agent configs
├── report/ # Report agent configs
└── traveler/ # TripAdvisor agent configs
```

## Dependencies

- ADK Core
- ADK Dev (for web UI)
- Jackson (for YAML/JSON handling)
- Jakarta Inject
- Apache Commons Lang

## Reference

For more information on multi-agent patterns in ADK, see:
[Developer’s guide to multi-agent patterns in ADK](https://developers.googleblog.com/developers-guide-to-multi-agent-patterns-in-adk/)
66 changes: 66 additions & 0 deletions contrib/multi-agent-patterns/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.google.adk</groupId>
<artifactId>google-adk-parent</artifactId>
<version>1.1.1-SNAPSHOT</version><!-- {x-version-update:google-adk:current} -->
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>multi-agent-patterns</artifactId>
<name>Agent Development Kit - Multi-Agent Patterns</name>
<description>Multi-Agent Patterns Examples</description>
<properties>
<jackson.version>2.17.0</jackson.version>
<jakarta.inject.version>2.0.1</jakarta.inject.version>
<apache.commons.lang3.version>3.20.0</apache.commons.lang3.version>
</properties>
<dependencies>
<!-- The ADK core dependency -->
<dependency>
<groupId>com.google.adk</groupId>
<artifactId>google-adk</artifactId>
<version>${project.version}</version>
</dependency>
<!-- The ADK dev web UI to debug your agent -->
<dependency>
<groupId>com.google.adk</groupId>
<artifactId>google-adk-dev</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<!-- Source: https://mvnrepository.com/artifact/jakarta.inject/jakarta.inject-api -->
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<!--<version>${jakarta.inject.version}</version> -->
<scope>compile</scope>
</dependency>
<!-- Source: https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<!--<version>${apache.commons.lang3.version}</version>-->
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<!--<version>${jackson.version}</version> -->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<!--<version>${jackson.version}</version> -->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-guava</artifactId>
<!--<version>${jackson.version}</version>-->
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.google.adk.agents;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

// mvn compile exec:java -Dexec.mainClass=com.google.adk.agents.MultiAgentsSystem

@SpringBootApplication
public class MultiAgentsSystem {

public static void main(String[] agrs) {
SpringApplication.run(MultiAgentsSystem.class, agrs);
}
}
Loading