gemini-code-assist[bot] commented on code in PR #37917: URL: https://github.com/apache/beam/pull/37917#discussion_r2994973270
########## sdks/python/apache_beam/ml/inference/agent_development_kit.py: ########## @@ -0,0 +1,295 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +"""ModelHandler for running agents built with the Google Agent Development Kit. + +This module provides :class:`ADKAgentModelHandler`, a Beam +:class:`~apache_beam.ml.inference.base.ModelHandler` that wraps an ADK +:class:`google.adk.agents.llm_agent.LlmAgent` so it can be used with the +:class:`~apache_beam.ml.inference.base.RunInference` transform. + +Typical usage:: + + import apache_beam as beam + from apache_beam.ml.inference.base import RunInference + from apache_beam.ml.inference.agent_development_kit import ADKAgentModelHandler + from google.adk.agents import LlmAgent + + agent = LlmAgent( + name="my_agent", + model="gemini-2.0-flash", + instruction="You are a helpful assistant.", + ) + + with beam.Pipeline() as p: + results = ( + p + | beam.Create(["What is the capital of France?"]) + | RunInference(ADKAgentModelHandler(agent=agent)) + ) + +If your agent contains state that is not picklable (e.g. tool closures that +capture unpicklable objects), pass a zero-arg factory callable instead:: + + handler = ADKAgentModelHandler(agent=lambda: LlmAgent(...)) + +""" + +import asyncio +import logging +import uuid +from collections.abc import Callable +from collections.abc import Iterable +from collections.abc import Sequence +from typing import Any +from typing import Optional +from typing import Union + +from apache_beam.ml.inference.base import ModelHandler +from apache_beam.ml.inference.base import PredictionResult + +try: + from google.adk.agents import Agent + from google.adk.runners import Runner + from google.adk.sessions import BaseSessionService + from google.adk.sessions import InMemorySessionService + from google.genai.types import Content as genai_Content + from google.genai.types import Part as genai_Part + ADK_AVAILABLE = True +except ImportError: Review Comment:  The `sessions` module is used in `run_inference` (line 233) but is not imported. This will cause a `NameError` at runtime. Please import it along with the other `google-adk` components. ```suggestion try: from google.adk.agents import Agent from google.adk.runners import Runner from google.adk import sessions from google.adk.sessions import BaseSessionService from google.adk.sessions import InMemorySessionService from google.genai.types import Content as genai_Content from google.genai.types import Part as genai_Part ADK_AVAILABLE = True except ImportError: ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
