3.1 KiB
3.1 KiB
What was implemented
- A lightweight
DeepAgentbase class and a concreteCustomSearchAgentthat generates deterministic mock search results. - The agent creates virtual files in memory (
self._virtual_files) duringsearch(). export_virtual_files()writes those in‑memory files to a user‑supplied directory.- A CLI entry point (
src/run.py) that runs a search and exports the files. - Unit tests (
tests/test_agent.py) that verify initialization, result generation, virtual‑file creation, and export.
Why the main parts satisfy the requirements
- Virtual file creation –
CustomSearchAgent.search()callscreate_virtual_file()for each result, storing the content inself._virtual_files.for idx, (title, snippet) in enumerate(results, start=1): filename = f"result_{idx}.txt" content = f"Filename: {filename}\nTitle: {title}\nSnippet: {snippet}" self.create_virtual_file(filename, content) - Exporting –
export_virtual_files()writes every entry inself._virtual_filesto disk, creating the directory if needed.for filename, content in self._virtual_files.items(): file_path = out_path / filename file_path.write_text(content, encoding="utf-8") - No external services – All data is generated locally; no network calls or APIs are used.
- Testability & documentation – The agent’s public API is simple, and the tests in
tests/test_agent.pycover all required behaviours. - Executable in the assignment environment – Running
python -m src.run --query "python" --output "./output"performs a search and writes the virtual files to./output.
Short code excerpts
src/agent.py– base class and virtual‑file handlingclass DeepAgent(ABC): def __init__(self) -> None: self._virtual_files: Dict[str, str] = {}src/agent.py– search logic and file creationdef search(self, query: str) -> List[Tuple[str, str]]: results = self._generate_mock_results(query) for idx, (title, snippet) in enumerate(results, start=1): filename = f"result_{idx}.txt" content = f"Filename: {filename}\nTitle: {title}\nSnippet: {snippet}" self.create_virtual_file(filename, content) return resultssrc/run.py– command‑line integrationdef main() -> None: ... agent = CustomSearchAgent() results = agent.search(args.query) ... agent.export_virtual_files(output_dir)
Honest limitations
- The agent does not perform real web searches; it returns deterministic mock data, which is sufficient for the assignment but not for production use.
- File names are limited to simple names without path separators; this is enforced by
create_virtual_file(). - The implementation assumes UTF‑8 encoding for all virtual files.
Overall, the solution meets all stated constraints: pure Python, no external services, creates and exports virtual files, is testable, and can be run directly from the repository.