Optimizing Agent Behavior Through Ruleset Optimization

⭐️This is Day 13 of the JAPAN AI Advent Calendar 2025⭐️
Hello, my name is Khoo, and I’m one of the members of JAPAN AI Labs. Our team mission in the company is to bridge research to production- Research, prototype, and systematically integrate frontier Agentic AI advances to deliver measurable platform improvements.
In recent years, the rapid advancement of large language models (LLM) and intelligent agents has brought growing attention to the role that context plays in shaping model behavior. The effectiveness of LLM is largely determined by the context they receive, spanning everything from simple prompts to extensive external knowledge sources. As these models have become central reasoning components in modern applications, the deliberate design and management of context has developed into a distinct field of practice: Context Engineering. [5]
In other words, instead of changing the brain, we change what the brain sees.
Context engineering in practice
A modern AI agent does not rely on a single prompt. Its responses are shaped by a continuously assembled context that usually includes the system context below

Every layer adds constraints and guidance to the model’s behavior. Optimizing any of these layers can change the outcomes significantly. And among all context components being mentioned here, one layer stands out for its impact and accessibility: project-level rulesets.
In fact, most modern coding agents support rules through project-level files such as:
- claude.md
- agents.md
- .cursor/rules
These files all do roughly the same thing. They inject persistent rules into the system prompt for every request. They tell the agent how to behave, what to prioritize, and where the cliffs are. Meanwhile, ruleset does not store or update facts about past interactions, unlike memory systems, which persist user or task-specific state across sessions.
Example:
Project coding rules:
1. Always run tests before proposing a final patch.
2. Prefer minimal, surgical diffs over large refactors.
3. When unsure, please ask for clarification.
4. Explain your reasoning in a short bullet list at the end of the patch.This is just text, but since these files are appended to every single inference, modifying them is effectively equivalent to re-targeting the agent’s personality and priorities across your entire development workflow. And I believe most programmers who have used AI coding tools would understand how these files can heavily impact the quality of the outcome.
Case study: Ruleset optimization
While manual ruleset tuning can produce noticeable gains, it quickly reaches a ceiling. Human prompt engineering is slow, subjective, and difficult to scale. You may tweak phrasing here or rearrange constraints there, but it’s rarely clear whether a particular change improved core task performance, or it just simply changed output style.
This is exactly where Prompt Learning, as explored in Arize’s recent experiments[1][2], becomes relevant.
Instead of humans manually optimizing rules, Arize treated the ruleset itself as a learnable object. The sample pattern utilizing the Cline agent looked like this:

