1
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?

[AgentCore×Strands Agents]失敗の「記憶」が tool useを止めていた話(忘備録)

1
Last updated at Posted at 2026-01-20

困った。。。

Strands Agents が tool をまったく使ってくれない
Gateway から MCP ツール(天気)を取得し、Agentに渡して天気について質問しているのに「利用できません」と返る。

なんとか解決したので忘備録として簡単にかく。

原因

開発中に MCP クライアント初期化エラーが発生した
その失敗が STM/LTM に残り、「天気は取れない」パターンが固定化されていた。

残っていた履歴(例)

  • user: 「東京の天気を教えて」
  • assistant: tool use weather-service___get-weather
  • tool result: MCP client session not running
  • 以後「天気情報を取得できません」が繰り返し

解決

STM の該当セッションを削除( LTM も削除)。
→ tool 呼び出しが復活。

最低限のコード断片

Strands に LTM を渡す箇所agent-code/personal_secretary_agent.py):

session_manager = AgentCoreMemorySessionManager(
    agentcore_memory_config=agentcore_memory_config,
    region_name="ap-northeast-1",
)

agent = Agent(
    system_prompt=self.system_prompt,
    session_manager=session_manager,
    model=BedrockModel(model_id="jp.amazon.nova-2-lite-v1:0"),
    tools=self.gateway_tools if self.mcp_enabled and self.gateway_tools else None,
)

Gateway から tool を取って渡す箇所agent-code/gateway_tools_loader.py):

def load_gateway_tools() -> List[Any]:
    invoker = MCPGatewayInvoker()
    def transport_factory():
        token = invoker.fetch_access_token()
        return streamablehttp_client(
            invoker.config.gateway_url,
            headers={"Authorization": f"Bearer {token}"},
        )
    _MCP_CLIENT = MCPClient(transport_factory)
    tools = _get_all_tools(_MCP_CLIENT)
    return tools

ネガティブな記憶は忘れた方が良いかもしれない。

失敗し過ぎてトラウマになると一歩踏み出せなくなることが人にもあるだろう。
AIエージェントも同じなんだなと思った。
都合の良い人はすぐに忘れるかも知れないが、長期記憶機能を持たせたAIエージェントは「できないという記憶」を永遠に保持してしまう。

まとめ

  • toolを使ってくれなかった原因は 開発中の一時エラー履歴が残っていたこと
  • デバッグ時は STM のクリアも選択肢に入れる。
  • 一時エラーは 「開発中エラー」扱いで履歴に残しにくくする工夫もありかも。
1
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
1
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?