Skip to content

Commit edd481c

Browse files
docs(agent-loop): add troubleshooting to agent loop section (#195)
1 parent bccc274 commit edd481c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/user-guide/concepts/agents/agent-loop.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,17 @@ This recursive nature allows for complex workflows like:
189189
### 7. Completion
190190

191191
The loop completes when the model generates a final text response or an exception occurs that cannot be handled. At completion, metrics and traces are collected, conversation state is updated, and the final response is returned to the caller.
192+
193+
## Troubleshooting
194+
195+
### MaxTokensReachedException
196+
197+
This exception indicates that the agent has reached an unrecoverable state because the `max_tokens` stop reason was returned from the model provider. When this occurs, the agent cannot continue processing and the loop terminates.
198+
199+
**Common causes and solutions:**
200+
201+
1. **Increase token limits**: If you have explicitly set a `max_tokens` limit in your model configuration, consider raising it to allow for longer responses.
202+
203+
2. **Audit your tool specifications**: A frequent cause of this exception is tool specifications that prompt the model to return excessively large `toolUse` responses. Review your tools for large JSON schemas, tool specs with many fields or deeply nested structures can consume significant tokens. Also, consider long string requirements which may bloat the output (e.g., "provide a string that is 101k characters long").
204+
205+
3. **Optimize tool design**: Consider breaking down complex tools into smaller, more focused tools, or simplifying tool input/output schemas to reduce token consumption.

0 commit comments

Comments
 (0)