langchain-ai/deepagents · error · ChannelMediaError

media file does not exist: {path}

Error message

media file does not exist: {path}

What it means

After resolving and validating the media path, `validate_media` checks `path.is_file()`. If the resolved path does not exist or is not a regular file, it raises `ChannelMediaError` with the resolved path in the message. This prevents sending nonexistent or special-file paths over a channel.

Source

Thrown at libs/talon/deepagents_talon/channels/base.py:266

    Returns:
        The validated media payload.

    Raises:
        ChannelMediaError: If the file is missing, unsupported, or too large.
    """
    try:
        path = (
            resolve_bounded_media_path(media.path, root, require_relative=False)
            if root is not None
            else media.path.expanduser()
        )
    except ValueError as exc:
        msg = str(exc)
        raise ChannelMediaError(msg) from exc
    if not path.is_file():
        msg = f"media file does not exist: {path}"
        raise ChannelMediaError(msg)

    detected = _media_type(path)
    if detected != media.media_type:
        msg = f"media file type {detected!r} does not match requested type {media.media_type!r}"
        raise ChannelMediaError(msg)

    return _validate_media_size(media, path=path, max_bytes=max_bytes)


def message_with_media_paths(
    message: ChannelMessage,
    *,
    media_paths: Sequence[str],
    mime_types: Sequence[str] = (),
    has_media: bool | None = None,
) -> ChannelMessage:
    """Return `message` with normalized inbound-media path metadata.

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Check `Path(media.path).is_file()` before calling and create/fix the file if missing.
  2. Verify the working directory and that relative paths resolve under the expected root.
  3. Catch `ChannelMediaError` and return a user-facing 'attachment not found' message.

Example fix

# before
await channel.send_media(ChannelMedia(path=Path('out.png'), media_type='image'))

# after
path = Path('out.png')
if not path.is_file():
    raise FileNotFoundError(f'generate {path} before sending')
await channel.send_media(ChannelMedia(path=path, media_type='image'))
Defensive patterns

Strategy: validation

Validate before calling

path = Path(media.path)
if not path.is_file():
    raise FileNotFoundError(f'media file missing before send: {path}')

Type guard

def is_readable_file(p: Path) -> bool:
    try:
        return p.is_file()
    except OSError:
        return False

Try / catch

try:
    await channel.send_media(media)
except ChannelMediaError as exc:
    if 'does not exist' in str(exc):
        await channel.send_text('Attachment is no longer available.')
    else:
        raise

Prevention

When it happens

Trigger: Calling `validate_media`/`send_media` with a `ChannelMedia` whose `path` points to a file that does not exist, was deleted/moved before send, or is a directory/socket rather than a regular file.

Common situations: Generating a screenshot/PDF then sending before it is written; relative path resolved against the wrong working directory; typo in filename; temp file cleaned up by a prior step.

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 langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/3e8802bb128d6ecf. Report an issue: GitHub.