MediaAgent: Building a Brain for ComfyUI in Rust to Fully Automate Workflows

MediaAgent uses Rust and AI agents to fully automate ComfyUI workflows with a single natural language command.
MediaAgent is an open-source project that adds an AI "brain" to ComfyUI using a Rust-based Agent OS called Gliding Holes. It combines a PTCA (Plan-Take-Check-Adjust) loop with JSON-LD semantic workflows to automatically select models, tune parameters, generate images, and retry on failure — all from a single natural language instruction.
From Manual Craftsmanship to Automated Pipelines
Anyone who has used ComfyUI has probably been through this: trying to build a working image generation workflow, only to spend an entire afternoon debugging because one node port was connected wrong. ComfyUI is a Stable Diffusion frontend built on a Node Graph paradigm — a design borrowed from professional VFX software like Nuke and Blender Compositor. Each node represents an independent computational unit, and nodes pass tensors, images, or parameter data between each other through "ports." The upside is fine-grained, visual control over data flow. The downside is a steep learning curve: users need to understand concepts like Latent Space, VAE encoding/decoding, and Samplers before they can connect nodes correctly and get the results they want.
ComfyUI's power lies in the creative freedom its node-based design provides — but that freedom comes at the cost of tedious manual setup and endless parameter tuning.
One Bilibili creator has his own answer to this problem. He built a project called MediaAgent in Rust, with a single core idea: "Can we let AI handle all of this itself?"

A traditional ComfyUI workflow is essentially "static" — whatever you build is what runs. Once the parameters, models, and connections are locked in, there's no room for adaptation. What MediaAgent aims to do is give ComfyUI a "brain," transforming it from a passive execution tool into an intelligent agent capable of actively planning, executing, inspecting, and adjusting on its own.
Under the Hood: An Agent OS Built in Rust
MediaAgent isn't a standalone script. Its foundation is an AI Agent operating system written in Rust by the author, codenamed Gliding Holes (流码). The choice of Rust is deliberate. Rust is a systems programming language developed by Mozilla Research, and its defining feature is an "Ownership" memory model that enforces memory safety at compile time without a garbage collector (GC). In AI Agent scenarios, this matters a great deal: Agent systems need to run for extended periods while concurrently scheduling multiple subtasks — managing image generation queues, monitoring output quality, maintaining workflow state, and more. The stop-the-world pauses of GC-based languages like Python or Go can introduce task scheduling latency in these situations. Rust's zero-cost abstractions and deterministic memory deallocation make it an ideal foundation for building highly reliable, low-latency Agent infrastructure. In scenarios requiring high concurrency, high reliability, and fine-grained control over system resources, these advantages translate directly into a stable, long-running Agent scheduling system.
The entire system comes down to two key pillars:
The PTCA Loop: Giving Agents True Autonomy
The PTCA loop is the core mechanism behind MediaAgent's autonomy. It describes the closed-loop process an Agent goes through when handling a task: Plan, Take/Act, Check, and Adjust. At an academic level, this design is closely related to the ReAct (Reasoning + Acting) framework proposed in 2022 by a Princeton University team. ReAct's core idea is to have large language models alternate between "Thought" and "Action," incorporating environmental feedback (Observation) into the next round of reasoning to form a closed loop. Unlike pure Chain-of-Thought approaches, agents in the ReAct framework actually call external tools and process their return values. The PTCA loop further refines the "Check" and "Adjust" phases, making it particularly well-suited for image generation — a domain where you need to evaluate output quality and dynamically correct your strategy based on that evaluation. This is fundamentally different from a one-shot script: the Agent dynamically decides what to do next based on the result of each step, retrying on failure and adjusting parameters when the output isn't good enough.

