chore: import upstream snapshot with attribution
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install the local ADK wheel (built from the repo under test).
|
||||
# Install the .whl file directly so pip uses it instead of PyPI.
|
||||
# Dependencies are resolved from PyPI automatically.
|
||||
COPY wheels/ /tmp/wheels/
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
RUN pip install --no-cache-dir /tmp/wheels/google_adk-*.whl \
|
||||
&& rm -rf /tmp/wheels
|
||||
|
||||
# Copy the agent into the expected adk layout:
|
||||
# /app/agents/trigger_echo_agent/__init__.py
|
||||
# /app/agents/trigger_echo_agent/agent.py
|
||||
COPY __init__.py agents/trigger_echo_agent/__init__.py
|
||||
COPY agent.py agents/trigger_echo_agent/agent.py
|
||||
|
||||
ENV PORT=8080
|
||||
ENV HOST=0.0.0.0
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["adk", "api_server", "--host=0.0.0.0", "--port=8080", "--trigger_sources=pubsub,eventarc", "/app/agents"]
|
||||
@@ -0,0 +1,13 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
@@ -0,0 +1,86 @@
|
||||
# Copyright 2026 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Echo agent for remote trigger integration tests.
|
||||
|
||||
Uses a before_model_callback to echo user input without calling the LLM,
|
||||
making tests fast, deterministic, and free of LLM model quota usage.
|
||||
|
||||
Supports optional 429 simulation via the SIMULATE_429_COUNT environment
|
||||
variable: when set to N > 0, the first N invocations per session will raise
|
||||
a RuntimeError containing "429 RESOURCE_EXHAUSTED" before succeeding.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from google.adk.agents.callback_context import CallbackContext
|
||||
from google.adk.agents.llm_agent import Agent
|
||||
from google.adk.models.llm_request import LlmRequest
|
||||
from google.adk.models.llm_response import LlmResponse
|
||||
from google.genai import types
|
||||
|
||||
# Track 429 simulation state across invocations within a process.
|
||||
# Keyed by session_id to allow per-session failure counts.
|
||||
_429_counter: dict[str, int] = {}
|
||||
|
||||
|
||||
def before_model_callback(
|
||||
callback_context: CallbackContext,
|
||||
llm_request: LlmRequest,
|
||||
) -> LlmResponse:
|
||||
"""Echo user input back without calling the LLM.
|
||||
|
||||
If SIMULATE_429_COUNT is set, raises a transient error for the first N
|
||||
invocations (per session) to exercise the retry-with-backoff logic in
|
||||
the trigger endpoints.
|
||||
"""
|
||||
fail_count = int(os.environ.get("SIMULATE_429_COUNT", "0"))
|
||||
session = callback_context.session
|
||||
session_id = session.id if session else "default"
|
||||
|
||||
if fail_count > 0:
|
||||
current = _429_counter.get(session_id, 0)
|
||||
if current < fail_count:
|
||||
_429_counter[session_id] = current + 1
|
||||
raise RuntimeError("429 RESOURCE_EXHAUSTED: simulated quota exceeded")
|
||||
|
||||
# Extract the most recent user message from the session events.
|
||||
user_text = ""
|
||||
if session and session.events:
|
||||
for event in reversed(session.events):
|
||||
if event.content and event.content.role == "user" and event.content.parts:
|
||||
user_text = event.content.parts[0].text or ""
|
||||
break
|
||||
|
||||
# Fall back to the current LLM request contents if no session event found.
|
||||
if not user_text and llm_request.contents:
|
||||
for content in reversed(llm_request.contents):
|
||||
if content.role == "user" and content.parts:
|
||||
user_text = content.parts[0].text or ""
|
||||
break
|
||||
|
||||
return LlmResponse(
|
||||
content=types.Content(
|
||||
role="model",
|
||||
parts=[types.Part(text=f"ECHO: {user_text}")],
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
root_agent = Agent(
|
||||
model="gemini-2.5-flash",
|
||||
name="trigger_echo_agent",
|
||||
instruction="Echo agent for trigger testing.",
|
||||
before_model_callback=before_model_callback,
|
||||
)
|
||||
Reference in New Issue
Block a user