opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: search through webfetch tool output (when result exceeds context limits -> blocks conversation)

Open shanjairaj7 opened this issue 2 months ago • 1 comments

Adds context limit checking to webfetch tool to prevent exceeding model's context window. Truncates large webfetch outputs when they would exceed available context space for the specific chosen model.

This is using the same overflow detection pattern as SessionCompaction.isOverflow().

Some docs like the nextjs docs or shadcn docs for certain components are a lot larger in context length. When fetch is called it exceeds the model's context limit and doesn't continue.

Now there is a search property which the model can use if it only needs specific content from the docs. Example: The shadcn sidebar documentation is very detailed and long (~50k tokens).

Now the model can search "SideMenuSub" in the webfetch directly, and it would return this specific section only. Which would be just 200-500 tokens.

  • Combination of chunking and tokenising the chunks
  • Finding and adding in table of contents for better context

I've only been using opencode for sometime, but when it stops when it encounters large docs or websites i am not even able to continue or even compact the conversation.

So this is something that fixes that for me with no performance loss.

shanjairaj7 avatar Nov 04 '25 04:11 shanjairaj7

bump - this is really really annoying :(

anntnzrb avatar Dec 23 '25 01:12 anntnzrb