Skip to content

Bug: GenerateImage tool returns relative path causing LLM to hallucinate incorrect domain in async image URL #10

@xinpehr

Description

@xinpehr

Description:

When an image is generated asynchronously (e.g. via fal.ai), the GenerateImage tool returns a relative path (/app/imagine/{id}) instead of a full absolute URL. This causes the LLM to hallucinate a domain name from its training data and construct an incorrect URL in its response to the user.

Steps to Reproduce:

  1. Enable the generate_image tool in an assistant.
  2. Use an async image generation model (e.g. fal.ai).
  3. Ask the assistant to generate an image.
  4. Observe the URL in the assistant's response — the domain is wrong.

Root Cause:

In src/Ai/Infrastructure/Services/Tools/GenerateImage.php, the call() method returns:

'The image is being generated asynchronously. You can view it at: /app/imagine/'
    . $image->getId()->getValue()->toString()
    . '. The image will be ready in a few seconds.'

The relative path is passed as a tool result to the LLM. Since the LLM has no knowledge of the actual deployment domain, it constructs a full URL using a hallucinated domain from its training data.

Expected Behavior:

The tool should return a full absolute URL using the configured site domain and protocol, e.g.:

https://yourdomain.com/app/imagine/{id}

Suggested Fix:

Inject option.site.domain and option.site.is_secure into the GenerateImage class (same pattern already used in src/Ai/Infrastructure/Services/FalAi/Helper.php) and build the full URL before returning it.

Environment:

  • Affects all deployments using async image generation models
  • Severity: Medium — users receive a broken or misleading link in chat

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions