fix(llm): cap max_tokens and enable streaming to prevent hangs with post-7/31 deepseek-v4-flash (#1204) - #1205
Open
ariesy wants to merge 2 commits into
Open
Conversation
added 2 commits
August 5, 2026 17:04
…long reasoning chains (TauricResearch#1204) DeepSeek V4 Flash (7/31 stable) emits much longer reasoning chains (500+ tokens for complex tasks). TradingAgents sent no max_tokens, so: - with a bounded default, the reasoning chain consumed the whole budget and content came back empty (agents got nothing to parse); - with no bound, a single generation could exceed the gateway's ~3 min idle timeout and drop the connection, hanging the run. Add TRADINGAGENTS_MAX_TOKENS (default 8192) and forward it through _get_provider_kwargs -> _PASSTHROUGH_KWARGS into every chat client.
…o backend (TauricResearch#1204) max_tokens alone does not fix hangs with the post-7/31 deepseek-v4-flash: long reasoning chains make single non-streamed generations exceed the OpenCode Go gateway's ~3 min idle timeout, which drops the connection and leaves the process in wait_woken. - Enable streaming when base_url points at opencode.ai (keeps the socket active; langchain aggregates chunks back to a single AIMessage) - Use DeepSeekChatOpenAI for opencode.ai + deepseek models so reasoning_content is captured on the streaming path via _convert_chunk_to_generation_chunk and round-tripped on the next turn
Merged
1 task
rajatvarna
added a commit
to rajatvarna/TradingAgents
that referenced
this pull request
Aug 10, 2026
feat: DeepSeek max_tokens and streaming reasoning round-trip (TauricResearch#1205)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1204. TradingAgents hangs indefinitely with the post-7/31 stable
deepseek-v4-flash(long reasoning chains). Root cause is two-fold:max_tokenssent._PASSTHROUGH_KWARGSinllm_clients/openai_client.pydoes not forwardmax_tokens. With the new long-reasoning v4-flash, an unbounded generation exceeds the gateway's ~3 min idle timeout and the connection is dropped — the process sits inwait_wokenforever. When a bounded default does apply, the reasoning chain can consume the entire budget andcontentcomes back empty.Verified against
opencode.ai/zen/go/v1withdeepseek-v4-flash:Changes
tradingagents/default_config.py: addTRADINGAGENTS_MAX_TOKENSenv override +max_tokens: 8192default.tradingagents/graph/trading_graph.py: forwardmax_tokensfrom config into LLM client kwargs.tradingagents/llm_clients/openai_client.py:max_tokensto_PASSTHROUGH_KWARGS;streamingwhenbase_urlpoints atopencode.ai(keeps the socket alive; langchain aggregates chunks back to a single AIMessage);DeepSeekChatOpenAIfor opencode.ai + deepseek models soreasoning_contentis captured on the streaming path via_convert_chunk_to_generation_chunkand round-tripped on the next turn.Verification
test_deepseek_reasoning,test_capabilities,test_env_overrides,test_openai_compatible_provider,test_llm_max_retries,test_temperature_config).max_tokensdefault (8192) and env override (TRADINGAGENTS_MAX_TOKENS=16384) both verified.Related