Creates a FastAPI app for the ADK web server. By default it'll just return a FastAPI instance with the API server endpoints, but if you specify a web_assets_dir, it'll also serve the static web assets from that directory. Args: lifespan: The lifespan of the FastAPI app.
(
self,
lifespan: Optional[Lifespan[FastAPI]] = None,
allow_origins: Optional[list[str]] = None,
web_assets_dir: Optional[str] = None,
setup_observer: Callable[
[Observer, "ApiServer"], None
] = lambda o, s: None,
tear_down_observer: Callable[
[Observer, "ApiServer"], None
] = lambda o, s: None,
register_processors: Callable[[TracerProvider], None] = lambda o: None,
otel_to_cloud: bool = False,
with_ui: bool = False,
)
| 870 | raise HTTPException(status_code=500, detail=str(e)) from e |
| 871 | |
| 872 | def get_fast_api_app( |
| 873 | self, |
| 874 | lifespan: Optional[Lifespan[FastAPI]] = None, |
| 875 | allow_origins: Optional[list[str]] = None, |
| 876 | web_assets_dir: Optional[str] = None, |
| 877 | setup_observer: Callable[ |
| 878 | [Observer, "ApiServer"], None |
| 879 | ] = lambda o, s: None, |
| 880 | tear_down_observer: Callable[ |
| 881 | [Observer, "ApiServer"], None |
| 882 | ] = lambda o, s: None, |
| 883 | register_processors: Callable[[TracerProvider], None] = lambda o: None, |
| 884 | otel_to_cloud: bool = False, |
| 885 | with_ui: bool = False, |
| 886 | ): |
| 887 | """Creates a FastAPI app for the ADK web server. |
| 888 | |
| 889 | By default it'll just return a FastAPI instance with the API server |
| 890 | endpoints, |
| 891 | but if you specify a web_assets_dir, it'll also serve the static web assets |
| 892 | from that directory. |
| 893 | |
| 894 | Args: |
| 895 | lifespan: The lifespan of the FastAPI app. |
| 896 | allow_origins: The origins that are allowed to make cross-origin requests. |
| 897 | Entries can be literal origins (e.g., 'https://example.com') or regex |
| 898 | patterns prefixed with 'regex:' (e.g., |
| 899 | 'regex:https://.*\\.example\\.com'). |
| 900 | web_assets_dir: The directory containing the web assets to serve. |
| 901 | setup_observer: Callback for setting up the file system observer. |
| 902 | tear_down_observer: Callback for cleaning up the file system observer. |
| 903 | register_processors: Callback for additional Span processors to be added |
| 904 | to the TracerProvider. |
| 905 | otel_to_cloud: Whether to enable Cloud Trace and Cloud Logging |
| 906 | integrations. |
| 907 | |
| 908 | Returns: |
| 909 | A FastAPI app instance. |
| 910 | """ |
| 911 | trace_dict = {} |
| 912 | session_trace_dict = {} |
| 913 | self._trace_dict = trace_dict |
| 914 | self._session_trace_dict = session_trace_dict |
| 915 | |
| 916 | # Set up a file system watcher to detect changes in the agents directory. |
| 917 | observer = Observer() |
| 918 | setup_observer(observer, self) |
| 919 | |
| 920 | @asynccontextmanager |
| 921 | async def internal_lifespan(app: FastAPI): |
| 922 | try: |
| 923 | if lifespan: |
| 924 | async with lifespan(app) as lifespan_context: |
| 925 | yield lifespan_context |
| 926 | else: |
| 927 | yield |
| 928 | finally: |
| 929 | tear_down_observer(observer, self) |
nothing calls this directly
no test coverage detected