Building Agent Systems Faster with AI Coding: From Workflow Orchestration to Modular Skills
This article walks through a real-world migration from low-code workflow orchestration to a modular Agent system, and explains how AI coding tools can compress a multi-week refactor into a few days. It covers the business requirements, key challenges such as state management and bounded planning, a five-layer target architecture, illustrative Python code, enterprise deployment practices, and the design principles that make the migration sustainable.
1. Introduction: From Workflow Orchestration to Modular Agents
As business complexity grows and technology stacks evolve quickly, low-code workflow orchestration solutions often run into limited scalability, poor logic reuse, and opaque debugging paths. When requirements shift from “single-shot generation” to “multi-turn interaction, multi-model collaboration, and multi-tool invocation,” the architecture has to make a leap: from a monolithic flow to a modular skill system, from hard-coded branches to intelligent planning, and from private integrations to standardized protocol interconnections.
Using a typical architecture migration as the background, this article discusses how to refactor and launch an Agent system within days with the help of AI coding tools, and presents actionable design principles along with illustrative implementations.
2. Business Scenario and Core Requirements
The target system accepts a single natural-language description from an operations user, for example “generate a venue for the summer camping scenario,” and then runs the following pipeline:
- Intent understanding: identify key elements such as the shopping scenario, categories, and attributes;
- Scene generation: produce structured content such as the title, copy, and tags;
- Tag expansion: generate second-level keywords from first-level tags;
- Product matching: retrieve products with the second-level keywords and apply relevance filtering;
- Result persistence: output a complete data structure that can be used directly to build the venue template.
The system must also satisfy six capability requirements:
- Multi-turn dialogue: support progressive refinement and repeated revisions;
- Intent recognition and content generation: handled by a large language model for semantic understanding and creative output;
- Multi-agent collaboration: connect to external agents such as product completion and relevance filtering through standard protocols;
- Tool and knowledge integration: connect search, caching, knowledge base retrieval, and link content extraction through a standard context protocol;
- Persistence: store scenes, products, and workflow state;
- Enterprise-grade deployment: support multiple machines, log retrieval, and trace-based observability.
3. Reframing the Key Challenges
3.1 Complex State Management
Multi-turn dialogue means state is no longer a local variable within a single request, but a persisted entity that spans machines and sessions. Three design points matter:
- State layering: separate “short-term session memory,” “intermediate task artifacts,” and “final business results” to avoid context pollution;
- Token budget: summarize and compress historical messages, replacing them with structured forms, and keep only the information required for decisions;
- Recoverability: write a checkpoint before each node executes, so a failure can resume from the most recent node.
An illustrative state structure:
class SessionState(TypedDict, total=False):session_id: struser_intent: dict # structured intentscene_draft: dict # scene draftkeywords: list[str] # second-level keywordsproducts: list[dict] # candidate productsbudget: int # remaining token budgetcheckpoint: str # resume node
3.2 Controllable Intelligent Planning
The flow should be neither fully decided by the model nor fully hard-coded. The recommended approach is “bounded planning”: the main agent chooses the next step from a limited set of actions, where the action set is exactly the modular skills. This preserves flexibility while static validation can guarantee convergence and testability.
3.3 Decoupling Tools and External Agents
Capabilities such as search, cache writes, knowledge base queries, and link content re-creation cause strong coupling and duplicated effort if they are hard-coded in a private way. After adopting a standard context protocol and an inter-agent communication protocol, tools and agents become “capability units” that are registrable, reusable, and replaceable.
4. Target Architecture: Skill System + Intelligent Planning + Protocol Interconnection
The architecture has five layers:
- Access layer: session entry, authentication, and rate limiting;
- Orchestration layer: the main agent handles planning, scheduling, and result aggregation;
- Skill layer: atomic skills such as intent recognition, scene generation, tag expansion, product retrieval, and content re-creation;
- Protocol layer: a standard context protocol connects tools and knowledge, while an inter-agent protocol connects external agents;
- Infrastructure layer: persistent storage, cache, message queue, container platform, logging service, and monitoring and alerting.
An illustrative main loop:
async def run(state: SessionState):while not is_done(state):action = planner.choose(state, allowed=SKILLS) # bounded planningresult = await SKILLS[action](state) # skill executionstate = reducer(state, result) # state mergeawait saver.put(state.session_id, state) # checkpointreturn state["scene_draft"]
Skills expose a unified contract, which makes them easy to replace and test:
@skill("keyword_expand")async def keyword_expand(state: SessionState) -> dict:tags = state["scene_draft"]["tags_l1"]return {"keywords": await llm.expand(tags, n=5)}
5. How AI Coding Compresses the Refactor Cycle
The value of AI coding tools is not “automatically generating all the code,” but parallelizing the repetitive, context-heavy work in a refactor:
- Skeleton generation: batch-generate skill templates, type definitions, and unit tests from interface contracts;
- Migration rewriting: map existing flow nodes to skills one by one while keeping input and output contracts unchanged;
- Contract validation: automatically generate request and response models for the protocol layer, plus compatibility checks;
- Observability integration: add logging, metrics, and trace fields in bulk;
- Documentation sync: generate interface descriptions and runbooks from code changes.
The practical recommendation is to move in small, fast steps: migrate only one skill at a time, get the contract tests passing first, then plug it into the main loop, and finally switch traffic over. Completing the overall refactor within a few days is feasible this way, provided that contracts come first and tests act as a safety net.
6. Enterprise Deployment Essentials
- Separate storage for state and results: hot data goes to cache, persistent data goes to object storage or a database;
- Asynchronous decoupling: use a message queue to smooth peaks for the time-consuming product matching step;
- Observability: a unified trace identifier runs through sessions, nodes, and tool calls, with logs centrally searchable;
- Canary release and rollback: roll out by session dimension and keep a switch for the old pipeline;
- Cost control: track tokens and call volume per node, and set budget-based circuit breaking.
7. Conclusion
The essence of this migration is to break “flows” into “capabilities,” replace “branches” with “planning,” and replace “private integrations” with “standard protocols.” Only once the architecture is modular and standardized can AI coding tools compress a refactor from weeks to days. For teams that want to build similar systems on cloud environments such as Baidu AI Cloud, the recommendation is to solidify contracts and tests first, then gradually introduce intelligent planning and protocol interconnection, so the Agent engineering capability can evolve sustainably.
