0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ADKで思考トークン数の上限を設定する

0
Posted at

はじめに

以前の記事で出力トークンを制限するための設定を行いました。

出力トークンの上限を設定できたものの、これは純粋な返答と思考で使用したトークンの合計に対する上限です。
そのため、思考にトークンを使いすぎるとそもそも返答ができないという問題がありました。

thinking_configで思考に使うトークン量を調整する

ADKのLLMエージェントには思考トークンthinking_configという設定があり、その中のthinking_budgetde
思考に使うトークンの量を調整できます。

thinking_configはLLMAgent自体の設定値ではなく、plannerの設定値です。
plannerとは、LLMが行う処理の実行計画を立てるために使われる設定で、デフォルトではBuiltInPlannerというPlannerが設定されています。

root_agent = Agent(
    model=os.environ.get("MODEL"),
    name="memory_agent",
    instruction="挨拶を返してください。猫のような口調で会話してください。",
    planner=BuiltInPlanner(
        thinking_config=types.ThinkingConfig(
            thinking_budget=1024,
        )
    ),
)

試してみる

というわけで試してみます。
まずはthinking_budgetの設定なしで実行します。

root_agent = Agent(
    model=os.environ.get("MODEL"),
    name="memory_agent",
    instruction="挨拶を返してください。猫のような口調で会話してください。",
)

image.png

思考に使われたのは32トークンです。

image.png

続いて、`thinking_budgetを10に設定して試してみます。

root_agent = Agent(
    model=os.environ.get("MODEL"),
    name="memory_agent",
    instruction="挨拶を返してください。猫のような口調で会話してください。",
    planner=BuiltInPlanner(
        thinking_config=types.ThinkingConfig(
            thinking_budget=10,
        )
    ),
)

image.png

思考に使われたトークンは8トークンでした!

image.png

一方で、thinking_budgetの値を大きくすると、使用されるトークンの量も増えてしまいました。

root_agent = Agent(
    model=os.environ.get("MODEL"),
    name="memory_agent",
    instruction="挨拶を返してください。猫のような口調で会話してください。",
    planner=BuiltInPlanner(
        thinking_config=types.ThinkingConfig(
            thinking_budget=1024,
        )
    ),
)

image.png

単純な上限というわけではなく、「この値まで考えていいよ~」というイメージなんですね。
大きくしすぎると、単純な質問でもものすごい考えてしまいそうです。

おわりに

今回はADKのthinking_configを用いて思考トークンの上限を設定してみました。
単純な出力トークンの上限だけではレスポンスが返ってこない場合もありましたが、思考トークンの上限を決めることで料金やスピードをコントロールしつつできるのは嬉しいですね。

ここまでご覧いただきありがとうございました!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?