ホーム AI・IT 【Tried AI-Driven Development】Starter Kit 46: Automated AI Model Selection

【Tried AI-Driven Development】Starter Kit 46: Automated AI Model Selection

東條 淳平 東條 淳平 • 更新: • 公開: • 読了約 35 分
目次

In the auto-mode of the AI-driven development starter kit, we separate the Worker and Reviewer roles to proceed sequentially through specifications, design, test design, implementation, and review.

Having built it this far, the next thing I wondered about was,

Do humans really need to think about which AI model to use every time?

That was the question.

It feels a bit wasteful to use a powerful model for simple tasks every time.

On the other hand, it is unsettling to rely only on cheaper models for difficult tasks.

So, this time,

I added a mechanism to automatically determine the model class to use based on the difficulty of the feature and the type of task being performed.

I added this mechanism.

However, I did not create a system that precisely determines the optimal model.

What I aimed for this time is much simpler.

  • Do not use 'strong' for obviously simple tasks.

  • Do not use 'cheap' for obviously difficult tasks.

  • Humans should not have to choose the model in daily use.

That is about it.

Until now, models were fixed.

nabced54268ad

In the previous auto-mode, we set the model class to be used for each role, such as design, implementation, and review.

For example,

設計     → standard
実装     → cheap
レビュー → standard

It looks like this.

This is easy to understand, but it does not take the difficulty of the feature into account.

Whether the task is very simple or complex, I use the same model for the same process.

So,

簡単なfeature
↓
少し軽いモデル

普通のfeature
↓
通常のモデル

難しいfeature
↓
少し強いモデル

I thought about whether I could implement some level of automatic adjustment.

However, I don't want to make the model selection mechanism complicated.

When I first started thinking about it, various methods came to mind.

For example,

  • Determine the difficulty level for each stage

  • Have the Worker and Reviewer assess the difficulty separately

  • Upgrade the model if a review results in a RETURN

  • Upgrade the model if a test fails

  • Upgrade to a stronger model if it doesn't converge after several attempts

  • Set about 5 levels of difficulty

and so on.

But, if I start going this far,

I felt that the mechanism for choosing the model would become more complex than the mechanism for creating the feature itself.

I felt that way.

Moreover,

"The test failed because the model was weak"

is not necessarily true.

It could be due to insufficient specifications, a design error, or simply a coding bug.

So, this time I simplified it quite a bit.

Only two criteria for judgment

I use the following two things for model selection.

featureの難しさ
+
実行するpromptの基礎レベル

That is all.

Feature difficulty has 3 levels

I judge the overall difficulty of a feature into

easy
normal
hard

three levels.

The correction value is

easy   = -1
normal =  0
hard   = +1

.

I set the guidelines as follows.

easy
  • Few requirements

  • Clear input and output

  • Clear behavior during exceptions

  • Almost no room for design choices

normal

Anything that cannot be clearly called easy or hard.

If you are unsure, it is also normal.

hard
  • Requirements that influence each other

  • Many error cases and boundary conditions

  • Multiple viable design approaches

These are the types of features.

Do not call AI just for difficulty assessment

I placed a lot of importance on this point this time.

Even though it is a mechanism to save on models,

calling AI one extra time to select a model

is a bit counterproductive.

Therefore, I decided to have it determined together during the existing CP1 Spec Review.

20_spec.md
↓
CP1 Reviewer
├─ 仕様レビュー
└─ feature難易度判定

There are no additional AI calls.

The CP1 Reviewer will

feature_difficulty: easy

record it in the Gate log like this.

From G1 onwards, the runner reads that value.

Do not assess difficulty every time

In principle, the difficulty of a feature is determined only once at CP1.

It is not re-assessed at G1, G2, or CP3.

Also, when

  • a FINDING is issued

  • it is RETURNED

  • it is retried

  • The test failed

I will not change it for reasons such as that.

That alone does not mean the feature itself has become difficult.

However, it is a different story if 20_spec.md has been changed.

Since the specification itself has changed,

仕様変更
↓
CP1再レビュー
↓
feature_difficultyも再判定

it becomes this.

Giving the prompt side a base level as well

Another element is the base level for each prompt.

I set it up like this this time.

create_feature_spec        = 2
create_function_design     = 2
create_function_call_flow  = 1
create_test_design         = 2
create_review_checklist    = 2
implement_feature          = 1
review_stage               = 2

For example, the implementation prompt is base level 1.

The reviewer is base level 2.

Even for the same hard feature,

実装
1 + 1 = 2
→ standard

レビュー
2 + 1 = 3
→ strong

it becomes this.

In other words,

it is not the case that everything is strong because it is hard

.

The calculation method is simple

The final model class is

promptの基礎レベル
+
feature難易度

determined by this.

The result is kept between 1 and 3.

1 → cheap
2 → standard
3 → strong

For example, since the G1 Worker is at basic level 2,

easy
2 - 1 = 1
→ cheap

normal
2 + 0 = 2
→ standard

hard
2 + 1 = 3
→ strong

it becomes this.

Since the CP3 Worker is at basic level 1,

easy   → cheap
normal → cheap
hard   → standard

it is this.

Since the Reviewer is at basic level 2,

easy   → cheap
normal → standard
hard   → strong

it becomes this.

This is what it looks like in a diagram.

                 CP1 Spec Review
                       │
                       │ feature_difficulty
                       │ easy / normal / hard
                       ▼
                ┌─────────────┐
                │    runner   │
                └──────┬──────┘
                       │
            promptのbase_levelを取得
                       │
                       ▼
        base_level + difficulty補正
                       │
                       ▼
             1       2        3
             │       │        │
             ▼       ▼        ▼
           cheap  standard  strong

There is no AI dedicated to model selection.

The runner simply performs a mechanical calculation.

Humans can also force a specific selection.

If you only use automatic selection, it becomes difficult when you want to experiment.

Therefore,

python tools/feature_runner.py \
  --feature <app>/<feature> \
  --model-class strong

I also kept the option to specify it.

In this case,

Worker   → strong
Reviewer → strong

it becomes this, and the feature difficulty and basic level are not used.

There are ultimately only two current model selection methods.

指定なし
→ auto

--model-classあり
→ manual

It has become quite simple.

Leave the selection results in the Gate as well.

Later on,

"Why did it run with this model?"

It is also problematic if you lose track of what is happening.

Therefore, in the Gate logs as well,

feature_difficulty: hard
worker_model_class: standard
reviewer_model_class: strong
model_selection: auto

I made sure to leave a record.

However, I did not include the actual model name in the Gate.

What I leave in the Gate is

which decision led to which model class being selected

at most.

As for how to actually

cheap = どのモデル
standard = どのモデル
strong = どのモデル

assign them, that is handled by the environment settings.

Tested easy and hard with actual AI

Since automated tests alone were a bit concerning, I also tested with actual AI.

This time, to check both extremes,

easy
hard

I prepared two types.

Can easy really be completed with a cheap model?

I made the easy side quite simple in functionality.

It is something like converting ASCII numbers to *.

The requirements are few,

  • input and output are clear

  • low design flexibility

  • no complex state

This is the feature.

The CP1 Reviewer judgment was,

feature_difficulty = easy

it was.

The subsequent model selection was,

CP1 Reviewer   standard

G1 Worker      cheap
G1 Reviewer    cheap

G2 Worker      cheap
G2 Reviewer    cheap

CP3 Worker     cheap
CP3 Reviewer   cheap

it became.

The result reached the Human Gate without any issues, and it is done.

At least in this case,

I was able to proceed with an easy feature using mostly cheap models until the end.

I was able to.

I made the hard feature one where states interact with each other.

For the hard side, I didn't just increase the number of requirements.

It is a small feature, but I made it a specification where

  • normal state

  • single-quoted string

  • double-quoted string

  • comment

  • escape

  • newline

  • unclosed string

and others interact with each other.

The specification text does not contain

"it is hard"

.

I had it determine the difficulty based solely on the feature content.

The result of the CP1 Reviewer was

feature_difficulty = hard

.

A specification omission was also found in the hard CP1

In the initial Spec Review, one specification omission was found, separate from the difficulty assessment.

When a raw newline occurs in the middle of a quoted string,

文字列状態を継続するのか
改行で終了するのか

was undefined.

The Reviewer did not decide on its own, but returned it as a human judgment.

Therefore, I added the specification that

改行はそのまま保持する
文字列状態は継続する

.

When I ran the CP1 Review again,

PASS
feature_difficulty = hard

it became

.

Since the specification was changed, the difficulty was also re-evaluated.

A strong Reviewer found one issue in the hard G2

Worker   strong
Reviewer strong

The G1 on the hard side passed once with

G2 also,

Worker   strong
Reviewer strong

