{"record":{"id":"94c1a5afc75c6c5d","repo":"apache/beam","slug":"agent-must-be-an-agent-instance-or-a-callable","errorCode":null,"errorMessage":"'agent' must be an Agent instance or a callable.","messagePattern":"'agent' must be an Agent instance or a callable\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/inference/agent_development_kit.py","lineNumber":144,"sourceCode":"      self,\n      agent: _AgentOrFactory,\n      app_name: str = \"beam_inference\",\n      session_service_factory: Optional[Callable[[],\n                                                 \"BaseSessionService\"]] = None,\n      *,\n      min_batch_size: Optional[int] = None,\n      max_batch_size: Optional[int] = None,\n      max_batch_duration_secs: Optional[int] = None,\n      max_batch_weight: Optional[int] = None,\n      element_size_fn: Optional[Callable[[Any], int]] = None,\n      **kwargs):\n    if not ADK_AVAILABLE:\n      raise ImportError(\n          \"google-adk is required to use ADKAgentModelHandler. \"\n          \"Install it with: pip install google-adk\")\n\n    if agent is None:\n      raise ValueError(\"'agent' must be an Agent instance or a callable.\")\n\n    self._agent_or_factory = agent\n    self._app_name = app_name\n    self._session_service_factory = session_service_factory\n\n    super().__init__(\n        min_batch_size=min_batch_size,\n        max_batch_size=max_batch_size,\n        max_batch_duration_secs=max_batch_duration_secs,\n        max_batch_weight=max_batch_weight,\n        element_size_fn=element_size_fn,\n        **kwargs)\n\n  def load_model(self) -> \"Runner\":\n    \"\"\"Instantiates the ADK Runner on the worker.\n\n    Resolves the agent (calling the factory if a callable was provided), then\n    creates a :class:`~google.adk.runners.Runner` backed by the configured","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/inference/agent_development_kit.py#L126-L162","documentation":"Type guard on the agent argument: ADKAgentModelHandler accepts either a live google.adk Agent instance or a zero-arg callable that constructs one; anything else (a class not derived from Agent, a string, etc.) cannot produce a runnable agent and is rejected.","triggerScenarios":"Thrown at sdks/python/apache_beam/ml/inference/agent_development_kit.py:144 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass an instance of google.adk.Agent directly","Or pass a factory lambda: agent=lambda: LlmAgent(name='my_agent', ...)"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}