Skip to content

Fix agent tool results on text-only DeepSeek engines - #982

Open
zhangjun8823-gif wants to merge 1 commit into
antirez:mainfrom
zhangjun8823-gif:fix/text-only-tool-observation
Open

Fix agent tool results on text-only DeepSeek engines#982
zhangjun8823-gif wants to merge 1 commit into
antirez:mainfrom
zhangjun8823-gif:fix/text-only-tool-observation

Conversation

@zhangjun8823-gif

Copy link
Copy Markdown

Problem

Since 4771329 ("Add GLM 5.3 Flash vision support"), agent_tool_observation_build() in ds4_agent.c appends every tool observation through ds4_chat_append_multimodal_message(). That function rejects any engine that is neither GLM nor DeepSeek-with-vision:

if ((DS4_MODEL_FAMILY != DS4_MODEL_FAMILY_GLM_DSA &&
     e->vision_kind != DS4_VISION_DEEPSEEK4) || (!tool && !user))
    ... return 0;

On a plain text-only DeepSeek V4 Flash/Pro engine (no --vision encoder loaded), every tool result append therefore fails. The failure is swallowed by agent_tool_observation_fits() and misread as "tool result would exceed context", which triggers a context compaction that can never help. After compaction the append still fails, and the agent dies with a bogus error:

COMPACTING rebuilding context: old=1860 summary+tail=2023 tail=123
ds4-agent: context full after compaction

...even with a 1M-token context and only ~2k tokens in use. The agent then sits idle; tool use (bash, web, file edits) is completely broken on text-only DeepSeek models.

Reproduce

./ds4-agent -m <text-only DeepSeek GGUF> --non-interactive \
  -p "Run: echo hello, then tell me the output"

The bash call executes, but appending its observation fails and the run ends with the error above.

Fix

When the observation carries no images, append it through the plain ds4_chat_append_message() tool path — the same path used before 4771329. The multimodal path is kept for image-carrying observations (GLM / DeepSeek vision engines).

Tested

  • Apple M3 Ultra, macOS, Metal backend, text-only DeepSeek V4 Flash GGUF
  • Non-interactive run with a forced bash tool call now completes the full round trip: tool executes, observation is appended, model answers with the command output, clean exit. No "context full" error.
  • make ds4-agent builds warning-free.

agent_tool_observation_build() always appended tool observations via
ds4_chat_append_multimodal_message(), which rejects engines that are
neither GLM nor DeepSeek-with-vision. On a plain text-only DeepSeek
model every tool result append therefore failed; the failure was
misread as 'tool result would exceed context', triggering a compaction
that could never help and ending in a bogus 'context full after
compaction' error that idled the agent.

Regression introduced in 4771329 (GLM 5.3 Flash vision support).

Fix: when the observation carries no images, append it through the
plain ds4_chat_append_message() tool path, as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant