Building a Long-Horizon AI Agent for E-commerce Product Detail Pages
This article explains why e-commerce content generation is a practical long-horizon agent task, outlines the business requirements and model-selection criteria, presents a planner-executor-reviewer architecture with prompt and Python examples, and shares lessons from building a system that turns rough product specifications into ready-to-publish content packages.
1. Why E-commerce Content Generation Is a Good Test of Model Capability
Before writing code, it is worth discussing a more valuable question: what kind of task can truly test a large model’s engineering capability?
The answer is a long-horizon task.
A long-horizon task is one that cannot be completed with a single prompt. It usually has the following characteristics:
- Multi-step: The task must be broken into multiple dependent subtasks, where the output of one step becomes the input of the next.
- Multi-tool: The process requires calling search engines, image-processing tools, databases, external APIs, and other tools.
- Long duration: The whole task may run for tens of minutes or even hours.
- Frequent exceptions: Network timeouts, data-format errors, and quality failures can occur at any point, requiring autonomous planning, execution, and correction.
Industry research has offered an observation: in areas such as programming, the complexity of tasks that AI can complete with about a 50% success rate—measured by the time a human expert would need for the same task—is growing exponentially, recently doubling roughly every 4 to 6 months. This means models are evolving from “conversational assistants” into “digital labor capable of completing engineering projects independently.”
“Automated e-commerce product content generation” is a typical long-horizon task: it requires understanding selling points, analyzing the target audience, generating titles, writing detail pages, producing marketing copy, performing quality checks, and rewriting when necessary. Each step depends on the previous one, and each step can fail. Practicing with this scenario provides real business value while stress-testing the model.
2. Clarifying the Requirements: What White-Label Products Are Missing
Start with the business pain point. Many small and medium-sized merchants sell white-label products—products without brand premium or a professional copywriting team. Their product detail pages are often just a few images plus dry parameter descriptions, which naturally hurts conversion.
The essence of a “premium brand feel” can be broken down into three things:
- Consistent visual and copy tone: From the title to the detail page, the voice is consistent and has a brand personality.
- Scenario-based selling points: Instead of listing parameters, the copy translates parameters into value the user can perceive.
- Complete trust elements: After-sales commitments, quality-inspection notes, usage tutorials, and other trust-building elements are all in place.
These three things are exactly the kind of structured generation tasks that large models are good at. The goal is therefore clear: take a rough product parameter description as input and output a complete, tonally consistent, ready-to-list product content package.
3. Considerations for Technology Selection
For model selection, I summarized four key evaluation dimensions:
- Long-horizon planning: Can the model reliably decompose a large goal into an executable sequence of subtasks and adjust dynamically during execution?
- Tool-calling reliability: Is structured output—such as JSON-formatted tool-calling instructions—stable, and is the format-error rate low enough?
- Context length and memory: In a long task, can the model remember outputs from earlier steps and avoid contradictions?
- Self-correction: After an error occurs, can the model understand the error message, locate the cause, and fix it instead of spinning in place?
If you prefer local deployment of open-source models for better data privacy—so product data never leaves the internal network—prioritize open-source models that rank well on public long-horizon or agent-task benchmarks. If you choose a cloud API, you may also consider large-model platforms from cloud providers such as Baidu AI Cloud, which often provide stronger engineering, stability, and compliance support. Whichever route you choose, run a small benchmark test with 20 to 30 samples from your own real business before making a decision.
4. System Architecture Design
The overall architecture uses a three-stage design: Planner + Executor + Reviewer. This is a classic Agent-system pattern:
User input (product parameters / image descriptions)│▼┌─────────────┐│ Planner │ Decompose the task: generate a content plan└─────────────┘│▼┌─────────────┐ Call tools: search trends / check competitor copy / template library│ Executor │──► Produce step by step: title → selling points → detail page → after-sales copy└─────────────┘│▼┌─────────────┐│ Reviewer │ Quality checks: prohibited words / consistency / tonal alignment└─────────────┘│Pass ─┴─ Fail ──► Rewrite and retry (up to N times)▼Content package output
Several design points:
1. The Planner uses a “plan-as-data” approach
Let the model first generate a structured task list in JSON rather than starting to write copy directly. This way, each subtask can be executed independently, retried, and cached. If a problem occurs, only the single step needs to be rerun instead of starting over.
2. The Executor has a strict single responsibility
Each execution step does only one thing and produces only one structured result. For example, the output of the “generate titles” step is simply an array of candidate titles and nothing else. The benefit of single responsibility is that errors can be located and quality can be measured.
3. The Reviewer acts as a safety net
The reviewer handles three types of checks: sensitive-word and advertising-compliance checks (for example, superlatives such as “best” or “No.1”), logical-consistency checks (parameters on the detail page must not contradict the input), and tonal-consistency checks (whether all modules use a unified voice). When a review fails, the specific reasons are sent back to the Executor for targeted rewriting. This is exactly where the “self-correction” capability of a long-horizon task comes into play.
5. Key Code Sketch (Prompt Engineering)
The core planning prompt looks roughly like this:
PLANNER_PROMPT = """You are an e-commerce content planning expert. Based on the following product information, output a JSON content generation plan including: 5 title candidates, 3–5 core selling points, detail-page section structure, after-sales trust module, and target audience profile. Output only JSON, nothing else.Product information:{product_info}Target tone: {brand_tone}"""
The execution stage uses a simplified loop:
def run_pipeline(product_info, brand_tone):plan = llm_call(PLANNER_PROMPT.format(product_info=product_info, brand_tone=brand_tone))plan = parse_json(plan) # Retry if parsing failsresults = {}for step in plan["steps"]:draft = executor.run(step, context=results)review = reviewer.check(draft)for _ in range(MAX_RETRY):if review["passed"]:breakdraft = executor.rewrite(step, draft, review["issues"])review = reviewer.check(draft)results[step["name"]] = draftreturn assemble(results) # Assemble into the final content package
6. Pitfalls and Lessons Learned
- Structured output must use defensive parsing: Even strong models sometimes output invalid JSON, so always wrap parsing with retry and repair logic.
- Context trimming is critical: Late in the task, compress earlier finalized content into a summary and inject it into the context. This saves tokens and prevents the model from being distracted by details.
- Do not aim for perfection in one pass: Instead of writing an extremely long prompt to generate everything at once, split the work into smaller steps with generation and review. The success rate is higher.
- Build a human-in-the-loop gate: Keep a manual confirmation step before final publishing. AI handles 90% of the first-draft workload, while humans make the final brand judgment.
7. Final Thoughts
In testing, this system reduced the content production time for one product from 2–3 hours of manual work to under 10 minutes, with copy quality consistently above a usable level. More importantly, this practice made one thing clear: when models have the planning and correction capabilities for long-horizon tasks, the developer’s role shifts from “the person who writes code” to “the person who designs the process.”
If you also have business scenarios with high repetition and long workflows, try the three-stage architecture in this article. Validate with a small sample first, then gradually expand the automation boundary. That is the right way to turn large models into real productivity.
