TradingAgents/tradingagents/agents
Michael Yang 3d8341c104 fix: report LLM calls, tool calls, and token usage for claude_agent
ChatClaudeAgent is a plain Runnable rather than a BaseChatModel, so
LangChain's callback system never fired on_chat_model_start / on_llm_end
for it — leaving the CLI TUI stuck on "LLM: 0" and "Tokens: --" during
runs. Pop callbacks out of the LLM kwargs, invoke them manually around
each SDK call, and attach usage_metadata extracted from the SDK's
ResultMessage (input, output, total — including cached input) to the
returned AIMessage so downstream handlers pick it up.

Tool callbacks now also fire through the MCP wrapper: forward the
callback list into each wrapped LangChain tool's invocation config so
StatsCallbackHandler sees on_tool_start/on_tool_end when the SDK loop
calls a tool.

Verified via direct StatsCallbackHandler round-trip on both Shape A
(ChatClaudeAgent.invoke) and Shape B (run_sdk_analyst): llm_calls,
tool_calls, tokens_in, and tokens_out all increment as expected.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 17:32:11 -04:00
..
analysts fix: report LLM calls, tool calls, and token usage for claude_agent 2026-04-14 17:32:11 -04:00
managers refactor: remove stale imports, use configurable results path (#499) 2026-04-04 07:35:35 +00:00
researchers refactor: remove stale imports, use configurable results path (#499) 2026-04-04 07:35:35 +00:00
risk_mgmt refactor: remove stale imports, use configurable results path (#499) 2026-04-04 07:35:35 +00:00
trader refactor: remove stale imports, use configurable results path (#499) 2026-04-04 07:35:35 +00:00
utils fix: process all chunk messages for tool call logging, harden memory score normalization (#534, #531) 2026-04-13 07:21:33 +00:00
__init__.py refactor: standardize portfolio manager, five-tier rating scale, fix analyst status tracking 2026-03-22 23:30:29 +00:00