Fosowl/agenticSeek · error · FileNotFoundError

Prompt file not found at path: {file_path}

Error message

Prompt file not found at path: {file_path}

What it means

load_prompt() reads a prompt template from disk and re-raises FileNotFoundError with the offending path when open() fails because the file does not exist. Agents load their prompt during __init__, so this aborts construction. It exists to give a clearer, path-bearing message than the bare OS error.

Source

Thrown at sources/agents/agent.py:117

        Get the list of tools names.
        """
        return list(self.tools.keys())
    
    def get_tools_description(self) -> str:
        """
        Get the list of tools names and their description.
        """
        description = ""
        for name in self.get_tools_name():
            description += f"{name}: {self.tools[name].description}\n"
        return description
    
    def load_prompt(self, file_path: str) -> str:
        try:
            with open(file_path, 'r', encoding="utf-8") as f:
                return f.read()
        except FileNotFoundError:
            raise FileNotFoundError(f"Prompt file not found at path: {file_path}")
        except PermissionError:
            raise PermissionError(f"Permission denied to read prompt file at path: {file_path}")
        except Exception as e:
            raise e
    
    def request_stop(self) -> None:
        """
        Request the agent to stop.
        """
        self.stop = True
        self.status_message = "Stopped"
    
    @abstractmethod
    def process(self, prompt, speech_module) -> str:
        """
        abstract method, implementation in child class.
        Process the prompt and return the answer of the agent.
        """

View on GitHub (pinned to ae57a23577)

Solutions

  1. Correct the path — use an absolute path (e.g. Path(__file__).parent / "prompts" / "system.txt") instead of a CWD-relative one.
  2. Verify the file exists: os.path.isfile(file_path) or `ls` the directory before constructing the agent.
  3. If packaged/deployed, ensure prompt files are included in the build (package data, Docker COPY).
  4. Check filename spelling and case against the actual file on disk.

Example fix

// before
agent = Agent(prompt_path="prompts/system.txt")  # FileNotFoundError if CWD differs
// after
from pathlib import Path
prompt = Path(__file__).parent / "prompts" / "system.txt"
agent = Agent(prompt_path=str(prompt))
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
def resolve_prompt(name: str) -> str:
    p = Path(__file__).parent / "prompts" / name
    if not p.is_file():
        raise FileNotFoundError(f"Prompt missing before Agent init: {p}")
    return str(p)
agent = Agent(prompt_path=resolve_prompt("system.txt"))

Try / catch

try:
    agent = Agent(prompt_path=path)
except FileNotFoundError as e:
    if "Prompt file not found" in str(e):
        logger.error("Prompt file missing: %s — check CWD and packaging", path)
        fallback = Path(__file__).parent / "prompts" / "default.txt"
        agent = Agent(prompt_path=str(fallback))
    else:
        raise

Prevention

When it happens

Trigger: Calling agent.load_prompt(file_path) — directly or via __init__ — when file_path points to a nonexistent file (typo, wrong working directory, file not shipped/created yet).

Common situations: Relative path resolved against a different CWD than expected (running from repo root vs. package dir); prompt file excluded from package/docker build; renamed or moved prompts directory; OS case-sensitivity mismatch (Linux vs. Windows filenames).

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of Fosowl/agenticSeek@ae57a23577 (2026-08-30). Data as JSON: /api/errors/b18516381b7e269f. Report an issue: GitHub.