fix: Remove 'per_agent' from kwargs when using remote session service URIs

Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 837169299
This commit is contained in:
George Weale
2025-11-26 10:08:13 -08:00
committed by Copybara-Service
parent ec4ccd718f
commit 73e5687b9a
6 changed files with 10 additions and 82 deletions
-2
View File
@@ -106,7 +106,6 @@ def get_fast_api_app(
base_dir=agents_dir,
session_service_uri=session_service_uri,
session_db_kwargs=session_db_kwargs,
per_agent=True, # Multi-agent mode
)
# Build the Artifact service
@@ -114,7 +113,6 @@ def get_fast_api_app(
artifact_service = create_artifact_service_from_options(
base_dir=agents_dir,
artifact_service_uri=artifact_service_uri,
per_agent=True, # Multi-agent mode
)
except ValueError as exc:
raise click.ClickException(str(exc)) from exc
+2 -6
View File
@@ -271,18 +271,14 @@ def _register_builtin_services(registry: ServiceRegistry) -> None:
kwargs_copy = kwargs.copy()
kwargs_copy.pop("agents_dir", None)
kwargs_copy.pop("per_agent", None)
parsed_uri = urlparse(uri)
bucket_name = parsed_uri.netloc
return GcsArtifactService(bucket_name=bucket_name, **kwargs_copy)
def file_artifact_factory(uri: str, **kwargs):
def file_artifact_factory(uri: str, **_):
from ..artifacts.file_artifact_service import FileArtifactService
per_agent = kwargs.get("per_agent", False)
if per_agent:
raise ValueError(
"file:// artifact URIs are not supported in multi-agent mode."
)
parsed_uri = urlparse(uri)
if parsed_uri.netloc not in ("", "localhost"):
raise ValueError(
+2 -9
View File
@@ -58,13 +58,12 @@ def create_local_database_session_service(
def create_local_artifact_service(
*, base_dir: Path | str, per_agent: bool = False
*, base_dir: Path | str
) -> BaseArtifactService:
"""Creates a file-backed artifact service rooted in `.adk/artifacts`.
Args:
base_dir: Directory whose `.adk` folder will store artifacts.
per_agent: Indicates whether the service is being used in multi-agent mode.
Returns:
A `FileArtifactService` scoped to the derived root directory.
@@ -72,13 +71,7 @@ def create_local_artifact_service(
manager = DotAdkFolder(base_dir)
artifact_root = manager.artifacts_dir
artifact_root.mkdir(parents=True, exist_ok=True)
if per_agent:
logger.info(
"Using shared file artifact service rooted at %s for multi-agent mode",
artifact_root,
)
else:
logger.info("Using file artifact service at %s", artifact_root)
logger.info("Using file artifact service at %s", artifact_root)
return FileArtifactService(root_dir=artifact_root)
+1 -18
View File
@@ -32,7 +32,6 @@ def create_session_service_from_options(
base_dir: Path | str,
session_service_uri: Optional[str] = None,
session_db_kwargs: Optional[dict[str, Any]] = None,
per_agent: bool = False,
) -> BaseSessionService:
"""Creates a session service based on CLI/web options."""
base_path = Path(base_dir)
@@ -40,17 +39,11 @@ def create_session_service_from_options(
kwargs: dict[str, Any] = {
"agents_dir": str(base_path),
"per_agent": per_agent,
}
if session_db_kwargs:
kwargs.update(session_db_kwargs)
if session_service_uri:
if per_agent:
logger.warning(
"per_agent is not supported with remote session service URIs,"
" ignoring"
)
logger.info("Using session service URI: %s", session_service_uri)
service = registry.create_session_service(session_service_uri, **kwargs)
if service is not None:
@@ -63,7 +56,6 @@ def create_session_service_from_options(
fallback_kwargs = dict(kwargs)
fallback_kwargs.pop("agents_dir", None)
fallback_kwargs.pop("per_agent", None)
logger.info(
"Falling back to DatabaseSessionService for URI: %s",
session_service_uri,
@@ -105,23 +97,16 @@ def create_artifact_service_from_options(
*,
base_dir: Path | str,
artifact_service_uri: Optional[str] = None,
per_agent: bool = False,
) -> BaseArtifactService:
"""Creates an artifact service based on CLI/web options."""
base_path = Path(base_dir)
registry = get_service_registry()
if artifact_service_uri:
if per_agent:
logger.warning(
"per_agent is not supported with remote artifact service URIs,"
" ignoring"
)
logger.info("Using artifact service URI: %s", artifact_service_uri)
service = registry.create_artifact_service(
artifact_service_uri,
agents_dir=str(base_path),
per_agent=per_agent,
)
if service is None:
logger.warning(
@@ -133,6 +118,4 @@ def create_artifact_service_from_options(
return InMemoryArtifactService()
return service
if per_agent:
logger.info("Using shared file artifact service rooted at %s", base_dir)
return create_local_artifact_service(base_dir=base_path, per_agent=per_agent)
return create_local_artifact_service(base_dir=base_path)