JSON-LD Semantic Workflows: Letting AI Actually "Understand" Tasks
The other core innovation is using JSON-LD to describe semantically rich workflows. JSON-LD (JSON for Linked Data) is a semantic web standard officially recommended by the W3C in 2014. Its core idea is to embed semantic annotations like @context (context) and @type (type) within JSON data structures, allowing machines to understand the meaning of data items rather than just reading their values. In a native ComfyUI workflow, the relationships between nodes are expressed as a graph structure (node ID + port index), which makes it difficult for an AI to infer whether a given step is doing style transfer or super-resolution reconstruction. JSON-LD semantic workflows solve this by attaching semantic labels to each step (e.g., "task:StyleTransfer", "task:Upscale"), enabling large language models to reason about, decompose, and reassemble workflows based on natural language understanding. Compared to ComfyUI's native node-and-wire representation, JSON-LD provides a semantic-level workflow definition — the Agent can "understand" the purpose and intent of each stage in the workflow, rather than just mechanically following a graph. This semantic expressiveness also makes it much easier for AI to reason about, modify, and recombine workflows, which is the very foundation of autonomous planning.
Real-World Experience: Ghibli-Style Transfer With a Single Sentence
What does this system actually feel like to use? The author walks through a concrete example: just tell MediaAgent "turn this photo into Ghibli style at 2K resolution," and hand everything else off to it.

Behind the scenes, MediaAgent automatically handles all of the following:
- Automatically selects the right model — matches a model to the style transfer requirement;
- Automatically adjusts parameters — including resolution, sampling steps, and other key settings;
- Automatically runs the generation and checks the result — evaluates output quality after generation;
- Automatically retries if unsatisfied — adjusts strategy and regenerates if the result doesn't meet expectations.
The entire process requires zero human intervention. This effectively upgrades ComfyUI from a "manual workshop" that requires specialized knowledge to operate, into a self-optimizing automated pipeline. For users who aren't familiar with node-based workflows and just want a finished image quickly, this interaction model dramatically lowers the barrier to entry.
What It Means to Give ComfyUI a Brain

The significance of MediaAgent goes beyond simply "saving effort" — it represents a fundamental shift in how we interact with AI tools: from humans adapting to tools, to tools adapting to humans.
In the past, getting good results from ComfyUI required learning its node logic, understanding the characteristics of different models, and accumulating hands-on experience with parameter tuning. With an Agent layer, that specialized knowledge gets encapsulated inside the AI's "brain," and users only need to express their intent in natural language. This aligns perfectly with the broader trend toward agentic AI — since 2024, leading organizations like OpenAI, Anthropic, and Google have all invested heavily in expanding their models' tool-calling (Function Calling / Tool Use) capabilities, enabling models to proactively call external APIs, execute code, and operate file systems. The industry broadly believes that the future competition in AIGC won't be limited to the raw generation quality of individual models, but will center on "the degree of end-to-end creative process automation" — that is, whether the full pipeline from user intent to finished output can be completed seamlessly and automatically. MediaAgent sits squarely within this context, enabling AI not just to answer questions, but to autonomously complete complex sequences of operational tasks.
Of course, projects like this are still in an exploratory phase. The accuracy and reliability of automatic model selection and parameter tuning depend heavily on the planning capabilities of the underlying Agent and the depth of its understanding of workflow semantics. How the "Check" phase of the PTCA loop accurately assesses image quality, and how the "Adjust" phase reliably converges toward ideal results, are both key challenges that warrant continued refinement.
Open Source and What's Next
It's worth noting that the MediaAgent project is already open source on GitHub. Interested developers can find the relevant repositories by searching for Doito MediaAgent or Doito Gliding Holes — the author welcomes Stars and contributions.
For AIGC creators, heavy ComfyUI users, and developers interested in Agent systems, this is a direction worth watching. It takes the somewhat abstract concept of "AI Agent" and grounds it in a concrete, pain-point-driven use case: making image generation workflows truly automated.
As the underlying Agent OS matures, this approach may not stay limited to image generation — it could expand to video generation, audio processing, and other areas of media creation. When every professional tool can be given a "brain," the barrier to creative work will drop even further.
Key Takeaways
Related articles

Pinery Prose: Redefining the AI Book-Writing Experience with Diff Review
Pinery Prose is a Mac AI book-writing assistant using code diff review mechanics, letting authors accept or reject each AI edit. Supports Markdown, ePub/PDF export, and covers the full self-publishing workflow.

How Developer Productivity Startups Boost Their Own Efficiency: Practicing What You Preach
How developer productivity startups practice what they preach—from automated toolchains and DORA metrics to engineering culture that shortens feedback loops and reduces cognitive load.

Laxis Review: Bot-Free Meeting Notes & Real-Time Translation AI Tool
In-depth review of Laxis AI meeting tool: bot-free recording, 100+ language real-time translation, voice dictation 4x faster than typing. Features, competitors & value analysis.