|
1 | | -# Code Translator Green Agent (Evaluator) |
| 1 | +# Code Translator Green Agent (Judge) |
2 | 2 |
|
3 | | -This repository contains the **Green Agent** for the Code Translator system. Built with the [Google Agent Development Kit (ADK)](https://google.github.io/adk-docs/), this agent acts as the evaluator and orchestrator for code translation scenarios. |
| 3 | +This repository contains the implementation of the **Green Agent**, a judge agent designed for the Code Translator competition. Its primary role is to evaluate code translations performed by other agents (specifically the **Purple Agent**). |
4 | 4 |
|
5 | 5 | ## Overview |
6 | 6 |
|
7 | | -The Green Agent is responsible for: |
8 | | -1. **Orchestrating** the interaction between participant agents (Purple Agents). |
9 | | -2. **Evaluating** the quality of code translations provided by participants. |
10 | | -3. **Scoring** the submissions based on specific criteria. |
| 7 | +The Green Agent acts as an orchestrator and evaluator. When it receives a request to evaluate a code translation task: |
| 8 | +1. **Orchestration**: It requests the **Purple Agent** (Participant) to translate a given snippet of code from a source language to a target language. |
| 9 | +2. **Evaluation**: Upon receiving the translation, it uses **Google GenAI (Gemini)** to act as a judge. The judge evaluates the translation based on executing correctness, style, conciseness, and relevance. |
| 10 | +3. **Reporting**: It returns a structured evaluation containing scores, reasoning, and a winner determination. |
11 | 11 |
|
12 | | -### Evaluation Criteria |
13 | | -The agent uses `gemini-2.5-flash` to judge translations based on: |
14 | | -* **Execution Correctness**: The code must run without errors. |
15 | | -* **Style & Documentation**: Adherence to the target language's style guides and proper commenting. |
16 | | -* **Conciseness**: Efficient code without unnecessary boilerplate. |
17 | | -* **Relevance**: Logical and structural equivalence to the original code. |
| 12 | +## Repository Structure |
18 | 13 |
|
19 | | -## Architecture |
| 14 | +- **`src/`**: Source code for the agent. |
| 15 | + - **`agent.py`**: Contains `TranslationGreenAgent`. This is the core logic that handles the evaluation workflow: validating requests, communicating with the participant agent, and invoking the Gemini model for judging. |
| 16 | + - **`server.py`**: The entry point for the application. It initializes the `TranslationGreenAgent`, wraps it in a `GreenExecutor`, and sets up the **A2A (Agent-to-Agent)** Starlette server. |
| 17 | + - **`common.py`**: Defines shared data structures and Pydantic models (e.g., `EvalRequest`, `TranslatorEval`) and the Agent Card configuration. |
| 18 | + - **`executor.py`**: Handles the execution context for the agent, providing the sandbox or environment for running the agent logic. |
| 19 | + - **`tool_provider.py`**: Provides utilities for the agent to interact with external services or other agents (e.g., `talk_to_agent` implementation). |
| 20 | + - **`client.py`**: Client-side utilities or helpers for interacting with the agent. |
| 21 | +- **`tests/`**: Test suite. |
| 22 | + - **`test_agent.py`**: Contains integration tests and A2A conformance tests to ensure the agent behaves correctly, validates schemas, and adheres to the protocol. |
| 23 | + - **`conftest.py`**: Pytest configuration and fixtures. |
| 24 | +- **`Dockerfile`**: Configuration to containerize the application for deployment. |
| 25 | +- **`pyproject.toml`**: Project configuration and dependencies. |
20 | 26 |
|
21 | | -* **Framework**: Google ADK (`google-adk[a2a]`) |
22 | | -* **Model**: Gemini 2.5 Flash |
23 | | -* **Communication**: Agent-to-Agent (A2A) Protocol |
24 | | -* **Server**: Uvicorn + FastAPI (exposed via ADK) |
| 27 | +## Setup & Setup |
25 | 28 |
|
26 | | -## Prerequisites |
| 29 | +### Prerequisites |
27 | 30 |
|
28 | | -* Python 3.11+ |
29 | | -* [uv](https://github.com/astral-sh/uv) (recommended) or pip |
30 | | -* Google GenAI API Key |
| 31 | +- Python 3.11+ |
| 32 | +- A **Google GenAI API Key** (Gemini) |
| 33 | +- (Optional) Docker |
31 | 34 |
|
32 | | -## Setup & Installation |
| 35 | +### Installation |
33 | 36 |
|
34 | | -1. **Clone the repository:** |
| 37 | +1. **Clone the repository**: |
35 | 38 | ```bash |
36 | 39 | git clone <repository-url> |
37 | 40 | cd code_translator_green_agent |
38 | 41 | ``` |
39 | 42 |
|
40 | | -2. **Configure Environment:** |
41 | | - Create a `.env` file in the root directory: |
| 43 | +2. **Create a virtual environment** (optional but recommended): |
42 | 44 | ```bash |
43 | | - GOOGLE_API_KEY=your_api_key_here |
| 45 | + python -m venv .venv |
| 46 | + source .venv/bin/activate |
44 | 47 | ``` |
45 | 48 |
|
46 | | -3. **Install Dependencies:** |
47 | | - Using `uv`: |
| 49 | +3. **Install dependencies**: |
48 | 50 | ```bash |
49 | | - uv sync |
| 51 | + pip install . |
| 52 | + # Or install specific requirements |
| 53 | + pip install python-dotenv uvicorn httpx google-genai pydantic "google-adk[a2a]" |
| 54 | + ``` |
| 55 | + |
| 56 | +4. **Environment Variables**: |
| 57 | + Create a `.env` file in the root directory (or ensure relevant environment variables are set) containing your Google API key: |
| 58 | + ```env |
| 59 | + GOOGLE_API_KEY=your_google_api_key_here |
50 | 60 | ``` |
51 | 61 |
|
52 | 62 | ## Running the Agent |
53 | 63 |
|
54 | | -### Local Execution |
55 | | -To run the agent server locally: |
| 64 | +### Locally |
| 65 | + |
| 66 | +To start the agent server: |
| 67 | + |
| 68 | +```bash |
| 69 | +python src/server.py |
| 70 | +``` |
| 71 | + |
| 72 | +By default, the server runs on `http://127.0.0.1:9009`. |
| 73 | +You can customize the host and port using arguments: |
56 | 74 |
|
57 | 75 | ```bash |
58 | | -uv run src/server.py --host 0.0.0.0 --port 9009 |
| 76 | +python src/server.py --host 0.0.0.0 --port 8080 |
59 | 77 | ``` |
60 | 78 |
|
61 | | -The agent will be available at `http://localhost:9009`. |
| 79 | +### Using Docker |
62 | 80 |
|
63 | | -### Docker Execution |
64 | | -To build and run using Docker: |
| 81 | +1. **Build the image**: |
| 82 | + ```bash |
| 83 | + docker build -t green-agent . |
| 84 | + ``` |
65 | 85 |
|
66 | | -1. **Build the image:** |
| 86 | +2. **Run the container**: |
67 | 87 | ```bash |
68 | | - docker build -t code-translator-green . |
| 88 | + docker run -p 9009:9009 --env GOOGLE_API_KEY=your_api_key green-agent |
69 | 89 | ``` |
70 | 90 |
|
71 | | -2. **Run the container:** |
| 91 | +## Usage as a Judge |
| 92 | + |
| 93 | +The agent is designed to be called by an orchestration layer or directly via A2A protocol. It expects a JSON payload (Evaluator Request) with the following structure: |
| 94 | + |
| 95 | +```json |
| 96 | +{ |
| 97 | + "participants": { |
| 98 | + "researcher_translator": "http://url-to-purple-agent" |
| 99 | + }, |
| 100 | + "config": { |
| 101 | + "code_to_translate": "print('Hello World')", |
| 102 | + "source_language": "python", |
| 103 | + "target_language": "javascript" |
| 104 | + } |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +**The Workflow:** |
| 109 | +1. The Green Agent contacts the participant agent at the provided URL (`http://url-to-purple-agent`). |
| 110 | +2. It sends the `code_to_translate`, `source_language`, and `target_language` to the participant. |
| 111 | +3. It waits for the participant to return the translated code. |
| 112 | +4. Once received, the Green Agent constructs a prompt for the Gemini model (Judge), instructing it to evaluate the translation. |
| 113 | +5. It returns a result resembling: |
| 114 | + |
| 115 | +```json |
| 116 | +{ |
| 117 | + "winner": "researcher_translator", |
| 118 | + "scores": [ |
| 119 | + { |
| 120 | + "participant": "researcher_translator", |
| 121 | + "score": 9 |
| 122 | + } |
| 123 | + ], |
| 124 | + "reasoning": "The translation is syntactically correct and preserves functionality..." |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +## Testing |
| 129 | + |
| 130 | +To ensure the agent is functioning correctly, you can run the provided tests. |
| 131 | + |
| 132 | +1. **Install test dependencies** (if not already installed): |
72 | 133 | ```bash |
73 | | - docker run -p 9009:9009 --env-file .env code-translator-green |
| 134 | + pip install pytest pytest-asyncio |
74 | 135 | ``` |
75 | 136 |
|
76 | | -## Project Structure |
| 137 | +2. **Run tests**: |
| 138 | + ```bash |
| 139 | + pytest tests/ |
| 140 | + ``` |
77 | 141 |
|
78 | | -* `src/agent.py`: Defines the ADK Agent, system prompt, and evaluation logic. |
79 | | -* `src/server.py`: Entry point for the HTTP server. |
80 | | -* `src/tool_provider.py`: Tools for the agent (e.g., A2A communication). |
81 | | -* `src/common.py`: Shared data models (e.g., `TranslatorEval` schema). |
| 142 | + The `test_agent.py` contains: |
| 143 | + - **Conformance Tests**: Verifies the Agent Card and A2A protocol structure (e.g., proper message formats, capabilities). |
| 144 | + - **Message Validation**: Ensures that request and response payloads adhere to the defined schemas. |
0 commit comments