Skip to content
← Back to activity

Immutable solution version

KeyError 'content' caused by negative max_tokens from long tool output

Version 2

Complete solution

Shows how to fix keyError 'content' caused by negative max_tokens from long tool output. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

This issue usually appears after I run a custom tool I've designed for Super AGI. Fix it by trimming what your tool returns, raising the model's token limit, or both.

Steps

  1. Issue TransformerOptimus/SuperAGI#560 (closed, 9 comments): I am writing this issue to bring your attention to a recurring error I have encountered while working with your system. This issue usually appears after I run a custom tool I've designed for Super AGI. The tool is returning almost 200 lines of data. Logs show: errorcode=None errormessage="-3038 is less than the minimum of 1 - 'maxtokens'" errortype=invalidrequesterror, followed by KeyError: 'content'.
  2. The KeyError on 'content' is a downstream symptom. The real error is '-3038 is less than the minimum of 1 - maxtokens': SuperAGI computes maxtokens as tokenlimit - currenttokens - functiontokens, and a long tool output pushed it negative, which the API rejects. When you see this, your tool output ate the whole token budget. Fix it by trimming what your tool returns, raising the model's token limit, or both. The negative maxtokens error in the celery logs is the giveaway.

When to use

You are seeing this: Issue TransformerOptimus/SuperAGI#560 (closed, 9 comments): I am writing this issue to bring your attention to a recurring error I have encountered while working with your system. Use this skill when you run into "KeyError 'content' caused by negative max_tokens from long tool output".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

In gh:TransformerOptimus/SuperAGI#560 (SuperAGI), the issue reported was: Issue TransformerOptimus/SuperAGI#560 (closed, 9 comments): I am writing this issue to bring your attention to a recurring error I have encountered while working with your system. This issue usually appears after I run a custom tool I've designed for Super AGI. The tool is returning almost 200 lines of data. Logs show: errorcode=None errormessage="-3038 is less than the minimum of 1 - 'maxtokens'" errortype=invalidrequesterror, followed by KeyError: 'content'. The verified resolution from the thread: The KeyError on 'content' is a downstream symptom. The real error is '-3038 is less than the minimum of 1 - maxtokens': SuperAGI computes maxtokens as tokenlimit - currenttokens - functiontokens, and a long tool output pushed it negative, which the API rejects. When you see this, your tool output ate the whole token budget. Fix it by trimming what your tool returns, raising the model's token limit, or both. The negative maxtokens error in the celery logs is the giveaway. Source: mount the host path https at container path //github.com/TransformerOptimus/SuperAGI/issues/560

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_rKmH9xs2XoRObIA3hv5_tg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">KeyError &#39;content&#39; caused by negative max_tokens from long tool output <span>— Vectle</span></a>

KeyError 'content' caused by negative max_tokens from long tool output | Vectle