A programming framework for agentic AI
Add an optional base path to FileSurfer (#5886)
Hussein Mozannar7d17b2292506
diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_file_surfer.py b/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_file_surfer.pyindex 8ab6ff9c6..aec34cc63 100644--- a/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_file_surfer.py+++ b/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_file_surfer.py@@ -1,4 +1,5 @@import json+import osimport tracebackfrom typing import List, Sequence, Tuple@@ -54,6 +55,7 @@ class FileSurfer(BaseChatAgent, Component[FileSurferConfig]):name (str): The agent's namemodel_client (ChatCompletionClient): The model to use (must be tool-use enabled)description (str): The agent's description used by the team. Defaults to DEFAULT_DESCRIPTION+ base_path (str): The base path to use for the file browser. Defaults to the current working directory."""@@ -75,11 +77,12 @@ class FileSurfer(BaseChatAgent, Component[FileSurferConfig]):name: str,model_client: ChatCompletionClient,description: str = DEFAULT_DESCRIPTION,+ base_path: str = os.getcwd(),) -> None:super().__init__(name, description)self._model_client = model_clientself._chat_history: List[LLMMessage] = []- self._browser = MarkdownFileBrowser(viewport_size=1024 * 5)+ self._browser = MarkdownFileBrowser(viewport_size=1024 * 5, base_path=base_path)@propertydef produced_message_types(self) -> Sequence[type[ChatMessage]]:diff --git a/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_markdown_file_browser.py b/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_markdown_file_browser.pyindex b26fa49c2..03d3e72ea 100644--- a/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_markdown_file_browser.py+++ b/python/packages/autogen-ext/src/autogen_ext/agents/file_surfer/_markdown_file_browser.py@@ -17,13 +17,14 @@ class MarkdownFileBrowser:# TODO: Fix unfollowed importdef __init__( # type: ignore- self, viewport_size: Union[int, None] = 1024 * 8+ self, viewport_size: Union[int, None] = 1024 * 8, base_path: str = os.getcwd()):"""Instantiate a new MarkdownFileBrowser.Arguments:viewport_size: Approximately how many *characters* fit in the viewport. Viewport dimensions are adjusted dynamically to avoid cutting off words (default: 8192).+ base_path: The base path to use for the file browser. Defaults to the current working directory."""self.viewport_size = viewport_size # Applies only to the standard uri typesself.history: List[Tuple[str, float]] = list()@@ -31,16 +32,17 @@ class MarkdownFileBrowser:self.viewport_current_page = 0self.viewport_pages: List[Tuple[int, int]] = list()self._markdown_converter = MarkItDown()- self.set_path(os.getcwd())+ self._base_path = base_pathself._page_content: str = ""self._find_on_page_query: Union[str, None] = Noneself._find_on_page_last_result: Union[int, None] = None # Location of the last result+ self.set_path(self._base_path)@propertydef path(self) -> str:"""Return the path of the current page."""if len(self.history) == 0:- return os.getcwd()+ return self._base_pathelse:return self.history[-1][0]