How Alibaba’s “Yuanfang” Agent System Enables Reliable AI Coding for Complex Ad Engines

This article details Alibaba‑Mama’s AI‑coding initiative, describing how a decoupled CommonAds architecture and a multi‑agent framework called “Yuanfang” transform large‑scale advertising engine development by integrating AI‑friendly design, context‑driven specifications, and automated code‑generation, testing, and validation pipelines.

Alimama Tech
Alimama Tech
Alimama Tech
How Alibaba’s “Yuanfang” Agent System Enables Reliable AI Coding for Complex Ad Engines

Introduction

With the rapid rise of large‑model technology, AI coding has become a key lever for boosting R&D efficiency, yet applying generic AI programming models to massive, complex production systems often results in "usable but not reliable" outcomes. Challenges include limited performance on intricate tasks, reliance on manual prompt engineering, and a lack of understanding of private code‑base semantics.

AI‑Friendly Architecture

Alibaba‑Mama built a three‑year CommonAds development platform that emphasizes clear module decoupling, unified interfaces, and traceable context, providing a solid foundation for high‑quality, trustworthy code generation. The platform consists of four layers:

Util Layer : generic tooling and framework capabilities.

Helper Layer : atomic table operations for user convenience.

Operator Layer : custom operators that encapsulate specific business logic.

Sub‑graph Layer : external graph definitions that serve as the basic deployment unit.

Each layer has a single responsibility, clear interfaces, fine‑grained code, rich comments, and deterministic task decomposition, making it highly AI‑friendly.

Multi‑Agent Solution

The "Yuanfang" system follows three design principles:

Specification‑Driven : AI generation is constrained by strict coding specs, creating a positive feedback loop of spec → generation → interface improvement.

Context Engineering : Rich, structured context (knowledge bases, code‑base semantics) is injected into prompts to guide the model.

Agent‑First : Agents act as intelligent entities capable of reasoning, planning, and decision‑making, extending AI beyond simple "prompt‑in, code‑out".

The workflow splits the overall development process into clear stages, each handled by a dedicated agent (plan generation, interface retrieval, code generation, test generation, verification, and validation), with context knowledge dynamically loaded from a memory store.

Engineering Practice with IFLOW‑CLI and MCP Server

Integration with IFLOW‑CLI provides a unified development environment where developers can compile, build, and run code. The system exposes:

Servers : multiple MCP servers synchronized to the local IFLOW workspace.

Tools : reusable specifications, interface lookup, and other capabilities packaged as CLI tools.

Agents : specialized agents for complex workflows and iterative fixing.

Hooks : mechanisms for pulling configurations, uploading logs, etc.

Memory : a knowledge base of CommonAds concepts, interfaces, and domain jargon.

Full Demo: From Requirement to Code

A concrete requirement (adjusting parameters for specific advertisers in certain traffic scenarios) is fed into the "Plan Generation Agent", which produces a detailed coding plan covering functional description, data structures, execution steps, reusable interfaces, and sample code.

子图:广告主 × 流量场景xxx参数调整能力
1. 背景与目标
当前观测到,在部分流量场景下 xxx参数存在低估,为优化商业效果,需在特定流量场景下,对符合条件的广告主进行参数调整,以优化广告展现效果。
2. 功能逻辑说明
系统需执行以下逻辑:
2.1 判断是否命中参数调整策略:
    ○ 根据当前请求的 流量场景 code 和 广告主id,组合生成 query_key,规则如下:
    ○ 查询广告主黑名单数据表,若 query_key 存在于表中,则跳过系数调整;
    ○ 若不在黑名单中,则继续下一步。
2.2 获取并应用参数修改:
    ○ 从实验参数配置中读取两个动态参数:
        ■ target_code:目标流量场景 code(整型)
        ■ ratio:参数提升系数(浮点型,如 1.3 表示参数 ×1.3)
    ○ 若当前请求的 流量场景 code 等于 target_code,则将原始算法参数乘以 ratio 作为最终参数;
    ○ 否则,保持原始参数不变;

The plan is then consumed by the "Interface Retrieval Agent" to locate high‑quality reusable APIs in the CommonAds codebase, followed by the "Code Generation Agent" which outputs both Python and C++ implementations. Subsequent agents generate unit tests, run coverage verification tools, and perform "try‑verify‑correct" cycles to iteratively improve the code.

Results

Code style and conventions fully align with the CommonAds repository.

Existing high‑quality interfaces are reused, avoiding duplicate effort.

Functions are fine‑grained with comprehensive comments.

Unit tests are uniform, with high coverage ensuring robustness.

Most of the workflow is automated, requiring minimal human intervention beyond requirement clarification.

Future Outlook

To further solidify the AI‑friendly foundation, the team plans to:

Extend the end‑to‑end intelligent development pipeline (requirement → experimental branch).

Continuously enrich specifications, knowledge bases, and automation tools.

Refactor legacy, tightly‑coupled code using an "architect‑led, AI‑executed" collaborative model to improve readability and AI accessibility.

Overall, the "Yuanfang" multi‑agent system demonstrates that with a well‑designed, AI‑friendly architecture and rigorous context‑driven specifications, large‑scale AI coding can become reliable and scalable in production environments.

AI codingmulti‑agent systemsoftware automationCommonAdsIFLOW‑CLIlarge‑model engineering
Alimama Tech
Written by

Alimama Tech

Official Alimama tech channel, showcasing all of Alimama's technical innovations.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.