That was it.

There was something interesting here.

Both requirement coverage and test perspective coverage

REQ 13 / 13
観点 19 / 19

were complete.

Looking only at the numbers, it seems fine.

However, the Reviewer

found a missing test case for when the character immediately following the escape character is the escape character itself

—a boundary case.

The Worker made the fix.

The Reviewer checked it again.

G2 passed in two rounds.

Based on this single instance,

I cannot say for sure that

“a strong Reviewer is always better.”

However, at least in this hard verification,

it was a case where using a strong Reviewer actually made a difference

.

Even in hard, the implementation Worker was standard

In CP3,

Worker   standard
Reviewer strong

it became.

This is the part I wanted to verify this time.

Even for hard features,

implement_feature base = 1
hard補正             = +1

1 + 1 = 2
→ standard

because of that.

On the other hand, the Reviewer,

review_stage base = 2
hard補正          = +1

2 + 1 = 3
→ strong

is.

In the implementation, I created 21 feature tests, and all of them passed.

The Reviewer also passed.

In other words,

hardだから全部strong

not,

switching models based on the task even within the same hard feature

was actually confirmed.

With actual AI verification included, 294 tests passed.

With the easy and hard verification features remaining,

294 passed

up to that point was confirmed.

After that, the verification-specific features were removed from the repository.

The verification results were saved in docs/context/work_notes/.

In the final repository,

257 passed

is.

When actually using it, hard features are expensive.

Since I used the strong model several times during hard verification, the AI usage increased more than I expected.

In this experiment, my Claude session usage exceeded 100%, and I spent an additional $2.

This made me wonder about something.

In actual business systems,

  • intertwined requirements,

  • boundary conditions,

  • exception handling,

  • and multiple design proposals

are not uncommon features.

In other words,

there is a high possibility that hard judgments will be quite frequent in professional work.

If you want to lower costs, change the base level, not the difficulty level.

So,

I also thought,

"Shouldn't I reduce the number of hard judgments?"

However, if I do that,

feature_difficulty

the meaning becomes strange.

It is actually hard, but I judge it as normal because I want to lower the cost.

That is not quite right.

After organizing it this time,

feature_difficulty
= featureそのものの難しさ

base_level
= その作業にどれくらい強いモデルを使いたいか

it can be thought of by separating them.

Therefore, if you want to keep costs down at a company or similar environment,

rather than changing the difficulty assessment,

base_level_create_function_design
base_level_create_test_design
base_level_create_review_checklist

it seems more natural to lower things like that.

For example,

Workerはstandard中心
Reviewerはhardならstrong

you can also set it up like this.

I plan to adjust this in actual work scenarios going forward.

I have not changed the default settings of the starter kit this time.

It ended up being quite simple.

To summarize the mechanism added this time,

CP1 Reviewer
↓
featureを easy / normal / hard に分類
↓
Gateに保存
↓
runner
↓
promptのbase_levelと加算
↓
cheap / standard / strongを選択
↓
Worker / Reviewerを起動

it is.

And from the user's perspective,

普通に実行する
→ auto

一時的に固定したい
→ --model-class

it is just that.

I didn't make the model selection incredibly smart.

Rather, what I was conscious of this time was,

not making the model selection too smart

it was.

If you aim for perfect optimization, the model selection itself becomes a new, complex system.

For now,

  • clearly simple tasks are handled lightly

  • clearly difficult tasks are handled strongly

  • Ordinary things should be handled ordinarily

I think that is sufficient.

Reflected in the starter kit

This change has been reflected in the AI-driven development starter kit.

The fixed tag is here.

https://github.com/arimoto1-beep/ai-driven-dev-starter-kit/tree/starter-kit-46-automatic-model-selection

commit:

287e1d9 feat: add automatic model selection

In the final state, I have confirmed

257 passed

.

During this implementation, apart from the automatic model selection, there was one other thing that really caught my attention.

AI thinks very seriously about adding new mechanisms without breaking existing ones.

On the other hand,

"In the first place, isn't that existing mechanism no longer needed?"

There were situations where it was difficult to move in that direction unless I asked the question myself.

Since this is a separate topic from the automatic model selection itself, I will organize it separately next time as an [AI-Driven Development Memo].

同じカテゴリの記事

東條 淳平

スポーツと芸能が交差する話題を担当。大会公式記録と所属先の発表を突き合わせ、数字は必ず出典付きで扱います。

おすすめの関連記事