feat(platform/blocks): add AI Image Editor Block powered by flux kontext (#10063)

<!-- Clearly explain the need for these changes: -->

This PR adds a new internal block, **AI Image Editor**, which enables
**text-based image editing** via BlackForest Labs’ Flux Kontext models
on Replicate. This block allows users to input a prompt and optionally a
reference image, and returns a transformed image URL. It supports two
model variants (Pro and Max), with different cost tiers. This
functionality will enhance multimedia capabilities across internal agent
workflows and support richer AI-powered image manipulation.

---

### Changes 🏗️

* Added `FluxKontextBlock` in `backend/blocks/flux_kontext.py`

  * Uses `ReplicateClient` to call Flux Kontext Pro or Max models
* Supports inputs for `prompt`, `input_image`, `aspect_ratio`, `seed`,
and `model`
  * Outputs transformed image URL or error
* Added credit pricing logic for Flux Kontext models to
`block_cost_config.py`:

  * Pro: 10 credits
  * Max: 20 credits
* Added documentation for the new block at
`docs/content/platform/blocks/flux_kontext.md`
* Updated block index at `docs/content/platform/blocks/blocks.md` to
include Flux Kontext

---


![image](https://github.com/user-attachments/assets/0edb2b30-4c37-4184-bcc8-9d733658f620)


### Checklist 📋

#### For code changes:

* [x] I have clearly listed my changes in the PR description
* [x] I have made a test plan
* [x] I have tested my changes according to the test plan:

  <!-- Put your test plan here: -->

  * [x] Prompt-only input generates an image
  * [x] Prompt with image applies edit correctly
  * [x] Image respects specified aspect ratio
  * [x] Invalid image URL returns helpful error
  * [x] Using the same seed gives consistent output
* [x] Output chaining works: result URI can be used in downstream blocks
  * [x] Output from Max model shows higher fidelity than Pro

<details>
  <summary>Example test plan</summary>

* [x] Create from scratch and execute an agent using Flux Kontext with
at least 3 blocks
* [x] Import agent with Flux Kontext from file upload, and confirm
execution
* [x] Upload agent (with Flux Kontext block) to marketplace (internal
test)
* [x] Import agent from marketplace and confirm correct execution
* [x] Edit agent with Flux Kontext block from monitor and confirm output

</details>

#### For configuration changes:

* [x] `.env.example` is updated or already compatible with my changes
* [x] `docker-compose.yml` is updated or already compatible with my
changes
* [x] I have included a list of my configuration changes in the PR
description (under **Changes**)

  * No new environment variables or services introduced

<details>
  <summary>Examples of configuration changes</summary>

* N/A

</details>

---------

Co-authored-by: Zamil Majdy <zamil.majdy@agpt.co>
This commit is contained in:
Toran Bruce Richards
2025-06-02 21:46:48 +01:00
committed by GitHub
parent 0ec557b942
commit 3f6585f763
4 changed files with 231 additions and 0 deletions

View File

@@ -86,6 +86,7 @@ Below is a comprehensive list of all available blocks, categorized by their prim
| [Unreal Text to Speech](text_to_speech_block.md#unreal-text-to-speech) | Converts text to speech using Unreal Speech API |
| [AI Shortform Video Creator](ai_shortform_video_block.md#ai-shortform-video-creator) | Generates short-form videos using AI |
| [Replicate Flux Advanced Model](replicate_flux_advanced.md#replicate-flux-advanced-model) | Creates images using Replicate's Flux models |
| [Flux Kontext](flux_kontext.md#flux-kontext) | Text-based image editing using Flux Kontext |
## Miscellaneous
| Block Name | Description |

View File

@@ -0,0 +1,31 @@
# Flux Kontext
## What it is
An internal block that performs text-based image editing using BlackForest Labs' Flux Kontext models.
## What it does
Takes a prompt describing the desired transformation and optionally a reference image, then returns a new image URL.
## How it works
The block sends your prompt, image, and settings to the selected Flux Kontext model on Replicate. The service processes the request and returns a link to the edited image.
## Inputs
| Input | Description |
|--------------|-----------------------------------------------------------------------------|
| Credentials | Replicate API key with permissions for Flux Kontext models |
| Prompt | Text instruction describing the desired edit |
| Input Image | (Optional) Reference image URI (jpeg, png, gif, webp) |
| Aspect Ratio | Aspect ratio of the generated image (e.g. match_input_image, 1:1, 16:9, etc.) |
| Seed | (Optional, advanced) Random seed for reproducible generation |
| Model | Model variant to use: Flux Kontext Pro or Flux Kontext Max |
## Outputs
| Output | Description |
|------------|------------------------------------------|
| image_url | URL of the transformed image |
| error | Error message if generation failed |
## Use Cases
- Enhance a marketing image by requesting "add soft lighting and a subtle vignette" while providing the original asset as the reference image.
- Generate social media assets with specific aspect ratios and style prompts.
- Apply creative edits to product photos using text instructions.