|
66 | 66 | from .utils.service_factory import create_artifact_service_from_options |
67 | 67 | from .utils.service_factory import create_memory_service_from_options |
68 | 68 | from .utils.service_factory import create_session_service_from_options |
69 | | - |
| 69 | +from ..apps.app import App |
| 70 | +from collections.abc import Mapping |
70 | 71 | _ALLOWED_AGENT_ENGINE_CLASS_METHODS = frozenset( |
71 | 72 | method["name"] for method in _AGENT_ENGINE_CLASS_METHODS |
72 | 73 | ) |
73 | 74 |
|
| 75 | +class DynamicAppMap(Mapping): |
| 76 | + def __init__(self, agent_loader): |
| 77 | + self.agent_loader = agent_loader |
| 78 | + |
| 79 | + def __getitem__(self, app_name): |
| 80 | + for folder_name in self.agent_loader.list_agents(): |
| 81 | + try: |
| 82 | + loaded = self.agent_loader.load_agent(folder_name) |
| 83 | + if isinstance(loaded, App) and loaded.name == app_name: |
| 84 | + return folder_name |
| 85 | + except Exception: |
| 86 | + pass |
| 87 | + return app_name |
| 88 | + |
| 89 | + def __iter__(self): |
| 90 | + return iter([]) |
| 91 | + |
| 92 | + def __len__(self): |
| 93 | + return 1 |
74 | 94 |
|
75 | 95 | class _QueryRequest(BaseModel): |
76 | 96 | input: dict[str, Any] | None = None |
@@ -543,13 +563,15 @@ def get_fast_api_app( |
543 | 563 | ) |
544 | 564 | except ValueError as exc: |
545 | 565 | raise click.ClickException(str(exc)) from exc |
546 | | - |
| 566 | + |
| 567 | + app_name_to_dir = DynamicAppMap(agent_loader) |
547 | 568 | # Build the Session service |
548 | 569 | session_service = create_session_service_from_options( |
549 | 570 | base_dir=agents_dir, |
550 | 571 | session_service_uri=session_service_uri, |
551 | 572 | session_db_kwargs=session_db_kwargs, |
552 | 573 | use_local_storage=use_local_storage, |
| 574 | + app_name_to_dir=app_name_to_dir |
553 | 575 | ) |
554 | 576 |
|
555 | 577 | # Build the Artifact service |
|
0 commit comments