[GH-ISSUE #221] Code generation frequently stops mid-way due to output token limits #46

Closed
opened 2026-02-16 06:16:58 -05:00 by yindo · 7 comments
Owner

Originally created by @enteve on GitHub (Feb 11, 2026).
Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/221

Originally assigned to: @christian-bromann on GitHub.

Description:

When using DeepAgent to generate code, I frequently encounter an issue where the generation process stops abruptly due to the LLM's output token limit. This often happens before the code is complete, leaving partial or unusable results.

I've tried adding prompts instructing the agent to generate code in segments/batches, but the issue persists.

Has anyone experienced this or found a workaround? Some potential solutions I'm considering:

  1. Automatic resumption when output is truncated - detect incomplete code and continue generation
  2. Built-in chunking strategy for large code generation tasks
  3. Configurable token limit awareness in the agent

Questions:

  • Is there a recommended way to handle long code generation?
  • Are there any built-in features I might be missing to mitigate this?
  • Would it be possible to add support for streaming/chunked code generation?

Any guidance would be appreciated!

Originally created by @enteve on GitHub (Feb 11, 2026). Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/221 Originally assigned to: @christian-bromann on GitHub. ## Description: When using DeepAgent to generate code, I frequently encounter an issue where the generation process stops abruptly due to the LLM's output token limit. This often happens before the code is complete, leaving partial or unusable results. I've tried adding prompts instructing the agent to generate code in segments/batches, but the issue persists. Has anyone experienced this or found a workaround? Some potential solutions I'm considering: 1. Automatic resumption when output is truncated - detect incomplete code and continue generation 2. Built-in chunking strategy for large code generation tasks 3. Configurable token limit awareness in the agent ## Questions: - Is there a recommended way to handle long code generation? - Are there any built-in features I might be missing to mitigate this? - Would it be possible to add support for streaming/chunked code generation? Any guidance would be appreciated!
Author
Owner

@christian-bromann commented on GitHub (Feb 11, 2026):

@enteve thanks for reporting, I experienced the same and will take a look.

@christian-bromann commented on GitHub (Feb 11, 2026): @enteve thanks for reporting, I experienced the same and will take a look.
Author
Owner

@christian-bromann commented on GitHub (Feb 11, 2026):

@enteve which deepagents version are you using?

@christian-bromann commented on GitHub (Feb 11, 2026): @enteve which `deepagents` version are you using?
Author
Owner

@christian-bromann commented on GitHub (Feb 11, 2026):

Also, mind sharing the exact error message? I am getting this:

{"type":"error","error":{"type":"invalid_request_error","message":"prompt is too long: 219536 tokens > 200000 maximum"},"request_id":"req_011CY2kPwWtNt2aoncRPXh3B"}
@christian-bromann commented on GitHub (Feb 11, 2026): Also, mind sharing the exact error message? I am getting this: ``` {"type":"error","error":{"type":"invalid_request_error","message":"prompt is too long: 219536 tokens > 200000 maximum"},"request_id":"req_011CY2kPwWtNt2aoncRPXh3B"} ```
Author
Owner

@enteve commented on GitHub (Feb 11, 2026):

"deepagents": "^1.7.3"

i didn't keep the error message, i'll share the next time. it's not the prompt that exceeds the length. it's the output token. the error message contains something like

{"finish_reason": "length"}
@enteve commented on GitHub (Feb 11, 2026): "deepagents": "^1.7.3" i didn't keep the error message, i'll share the next time. it's not the prompt that exceeds the length. it's the output token. the error message contains something like ```json {"finish_reason": "length"} ```
Author
Owner

@arielb-oasis commented on GitHub (Feb 16, 2026):

Is there any solution? I dropped deepagents and went to Claude Claude because of limits I got each time even with file system middleware

@arielb-oasis commented on GitHub (Feb 16, 2026): Is there any solution? I dropped deepagents and went to Claude Claude because of limits I got each time even with file system middleware
yindo changed title from Code generation frequently stops mid-way due to output token limits to [GH-ISSUE #221] Code generation frequently stops mid-way due to output token limits 2026-06-05 17:21:10 -04:00
yindo closed this issue 2026-06-05 17:21:11 -04:00
Author
Owner

@christian-bromann commented on GitHub (Feb 18, 2026):

Yes @arielb-oasis we have a solution in #234 which we will ship tomorrow

<!-- gh-comment-id:3919071174 --> @christian-bromann commented on GitHub (Feb 18, 2026): Yes @arielb-oasis we have a solution in #234 which we will ship tomorrow
Author
Owner

@christian-bromann commented on GitHub (Feb 23, 2026):

We have shipped multiple improvements to the summarization middleware and our compaction process. This should hopefully resolve this issue, please let me know if it doesn't and I am happy to re-open. Thanks for all the input here!

<!-- gh-comment-id:3947382431 --> @christian-bromann commented on GitHub (Feb 23, 2026): We have shipped multiple improvements to the summarization middleware and our compaction process. This should hopefully resolve this issue, please let me know if it doesn't and I am happy to re-open. Thanks for all the input here!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#46