docs(config): fix core_callback example

PiperOrigin-RevId: 795619488
This commit is contained in:
Liang Wu
2025-08-15 14:44:53 -07:00
committed by Copybara-Service
parent c84350345a
commit ba6e85eb3f
5 changed files with 17 additions and 110 deletions
@@ -19,25 +19,25 @@ instruction: |
You should always perform the previous 3 steps when asking for a roll and checking prime numbers.
You should not rely on the previous history on prime results.
tools:
- name: callbacks.tools.roll_die
- name: callbacks.tools.check_prime
- name: core_callback.tools.roll_die
- name: core_callback.tools.check_prime
before_agent_callbacks:
- name: callbacks.callbacks.before_agent_callback1
- name: callbacks.callbacks.before_agent_callback2
- name: callbacks.callbacks.before_agent_callback3
- name: core_callback.callbacks.before_agent_callback1
- name: core_callback.callbacks.before_agent_callback2
- name: core_callback.callbacks.before_agent_callback3
after_agent_callbacks:
- name: callbacks.callbacks.after_agent_callback1
- name: callbacks.callbacks.after_agent_callback2
- name: callbacks.callbacks.after_agent_callback3
- name: core_callback.callbacks.after_agent_callback1
- name: core_callback.callbacks.after_agent_callback2
- name: core_callback.callbacks.after_agent_callback3
before_model_callbacks:
- name: callbacks.callbacks.before_model_callback
- name: core_callback.callbacks.before_model_callback
after_model_callbacks:
- name: callbacks.callbacks.after_model_callback
- name: core_callback.callbacks.after_model_callback
before_tool_callbacks:
- name: callbacks.callbacks.before_tool_callback1
- name: callbacks.callbacks.before_tool_callback2
- name: callbacks.callbacks.before_tool_callback3
- name: core_callback.callbacks.before_tool_callback1
- name: core_callback.callbacks.before_tool_callback2
- name: core_callback.callbacks.before_tool_callback3
after_tool_callbacks:
- name: callbacks.callbacks.after_tool_callback1
- name: callbacks.callbacks.after_tool_callback2
- name: callbacks.callbacks.after_tool_callback3
- name: core_callback.callbacks.after_tool_callback1
- name: core_callback.callbacks.after_tool_callback2
- name: core_callback.callbacks.after_tool_callback3
+1 -9
View File
@@ -21,10 +21,8 @@ from typing import Optional
import click
from packaging.version import parse
BASE_BUILD_IMAGE = 'python:3.11-slim'
_DOCKERFILE_TEMPLATE = """
FROM {build_image}
FROM python:3.11-slim
WORKDIR /app
# Create a non-root user
@@ -132,7 +130,6 @@ def to_cloud_run(
session_service_uri: Optional[str] = None,
artifact_service_uri: Optional[str] = None,
memory_service_uri: Optional[str] = None,
build_image: Optional[str] = BASE_BUILD_IMAGE,
a2a: bool = False,
):
"""Deploys an agent to Google Cloud Run.
@@ -166,7 +163,6 @@ def to_cloud_run(
session_service_uri: The URI of the session service.
artifact_service_uri: The URI of the artifact service.
memory_service_uri: The URI of the memory service.
build_image: The image to use for building the Dockerfile.
"""
app_name = app_name or os.path.basename(agent_folder)
@@ -215,7 +211,6 @@ def to_cloud_run(
adk_version=adk_version,
host_option=host_option,
a2a_option=a2a_option,
build_image=build_image,
)
dockerfile_path = os.path.join(temp_folder, 'Dockerfile')
os.makedirs(temp_folder, exist_ok=True)
@@ -479,7 +474,6 @@ def to_gke(
session_service_uri: Optional[str] = None,
artifact_service_uri: Optional[str] = None,
memory_service_uri: Optional[str] = None,
build_image: Optional[str] = BASE_BUILD_IMAGE,
a2a: bool = False,
):
"""Deploys an agent to Google Kubernetes Engine(GKE).
@@ -501,7 +495,6 @@ def to_gke(
session_service_uri: The URI of the session service.
artifact_service_uri: The URI of the artifact service.
memory_service_uri: The URI of the memory service.
build_image: The image to use for building the Dockerfile.
"""
click.secho(
'\n🚀 Starting ADK Agent Deployment to GKE...', fg='cyan', bold=True
@@ -563,7 +556,6 @@ def to_gke(
adk_version=adk_version,
host_option=host_option,
a2a_option='--a2a' if a2a else '',
build_image=build_image,
)
dockerfile_path = os.path.join(temp_folder, 'Dockerfile')
os.makedirs(temp_folder, exist_ok=True)
-20
View File
@@ -44,8 +44,6 @@ LOG_LEVELS = click.Choice(
case_sensitive=False,
)
BASE_BUILD_IMAGE = "python:3.11-slim"
class HelpfulCommand(click.Command):
"""Command that shows full help on error instead of just the error message.
@@ -970,13 +968,6 @@ def cli_api_server(
help="Optional. Any additional origins to allow for CORS.",
multiple=True,
)
@click.option(
"--build_image",
type=str,
default=BASE_BUILD_IMAGE,
show_default=True,
help="Optional. The docker build version used in Cloud Run deployment. ",
)
# TODO: Add eval_storage_uri option back when evals are supported in Cloud Run.
@adk_services_options()
@deprecated_adk_services_options()
@@ -1000,7 +991,6 @@ def cli_deploy_cloud_run(
session_db_url: Optional[str] = None, # Deprecated
artifact_storage_uri: Optional[str] = None, # Deprecated
a2a: bool = False,
build_image: Optional[str] = BASE_BUILD_IMAGE,
):
"""Deploys an agent to Cloud Run.
@@ -1039,7 +1029,6 @@ def cli_deploy_cloud_run(
artifact_service_uri=artifact_service_uri,
memory_service_uri=memory_service_uri,
a2a=a2a,
build_image=build_image,
)
except Exception as e:
click.secho(f"Deploy failed: {e}", fg="red", err=True)
@@ -1292,13 +1281,6 @@ def cli_deploy_agent_engine(
" version in the dev environment)"
),
)
@click.option(
"--build_image",
type=str,
default=BASE_BUILD_IMAGE,
show_default=True,
help="Optional. The docker build version used in GKE deployment. ",
)
@adk_services_options()
@click.argument(
"agent",
@@ -1322,7 +1304,6 @@ def cli_deploy_gke(
session_service_uri: Optional[str] = None,
artifact_service_uri: Optional[str] = None,
memory_service_uri: Optional[str] = None,
build_image: Optional[str] = BASE_BUILD_IMAGE,
):
"""Deploys an agent to GKE.
@@ -1349,7 +1330,6 @@ def cli_deploy_gke(
session_service_uri=session_service_uri,
artifact_service_uri=artifact_service_uri,
memory_service_uri=memory_service_uri,
build_image=build_image,
)
except Exception as e:
click.secho(f"Deploy failed: {e}", fg="red", err=True)
@@ -168,43 +168,11 @@ def test_cli_deploy_cloud_run_success(
"proj",
"--region",
"asia-northeast1",
"--build_image",
"my-custom-image",
str(agent_dir),
],
)
assert result.exit_code == 0
assert rec.calls, "cli_deploy.to_cloud_run must be invoked"
called_kwargs = rec.calls[0][1]
assert called_kwargs.get("build_image") == "my-custom-image"
def test_cli_deploy_cloud_run_default_build_image(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test that the default build_image is used."""
rec = _Recorder()
monkeypatch.setattr(cli_tools_click.cli_deploy, "to_cloud_run", rec)
agent_dir = tmp_path / "agent2"
agent_dir.mkdir()
runner = CliRunner()
result = runner.invoke(
cli_tools_click.main,
[
"deploy",
"cloud_run",
"--project",
"proj",
"--region",
"asia-northeast1",
str(agent_dir),
],
)
assert result.exit_code == 0
assert rec.calls, "cli_deploy.to_cloud_run must be invoked"
called_kwargs = rec.calls[0][1]
assert called_kwargs.get("build_image") == cli_tools_click.BASE_BUILD_IMAGE
def test_cli_deploy_cloud_run_failure(
@@ -283,8 +251,6 @@ def test_cli_deploy_gke_success(
"us-central1",
"--cluster_name",
"my-cluster",
"--build_image",
"my-gke-image",
str(agent_dir),
],
)
@@ -294,37 +260,6 @@ def test_cli_deploy_gke_success(
assert called_kwargs.get("project") == "test-proj"
assert called_kwargs.get("region") == "us-central1"
assert called_kwargs.get("cluster_name") == "my-cluster"
assert called_kwargs.get("build_image") == "my-gke-image"
def test_cli_deploy_gke_default_build_image(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test that the default build_image is used for gke."""
rec = _Recorder()
monkeypatch.setattr(cli_tools_click.cli_deploy, "to_gke", rec)
agent_dir = tmp_path / "agent_gke"
agent_dir.mkdir()
runner = CliRunner()
result = runner.invoke(
cli_tools_click.main,
[
"deploy",
"gke",
"--project",
"test-proj",
"--region",
"us-central1",
"--cluster_name",
"my-cluster",
str(agent_dir),
],
)
assert result.exit_code == 0
assert rec.calls, "cli_deploy.to_gke must be invoked"
called_kwargs = rec.calls[0][1]
assert called_kwargs.get("build_image") == cli_tools_click.BASE_BUILD_IMAGE
# cli eval