An AI Agent for Automatic Build Plan Generation in 4X Strategy Games
This article presents a practical approach to building an AI agent that automatically generates opening build plans for 4X strategy games. It breaks the design into four layers—knowledge, data, reasoning, and feedback—and walks through how to teach build principles to the agent iteratively, pull up-to-date game numbers at runtime, force multiple distinct candidate plans and select the best by a unified scoring framework, and structure the output for traceability. It also discusses the agent's capability boundaries in the absence of a programmatic execution environment, and how structured feedback and lightweight regression testing help the generator improve over time. Readers will come away with a reusable architecture pattern for building domain decision-assistant agents.
1. Background: Why Strategy Game Builds Are a Good Fit for Agents
In 4X strategy games (eXplore, eXpand, eXploit, eXterminate), the opening build is critical to the outcome of a match. Army composition, technology order, hero progression paths, and economic pacing all constrain one another—if any single element falls out of balance, you can lose ground to your opponent by the mid-game. Yet for a long time, build ideas could only rely on strategy guides or community experience posts: they are static text, hard to query automatically for the latest numbers, and hard to tailor to “this map, this opponent, this victory condition.”
Agent applications offer a new approach to this kind of decision problem. At its core, an agent is “a reasoning engine + external knowledge + tool calls + output constraints”:
- The reasoning engine handles generalization and trade-offs;
- External knowledge gives conclusions a data basis;
- Tool calls fetch the latest information at runtime;
- Output constraints keep results usable, comparable, and traceable.
Using an automatic build generator for this type of strategy game as a case study, this article breaks the design down layer by layer: architecture, knowledge injection, data acquisition, multi-plan generation, capability boundaries, and iterative validation. This practice relies on no specific product or platform—it needs only general agent capabilities and an accessible data source.
2. Overall Architecture: Four Layers
The generator can be abstracted into four layers:
- Knowledge layer: Encodes personal build experience, character design, and scoring criteria as reusable instructions in the form of “skills”;
- Data layer: Automatically pulls numerical data for units, technologies, and equipment from public community databases at runtime, ensuring references stay consistent with the current version;
- Reasoning layer: Generates multiple candidate plans with distinct main strategies under skill constraints, then scores them and selects the best by a unified standard;
- Feedback layer: Feeds real-match results and improvement notes back into the skills, so capabilities keep evolving with use.
User constraints (map / opponent / goal / personal preference)│▼┌───────────────────┐ Skill loading (role + hard requirements + scoring rules)│ Knowledge layer │◄──────────── Feedback loop (post-match review)└─────────┬─────────┘▼┌───────────────────┐ Runtime fetch → parse → version tagging → cache validation│ Data layer │└─────────┬─────────┘▼┌───────────────────────────────────────────────────────────────┐│ Reasoning layer: interpret constraints → generate N candidates ││ → unified scoring → select best → structured output │└─────────┬─────────────────────────────────────────────────────┘▼Build report (version, scores, assumptions, risk notes)
This layered approach mirrors the layered architecture in software engineering: knowledge is replaceable, data is updatable, reasoning is re-runnable, and feedback is traceable.
3. Knowledge Layer: Teaching Build Ideas to the Agent
3.1 Iterative Teaching, Not a One-Shot Instruction
Personal experience is often tacit: when a veteran player judges whether “this build holds up,” they rely on pattern recognition accumulated over years, which is hard to explain fully at once. A workable approach is to treat the agent as an assistant you need to coach, working through it in stages:
- Express: Explain the core principles in your own words—for example, a single-unit-type main force, heroes as support, and prioritizing technology to unlock key unit types;
- Restate: Have the agent restate them in its own words and proactively point out contradictions and gaps;
- Interrogate: Ask reverse questions on key points such as unit counters, resource curves, and tech pacing to expose the ambiguous areas;
- Solidify: Once confirmed correct, write the current understanding into a skill file as the baseline for all subsequent generations.
The idea of “teaching it a little at a time” is exactly this. Accumulating experience is an ongoing process, and a skill file is more like a design document that is continually revised than a one-time prompt.
3.2 Structured Design of the Skill File
To prevent the skill from degrading into lengthy prose, a modular structure is recommended, separating “must do” from “can vary”:
skill: auto-build-plannerversion: 1.0role: Senior strategy game build consultant, balancing executability with trade-off logicgoals:- Provide a directly executable opening build for a given situation based on the current data version- Each plan explains its core idea, key milestones, and risk pointshard_rules: # Hard requirements: must be satisfied on every generation- Produce at least 3 candidate plans with distinct main strategies, then select the best- List the specific reasons each plan was rejected- Any cited numbers must come from the data pulled in this run, with the data version noted- Hero-related advice is only supplementary and must not serve as the core build- Default to a "single-unit-type main force + hero support" framework unless the user requests otherwisepreferences: # Soft preferences: can be overridden by user constraintsunit_count: single # single | dualmount: any # any | flying | vehicleoutput_schema: build_report_v1scoring:dimensions: [feasibility, resilience, economy, synergy, data_support]open_questions: # Registered but not yet covered mechanics- Special economic mechanics (e.g., special classes, trade-route systems)- Hero equipment, ruler-type traits, and faction-specific objective systems- Unit formation counts, mount candidates
This structure has four benefits:
- Hard requirements are auditable, scoring rules are adjustable, and open questions are always visible;
- Skills are split into files by responsibility (role, rules, scoring, output format), making individual edits and version comparison easy;
- Uncovered mechanics are not silently ignored during generation but are explicitly presented as “open questions”;
- Once a new mechanic is clarified, you only need to append a rule or an entry.
3.3 Express Methodology Through Constraints, Not by Listing Conclusions
What is truly valuable in a skill is not conclusions like “unit X is very strong,” but the methods of judgment. For example, you can write:
- In the opening, first determine the main unit type, then work backward from its unlock conditions to derive the order of technologies and buildings;
- If a key unit type requires a specific resource or prerequisite technology, assess whether it can take shape within the target pacing; if not, switch to an alternative;
- The hero’s role is to fill gaps and amplify, and should not carry the main output;
- When facing a high-frequency enemy that counters your main unit type, keep an adjustment window rather than betting everything at once.
These rules describe a reasoning process that can transfer to new data versions; the specific numbers are provided by the data layer at runtime.
4. Data Layer: Keeping Build References Fresh
4.1 Runtime Fetch, Not Hardcoding Numbers into the Skill
Build conclusions depend heavily on numbers, such as a unit’s attack and defense, cost, maintenance fee, technology prerequisites, and unlock time. Version updates frequently adjust balance, and once numbers are written into the skill, they quickly become outdated. The key design of this generator is:
- Every run automatically accesses public community databases and parses the currently available structured data;
- The skill file stores only methods of judgment, not specific numbers;
- Parsed results are uniformly normalized into an internal data structure, tagged with a version and timestamp.
# The following is illustrative code: `fetch` denotes a generic data-request capability;# the actual implementation depends on the runtime environmentdef load_game_data(source, version="latest", cache_ttl=3600):"""Fetch and normalize game data; prefer a non-expired cache, fall back to cache on failure, otherwise abort"""cached = cache.get(version)if cached and not cached.is_expired(cache_ttl):return cachedtry:raw = fetch(source, params={"version": version})except FetchError:if cached:return cached.with_flag("stale") # Mark data as potentially outdatedraise DataUnavailableError("Data source unavailable and no usable cache")data = normalize(raw) # Standardize field naming, types, and unitsvalidate(data) # Validate completeness of key fieldscache.set(version, data, ttl=cache_ttl)return data
4.2 Multi-Version Data: From “Always Latest” to “Select on Demand”
Data sources usually carry both stable and beta data. Once both are included as options, the generator can:
- Use stable data by default to ensure plans apply to most people;
- Switch to beta data and re-simulate when users ask about the impact of beta changes;
- Directly invoke historical version data when reviewing strong builds from older versions.
Two points to note:
- Data from different versions must not be mixed; every plan must state the version it relies on;
- Historical data reflects the environment at the time, and its conclusions cannot be applied directly to a new version.
4.3 Handling Uncertainty in Real Data
Community databases are mostly maintained by players, with varying field definitions, update frequency, and quality. Engineering-wise, you need to:
- Treat “data completeness” as a scoring dimension, down-weighting plans with insufficient support;
- For conflicting data, prompt the user to verify it themselves in the report;
- Design a fallback strategy for when a data source is unavailable, rather than fabricating numbers.
5. Reasoning Layer: Forcing Multiple Plans and Selecting the Best
5.1 Why Force Multiple Strategies
Single generation naturally tends toward the “most obvious” mainstream play, easily falling into two biases:
- Convergence: The model tends to reproduce the most common builds in the training corpus, lacking differentiation;
- Overconfidence: Without a comparison plan, the model struggles to detect weak spots in its own reasoning.
Forcing at least three plans with distinct main strategies creates a horizontal comparison and makes the trade-off process explicit:
- Strengths and costs are laid out at a glance;
- Unsuitable plans are explicitly excluded, with reasons;
- The final recommendation is built on comparison, not a single judgment.
Taking the single-unit-type main-force framework as an example, three plans can each lean toward different growth approaches:
| Plan | Positioning | Strengths | Main Risks |
|---|---|---|---|
| A | Few but strong, focused on core units | Concentrated power, clear pacing | Low fault tolerance, little room to adjust when countered |
| B | Spread out in numbers, win by scale | Resilient to losses, high fault tolerance | High economic pressure, slow to take shape |
| C | Mixed transition, transitional early, switch to main force late | Smooth, flexible | Resources spread thin, not extreme at either end |
5.2 Anti-Convergence Strategies at the Prompt Level
- Diverge first, then converge: Require listing all possible main routes first (divided by unit type, economic path, combat positioning, and so on), then select the several with the greatest differences and develop each separately, rather than generating them one after another;
- Anchor on different dimensions: Explicitly specify the differentiating dimension of each plan to avoid “same thing in new packaging”;
- Check divergence: If multiple plans highly overlap in unit structure, tech order, and economic pacing, judge them as unqualified and redo.
5.3 Unified Scoring Framework
Overall score = 0.25 × Opening feasibility # Whether key units can take shape within the target pacing+ 0.20 × Resilience # Ability to handle counters, surprises, and pacing shifts+ 0.20 × Economic efficiency # Input-output ratio, maintenance cost+ 0.20 × Synergy # Coordination among units, heroes, and technologies+ 0.15 × Data support # Whether key conclusions have current-version data backing
Weights should be adjusted to actual needs: a stability-oriented player can raise the resilience weight, while a rush-oriented player can focus on opening feasibility. Beyond the last two dimensions, you can also add “alignment with user preferences” to avoid recommending builds that are technically sound but do not match the player’s habits.
5.4 Why the Thinking Process Is Slow
This design is “trading time for quality”:
- Comparing plans, checking numbers, and organizing reasons all require extensive reasoning;
- In practice, it takes on the order of about twenty minutes, with similar timing across different model tiers;
- The bottleneck is not how deeply a single model “thinks,” but the number of steps in the process itself—including data acquisition and parsing, developing multiple plans, and justifying each one.
This observation applies to all agent applications: to cut the time, streamline the process steps and reduce the number of candidates, rather than simply switching to a stronger model.
6. Output: Structured Reports That Are Usable and Traceable
Input constraints:- Map type: mostly plains, few chokepoints- Opponent tendency: high-mobility raids- Personal preference: single-unit-type main force, mounts optional- Data version: latestCandidate plans:Plan A (few but strong) Score 8.1 SelectedPlan B (spread in numbers) Score 7.3 Rejected: economic pressure doesn't match map conditionsPlan C (mixed transition) Score 7.6 Rejected: resources spread thin, early pacing too slowRecommended build (Plan A):Phase 1 (opening): Build building XX, prioritize unlocking technology XX, set unit type XX as the main forcePhase 2 (mid-game): Fill in XX, have the hero grow along a "support-type" pathPhase 3 (late-game): Based on opponent movements, decide whether to switch production to XX as a supplementRisks and assumptions:- Relies on data version latest; needs re-simulation after a version update- If the opponent adopts XX play, resilience drops; prepare a Plan B- Hero equipment and ruler-type traits are not included in the assessment; advice is for reference only
The value of structured output lies in three points:
- Candidates, rejection reasons, the recommended plan, and risk assumptions are all present, so users can understand both “why this one” and “when to change”;
- The data version is output with the report, making it easy to trace and reproduce;
- Uncovered mechanics are presented as risks, making usage boundaries clear at a glance.
7. Capability Boundaries: Why “Paper Simulation” Must Be Acknowledged
7.1 No Programmatic Interface, No Closed-Loop Validation
The game itself offers no programmatic interface, so the agent cannot automatically enter a match to test. All conclusions are “paper simulations”:
- The model may argue convincingly yet fail in practice;
- Even if the designer ran the simulation themselves, deviations would be unavoidable;
- Therefore, one should not expect the generator to give a perfect answer.
7.2 Mechanics Not Yet Covered
- Economic systems: Not combined with real matches, special-class and trade-route economic mechanics are hard to explain; currently the agent basically does not understand such overly specialized mechanics;
- Hero-related: Hero equipment, ruler-type traits, and faction-specific objective systems are not addressed at all; understanding of hero classes is also shallow, so advice can only be “take a look,” and pure hero builds cannot be done;
- Unit details: Formation counts are not considered for now, due to missing data and too many special cases; mount candidate selection is limited, and when necessary you can explicitly request “must be a flying/vehicle mount”;
- Default framework: Defaults to “single-unit-type main force + hero support,” occasionally doing two-unit-type coordination.
7.3 Engineering Responses
- Annotate the basis: Note the source (data/reasoning/experience) for each key conclusion, distinguishing facts from inferences;
- Force comparison: Multi-plan selection is already implemented within the process;
- Surface risks: Write uncovered mechanics and dependency assumptions into the report;
- Human oversight: Decisions involving special mechanics or hero equipment are verified by the player themselves.
This is not a flaw of the generator, but a shared characteristic of agent applications that lack an execution-feedback loop; any similar tool should be positioned this way.
8. Iteration and Validation: Making the Generator More Accurate Over Time
8.1 Solidifying “Teaching” into the Skill
When you find the generator performing poorly on a mechanic, you can supplement its understanding through continued conversation and then write it into the skill, rather than re-explaining every time. As long as the mechanic can be described clearly and backed by enough real-match cases, there is a chance to bring it into coverage.
8.2 Structured Feedback
When leaving a message in the interface, or submitting an issue through the issue feature of a code-hosting platform, it is recommended to include:
- The data version used and the map/opponent conditions;
- The plan and key judgments the generator gave;
- Where the actual match differed from expectations;
- The rules or preferences you would like adjusted.
Structured feedback is easier to translate into skill updates than a vague “it doesn’t work well.”
8.3 Making Feedback Measurable
Without programmatic validation, you can build a lightweight regression test:
- Compile a set of fixed test scenarios, such as typical map types, opponent tendencies, and different preferences;
- Regenerate after each skill update and record changes in plan main strategy and scores;
- Compare with the previous round to judge whether the adjustment meets expectations and introduces no new problems;
- For uncovered mechanics, maintain “open question” registration to avoid repeatedly stepping into the same pitfalls.
testcase:id: plain_map_vs_rushconstraints: {terrain: plains, enemy: high_mobility, preference: single_unit}expect:data_version_required: truecandidates_min: 3must_state_risks: truelast_result:selected: plan_Ascore: 8.1
9. Conclusion
Teaching personal experience to an agent, keeping data fresh at runtime, and forcing multi-plan comparison before selecting the best—these three points form the core idea of this automatic build generator, and also a general paradigm for building “domain decision assistant” agent applications. At the same time, one must clearly recognize that, without a programmatic execution environment, the output is always a “reasoned simulation,” not a “verified conclusion.”
In the strategy game domain, players can use it as a starting point for build ideation—to broaden ideas, compare plans, and understand trade-offs; the final outcome still depends on their own judgment and execution in real matches.
