Skip to content

fix: Research Agentのトークンカウントが0/0/0で表示される問題を修正#1481

Open
takke1986 wants to merge 1 commit intoaws-samples:mainfrom
takke1986:fix/research-agent-token-count-pr
Open

fix: Research Agentのトークンカウントが0/0/0で表示される問題を修正#1481
takke1986 wants to merge 1 commit intoaws-samples:mainfrom
takke1986:fix/research-agent-token-count-pr

Conversation

@takke1986
Copy link
Copy Markdown
Contributor

@takke1986 takke1986 commented Mar 5, 2026

  • converters.py: ResultMessageからusage dictを抽出しトークン使用量を累計
    • total_input_tokens/total_output_tokensフィールドを追加
    • ResultMessageをスキップせずusage.input_tokens/output_tokensを蓄積
  • agent.py: ハードコードされた0/0/0をconverterの累計値に置き換え

Description of Changes

修正内容
converters.py:
ContentBlockConverter に total_input_tokens/total_output_tokens フィールドを追加
ResultMessage を単純にスキップせず、usage dict から input_tokens/output_tokens を抽出して累計
複数ターンの会話でもトークン使用量が正しく蓄積される
agent.py:
ハードコードされた {"inputTokens": 0, "outputTokens": 0, "totalTokens": 0} を converter.total_input_tokens/converter.total_output_tokens の累計値に置き換え
既存ユーザーへの影響
破壊的変更なし
UIのトークン表示が 0/0/0 から実際の使用量に変わるため、表示上の変化あり
Research Agent 以外のユースケースには影響なし

Checklist

  • Modified relevant documentation
  • Verified operation in local environment
  • Executed npm run cdk:test and if there are snapshot differences, execute npm run cdk:test:update-snapshot to update snapshots

Related Issues

Please list related issues as much as possible.

- converters.py: ResultMessageからusage dictを抽出しトークン使用量を累計
  - total_input_tokens/total_output_tokensフィールドを追加
  - ResultMessageをスキップせずusage.input_tokens/output_tokensを蓄積
- agent.py: ハードコードされた0/0/0をconverterの累計値に置き換え
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Issues or Pull Requests with no updates label Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Issues or Pull Requests with no updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant