# Copyright 2026 Flower Labs GmbH. All Rights Reserved.## Licensed 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.# =============================================================================="""Flower AgentApp."""from__future__importannotationsfromcollections.abcimportCallablefromflwr.commonimportContextfrom.baseimportAgentAppCallable,AgentSession
[docs]classAgentApp:"""Flower AgentApp. Examples -------- Define an AgentApp with a single main function:: app = AgentApp() @app.main() def main(agent: AgentSession, context: Context) -> None: print("AgentApp running") """def__init__(self)->None:self._main:AgentAppCallable|None=Nonedef__call__(self,agent:AgentSession,context:Context)->None:"""Execute `AgentApp`."""ifself._mainisNone:raiseValueError("AgentApp has no main function.")self._main(agent,context)
[docs]defmain(self)->Callable[[AgentAppCallable],AgentAppCallable]:"""Return a decorator that registers the main fn with the agent app. Examples -------- :: app = AgentApp() @app.main() def main(agent: AgentSession, context: Context) -> None: print("AgentApp running") """defmain_decorator(main_fn:AgentAppCallable)->AgentAppCallable:"""Register the main fn with the AgentApp object."""ifself._mainisnotNone:raiseValueError("AgentApp main function is already registered.")# Register provided function with the AgentApp objectself._main=main_fn# Return provided function unmodifiedreturnmain_fnreturnmain_decorator