Skip to content

agent, engine: restore text tool observation path for non-GLM models - #924

Open
vanantwerp wants to merge 1 commit into
antirez:mainfrom
vanantwerp:fix-tool-observation-deepseek
Open

agent, engine: restore text tool observation path for non-GLM models#924
vanantwerp wants to merge 1 commit into
antirez:mainfrom
vanantwerp:fix-tool-observation-deepseek

Conversation

@vanantwerp

Copy link
Copy Markdown

Summary

Fixes an issue introduced in 47713296d where executing any tool in ds4-agent under DeepSeek V4 models immediately failed with ds4-agent: context full after compaction.

Root Cause

  1. ds4_agent.c:agent_tool_observation_build() was refactored to route all tool observations through ds4_chat_append_multimodal_message().
  2. In ds4.c, ds4_chat_append_multimodal_message() enforced if (DS4_MODEL_FAMILY != DS4_MODEL_FAMILY_GLM_DSA) return 0;, failing unconditionally for DeepSeek V4 even on text-only tool results.
  3. agent_tool_observation_fits() received false from the failed build and treated it as a context-capacity overflow, triggering context compaction and ultimately reporting a false context full after compaction error.

Changes

  1. ds4.c: In ds4_chat_append_multimodal_message(), handle image_count == 0 by delegating to ds4_chat_append_message() so zero-image messages are valid across all model families.
  2. ds4_agent.c: In agent_tool_observation_build(), fast-path obs->image_count == 0 directly to ds4_chat_append_message(), avoiding unnecessary heap allocations and keeping the text-only path clean.

Validation

  • Tested with ds4-agent -m ds4flash.gguf on web search (google_search) and shell tools (bash), confirming tool execution succeeds without triggering compaction or context errors.
  • Verified standard test suites pass: make clean && make, make cpu, and make test (all 8 test suites passed on macOS Metal Apple M5 Max).
  • Verified GLM 5.3 Flash vision and multimodal tools continue to work.

@rinaldofesta

Copy link
Copy Markdown
Contributor

Hit the same thing independently on an M5 Max with DeepSeek V4 Flash 0731, no --vision: the first list . dies with ds4-agent: context full after compaction at 1.9k of 262k. This patch no longer applies on main after fc8bf3c moved the guard. I opened #963 with the same ds4.c delegation plus a regression test that fails on the old engine (--chat-multimodal-text-only). Happy to fold the test into this PR instead if you rebase it.

…-vision

Since 4771329 the agent builds every tool observation with
ds4_chat_append_multimodal_message, whose guard rejects any model that
is not GLM unless a DeepSeek vision encoder is loaded. On a text-only
DeepSeek model the observation never builds; agent_tool_observation_fits
reports the failure as a context overflow, triggering compaction and
ending with 'context full after compaction' on the first tool call.

A message with zero images is an ordinary chat message: delegate it to
ds4_chat_append_message, keeping the per-family rendering.

Add --chat-multimodal-text-only regression test in tests/ds4_test.c.

Co-Authored-By: rinaldofesta <festarinaldo@gmail.com>
@vanantwerp
vanantwerp force-pushed the fix-tool-observation-deepseek branch from 97a2bb9 to f44b32f Compare September 3, 2026 16:23
@vanantwerp

Copy link
Copy Markdown
Author

Thanks @rinaldofesta! I have rebased onto current main to resolve the conflict from fc8bf3c and incorporated your --chat-multimodal-text-only regression test, adding you as co-author on the commit. Verified locally with ./ds4_test --chat-multimodal-text-only, ./ds4_test --server, and ./ds4_agent_test (all passing).

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.

2 participants