mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
chore: Migrate /agents to use the new feature decorator
Co-authored-by: Xuan Yang <xygoogle@google.com> PiperOrigin-RevId: 873097395
This commit is contained in:
committed by
Copybara-Service
parent
485fcb84e3
commit
6ea3696bcc
@@ -16,14 +16,14 @@ from __future__ import annotations
|
||||
|
||||
from typing import Annotated
|
||||
from typing import Any
|
||||
from typing import get_args
|
||||
from typing import Union
|
||||
|
||||
from pydantic import Discriminator
|
||||
from pydantic import RootModel
|
||||
from pydantic import Tag
|
||||
|
||||
from ..utils.feature_decorator import experimental
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
from .base_agent_config import BaseAgentConfig
|
||||
from .llm_agent_config import LlmAgentConfig
|
||||
from .loop_agent_config import LoopAgentConfig
|
||||
@@ -68,6 +68,6 @@ ConfigsUnion = Annotated[
|
||||
|
||||
# Use a RootModel to represent the agent directly at the top level.
|
||||
# The `discriminator` is applied to the union within the RootModel.
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
class AgentConfig(RootModel[ConfigsUnion]):
|
||||
"""The config for the YAML schema to create an agent."""
|
||||
|
||||
@@ -40,10 +40,11 @@ from typing_extensions import TypeAlias
|
||||
|
||||
from ..events.event import Event
|
||||
from ..events.event_actions import EventActions
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
from ..telemetry import tracing
|
||||
from ..telemetry.tracing import tracer
|
||||
from ..utils.context_utils import Aclosing
|
||||
from ..utils.feature_decorator import experimental
|
||||
from .base_agent_config import BaseAgentConfig
|
||||
from .callback_context import CallbackContext
|
||||
|
||||
@@ -70,7 +71,7 @@ AfterAgentCallback: TypeAlias = Union[
|
||||
SelfAgent = TypeVar('SelfAgent', bound='BaseAgent')
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_STATE)
|
||||
class BaseAgentState(BaseModel):
|
||||
"""Base class for all agent states."""
|
||||
|
||||
@@ -618,7 +619,7 @@ class BaseAgent(BaseModel):
|
||||
|
||||
@final
|
||||
@classmethod
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
def from_config(
|
||||
cls: Type[SelfAgent],
|
||||
config: BaseAgentConfig,
|
||||
@@ -642,7 +643,7 @@ class BaseAgent(BaseModel):
|
||||
return cls(**kwargs)
|
||||
|
||||
@classmethod
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
def _parse_config(
|
||||
cls: Type[SelfAgent],
|
||||
config: BaseAgentConfig,
|
||||
|
||||
@@ -26,14 +26,15 @@ from pydantic import BaseModel
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import Field
|
||||
|
||||
from ..utils.feature_decorator import experimental
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
from .common_configs import AgentRefConfig
|
||||
from .common_configs import CodeConfig
|
||||
|
||||
TBaseAgentConfig = TypeVar('TBaseAgentConfig', bound='BaseAgentConfig')
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
class BaseAgentConfig(BaseModel):
|
||||
"""The config for the YAML schema of a BaseAgent.
|
||||
|
||||
|
||||
@@ -24,10 +24,11 @@ from pydantic import BaseModel
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import model_validator
|
||||
|
||||
from ..utils.feature_decorator import experimental
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
class ArgumentConfig(BaseModel):
|
||||
"""An argument passed to a function or a class's constructor."""
|
||||
|
||||
@@ -43,7 +44,7 @@ class ArgumentConfig(BaseModel):
|
||||
"""The argument value."""
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
class CodeConfig(BaseModel):
|
||||
"""Code reference config for a variable, a function, or a class.
|
||||
|
||||
@@ -81,7 +82,7 @@ class CodeConfig(BaseModel):
|
||||
"""
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
class AgentRefConfig(BaseModel):
|
||||
"""The config for the reference to another agent."""
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ from typing import List
|
||||
|
||||
import yaml
|
||||
|
||||
from ..utils.feature_decorator import experimental
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
from .agent_config import AgentConfig
|
||||
from .base_agent import BaseAgent
|
||||
from .base_agent_config import BaseAgentConfig
|
||||
@@ -30,7 +31,7 @@ from .common_configs import AgentRefConfig
|
||||
from .common_configs import CodeConfig
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
def from_config(config_path: str) -> BaseAgent:
|
||||
"""Build agent from a configfile path.
|
||||
|
||||
@@ -102,7 +103,7 @@ def _load_config_from_path(config_path: str) -> AgentConfig:
|
||||
return AgentConfig.model_validate(config_data)
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
def resolve_fully_qualified_name(name: str) -> Any:
|
||||
try:
|
||||
module_path, obj_name = name.rsplit(".", 1)
|
||||
@@ -112,7 +113,7 @@ def resolve_fully_qualified_name(name: str) -> Any:
|
||||
raise ValueError(f"Invalid fully qualified name: {name}") from e
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
def resolve_agent_reference(
|
||||
ref_config: AgentRefConfig, referencing_agent_config_abs_path: str
|
||||
) -> BaseAgent:
|
||||
@@ -170,7 +171,7 @@ def _resolve_agent_code_reference(code: str) -> Any:
|
||||
return obj
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
def resolve_code_reference(code_config: CodeConfig) -> Any:
|
||||
"""Resolve a code reference to actual Python object.
|
||||
|
||||
@@ -199,7 +200,7 @@ def resolve_code_reference(code_config: CodeConfig) -> Any:
|
||||
return obj
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
def resolve_callbacks(callbacks_config: List[CodeConfig]) -> Any:
|
||||
"""Resolve callbacks from configuration.
|
||||
|
||||
|
||||
@@ -18,10 +18,11 @@ from pydantic import BaseModel
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import Field
|
||||
|
||||
from ..utils.feature_decorator import experimental
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
class ContextCacheConfig(BaseModel):
|
||||
"""Configuration for context caching across all agents in an app.
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ from typing_extensions import TypeAlias
|
||||
|
||||
from ..code_executors.base_code_executor import BaseCodeExecutor
|
||||
from ..events.event import Event
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
from ..flows.llm_flows.auto_flow import AutoFlow
|
||||
from ..flows.llm_flows.base_llm_flow import BaseLlmFlow
|
||||
from ..flows.llm_flows.single_flow import SingleFlow
|
||||
@@ -55,7 +57,6 @@ from ..tools.function_tool import FunctionTool
|
||||
from ..tools.tool_configs import ToolConfig
|
||||
from ..tools.tool_context import ToolContext
|
||||
from ..utils.context_utils import Aclosing
|
||||
from ..utils.feature_decorator import experimental
|
||||
from .base_agent import BaseAgent
|
||||
from .base_agent import BaseAgentState
|
||||
from .base_agent_config import BaseAgentConfig
|
||||
@@ -883,7 +884,7 @@ class LlmAgent(BaseAgent):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
def _resolve_tools(
|
||||
cls, tool_configs: list[ToolConfig], config_abs_path: str
|
||||
) -> list[Any]:
|
||||
@@ -942,7 +943,7 @@ class LlmAgent(BaseAgent):
|
||||
|
||||
@override
|
||||
@classmethod
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
def _parse_config(
|
||||
cls: Type[LlmAgent],
|
||||
config: LlmAgentConfig,
|
||||
|
||||
@@ -26,8 +26,9 @@ from typing import Optional
|
||||
from typing_extensions import override
|
||||
|
||||
from ..events.event import Event
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
from ..utils.context_utils import Aclosing
|
||||
from ..utils.feature_decorator import experimental
|
||||
from .base_agent import BaseAgent
|
||||
from .base_agent import BaseAgentState
|
||||
from .base_agent_config import BaseAgentConfig
|
||||
@@ -37,7 +38,7 @@ from .loop_agent_config import LoopAgentConfig
|
||||
logger = logging.getLogger('google_adk.' + __name__)
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_STATE)
|
||||
class LoopAgentState(BaseAgentState):
|
||||
"""State for LoopAgent."""
|
||||
|
||||
@@ -153,7 +154,7 @@ class LoopAgent(BaseAgent):
|
||||
|
||||
@override
|
||||
@classmethod
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
def _parse_config(
|
||||
cls: type[LoopAgent],
|
||||
config: LoopAgentConfig,
|
||||
|
||||
@@ -21,11 +21,12 @@ from typing import Optional
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import Field
|
||||
|
||||
from ..utils.feature_decorator import experimental
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
from .base_agent_config import BaseAgentConfig
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
class LoopAgentConfig(BaseAgentConfig):
|
||||
"""The config for the YAML schema of a LoopAgent."""
|
||||
|
||||
|
||||
@@ -19,11 +19,12 @@ from __future__ import annotations
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import Field
|
||||
|
||||
from ..utils.feature_decorator import experimental
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
from .base_agent_config import BaseAgentConfig
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
class ParallelAgentConfig(BaseAgentConfig):
|
||||
"""The config for the YAML schema of a ParallelAgent."""
|
||||
|
||||
|
||||
@@ -24,8 +24,9 @@ from typing import Type
|
||||
from typing_extensions import override
|
||||
|
||||
from ..events.event import Event
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
from ..utils.context_utils import Aclosing
|
||||
from ..utils.feature_decorator import experimental
|
||||
from .base_agent import BaseAgent
|
||||
from .base_agent import BaseAgentState
|
||||
from .base_agent_config import BaseAgentConfig
|
||||
@@ -36,7 +37,7 @@ from .sequential_agent_config import SequentialAgentConfig
|
||||
logger = logging.getLogger('google_adk.' + __name__)
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_STATE)
|
||||
class SequentialAgentState(BaseAgentState):
|
||||
"""State for SequentialAgent."""
|
||||
|
||||
|
||||
@@ -19,11 +19,12 @@ from __future__ import annotations
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import Field
|
||||
|
||||
from ..agents.base_agent import experimental
|
||||
from ..agents.base_agent_config import BaseAgentConfig
|
||||
from ..features import experimental
|
||||
from ..features import FeatureName
|
||||
|
||||
|
||||
@experimental
|
||||
@experimental(FeatureName.AGENT_CONFIG)
|
||||
class SequentialAgentConfig(BaseAgentConfig):
|
||||
"""The config for the YAML schema of a SequentialAgent."""
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ from ..utils.env_utils import is_env_enabled
|
||||
class FeatureName(str, Enum):
|
||||
"""Feature names."""
|
||||
|
||||
AGENT_CONFIG = "AGENT_CONFIG"
|
||||
AGENT_STATE = "AGENT_STATE"
|
||||
AUTHENTICATED_FUNCTION_TOOL = "AUTHENTICATED_FUNCTION_TOOL"
|
||||
BASE_AUTHENTICATED_TOOL = "BASE_AUTHENTICATED_TOOL"
|
||||
BIG_QUERY_TOOLSET = "BIG_QUERY_TOOLSET"
|
||||
@@ -79,6 +81,12 @@ class FeatureConfig:
|
||||
|
||||
# Central registry: FeatureName -> FeatureConfig
|
||||
_FEATURE_REGISTRY: dict[FeatureName, FeatureConfig] = {
|
||||
FeatureName.AGENT_CONFIG: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
FeatureName.AGENT_STATE: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
FeatureName.AUTHENTICATED_FUNCTION_TOOL: FeatureConfig(
|
||||
FeatureStage.EXPERIMENTAL, default_on=True
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user