In other words, the algorithm automatically edited project-level rules files such as claude.md and agents.md. After that, it measured how each variation affected coding agent performance on SWE-Bench Lite [3], a standardized benchmark for real-world software engineering tasks. This benchmark serves as an objective scorekeeper, providing quantifiable insight into exactly how much a specific rule change improves the model's reliability versus simply changing its tone.
Crucially, no model weights were changed, and the only tuning surface was the visible rules text injected into the agent’s context.
This approach of treating rulesets as learnable objects has emerged independently across several researches. Other than the Arize's prompt learning experiments we mentioned above, concurrently, GEPA (Genetic-Pareto) [6] formalized ruleset optimization as reflective prompt evolution. It uses Pareto-based selection to maintain diverse candidate prompts rather than converging on a single best. Aside from that, ACE (Agentic Context Engineering) [7] extended the paradigm further, treating context as "evolving playbooks" that accumulate strategies through generation, reflection, and curation cycles.
Although these approaches were different (see table below), they shared the same insight: for agents built on frozen model weights, the highest-leverage optimization surface is often the visible text injected into context. Not retrieval pipelines, not memory architectures, but the instructions themselves.
| Dimension | Arize Approach | ACE | GEPA |
|---|---|---|---|
| Optimization target | Ruleset files (claude.md, agents.md) | Playbook (offline prompts + online memory) | System prompts across compound AI systems |
| Learning signal | LLM evaluator feedback on task outcomes | Execution feedback + structured curation | Textual feedback + standard task metric score |
| Selection strategy | Iterative refinement (greedy) | Grow-and-refine (incremental deltas) | Pareto frontier (multi-objective) |
| Key strength | Practitioner accessibility | Prevents context collapse | Sample efficiency |
| Reported gains | ~10% on SWE-Bench Lite | +10.6% on AppWorld | +10-20% vs. RL, 35× fewer rollouts across 4 benchmarks (HotpotQA, IFBench, HoVer and PUPA) |
What was optimized?
The prompt learning system explored multiple dimensions of instruction design. Instead of humans manually optimizing rules, the algorithm treated the ruleset itself as a learnable object.
Arize's results were promising (~10% improvement in SWE-Bench lite), but we wanted to test whether these gains were specific to coding tasks or reflected something more general about how agents respond to optimized context. To find out, we replicated this approach on Officebench [4], a benchmark that evaluates AI agents on office productivity tasks: spreadsheet manipulation, document editing, file organization, and similar workflows.
To illustrate what actually changes during optimization, here is a comparison from our internal Officebench experiments.
BEFORE
Read before acting: skim inputs, configs, and
adjacent files for coupling; avoid blind edits.
AFTER
[1] Read before write; after every change, re-read to verify exact
cells/paths/content were updated as intended. For generated documents,
include the task's required keywords/field labels verbatim (e.g., "Address") and,
if supported, read back to confirm; for file ops,
list before/after to confirm only intended files changed.
The optimized rule evolved from a general guideline into a procedural checklist. Key changes included:
| Dimension | Before | After |
|---|---|---|
| Specificity | "skim inputs" (vague) | "re-read to verify exact cells/paths/content" (precise) |
| Action Type | Suggestion | Mandate with verification step |
| Failure Mode | Not addressed | "list before/after to confirm only intended files changed" |
| Negative Constraint | None | Implicit: don't skip verification |
Similarly, generic computation guidance became domain-specific. The optimization process discovered that vague instructions fail on edge cases. For example, tasks requiring "average daily salary" were incorrectly computed until the ruleset explicitly encoded the formula and rounding behavior:
BEFORE
Compute locally when exactness is required (regex, math, table ops)
AFTER
[12] Time-based conversions: for "per [time period]" results,
convert totals accordingly (e.g., per day = total/365 unless stated otherwise)
and apply rounding instructions exactly.What changed?
In short, the agent did not become more intelligent. It became more procedurally aligned to engineering expectations. For the dataset used in this experiment, we shuffled the easy and hard tasks in Officebench and created two splits (training and test). In the chart below, the task index simply indicates the order in which subtasks are evaluated. Each Officebench task follows the format {task}/{subtask} (e.g. 1–1/0), where subtasks represent variants of the same scenario with different parameters. This tests whether the agent generalizes rather than memorizes.




We observed an average 12~15% increase in pass rate within 3 iterations by using Minimax-M2, with a slight token consumption increase as a trade-off. For the test split, the improvement is smaller, but no degradation is observed.
This proves that ruleset optimization works not only for coding, but is also applicable to other domains. For teams deploying AI in production environments, this finding is significant.
Ruleset functions as a behavioral control surface: a low-cost, low-risk layer for ongoing performance improvement. Without retraining models and modifying infrastructure, teams can meaningfully increase reliability simply by refining contextual instructions.
Conclusion
Context engineering represents one of the highest-leverage opportunities currently available for production AI teams. By shaping what models see rather than how models think, we can materially improve reliability, task completion rates, and overall usefulness without retraining, fine-tuning, or infrastructure upheaval.
As optimization tooling matures and automated Prompt Learning systems become more widespread, we are likely to see project rules evolve into tunable software layers rather than static prompts.
Reference:
[1] CLAUDE.md: Best Practices Learned from Optimizing Claude Code with Prompt Learning
[2] Optimizing Coding Agent Rules (./clinerules) for Improved Accuracy
[3] SWE-bench Lite - A curated subset of SWE-bench for faster, more cost-effective evaluation.
[4] OfficeBench: Benchmarking Language Agents across Multiple Applications for Office Automation
[5] Hua, Q., Ye, L., Fu, D., Xiao, Y., Cai, X., Wu, Y., Lin, J., Wang, J., & Liu, P. (2025). Context Engineering 2.0: The Context of Context Engineering. arXiv preprint arXiv:2510.26493.
[6] Agrawal, L. A. (2025). GEPA: Reflective Prompt Evolution Can Outperform Reinforcement-Learning for Prompt Optimization. arXiv preprint arXiv:2507.19457.
[7] Zhang, Q., Hu, C., Upasani, S., Ma, B., Hong, F., Kamanuru, V., Rainton, J., Wu, C., Ji, M., Li, H., Thakker, U., Zou, J., & Olukotun, K. (2025). Agentic Context Engineering: Evolving Contexts for Self-Improving Language Models. arXiv preprint arXiv:2510.04618.
【JAPAN AI】Generative AI Engineer (R&D) | 株式会社ジーニーhrmos.co