Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions ds4_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -3472,7 +3472,9 @@ static bool parse_responses_content_array(const char **p, char **out) {
* render_chat_prompt_text can wrap them in <think>. */
static bool parse_responses_input(const char **p, chat_msgs *msgs,
buf *loaded_tool_schemas,
tool_schema_orders *orders) {
tool_schema_orders *orders,
bool *last_was_compaction) {
if (last_was_compaction) *last_was_compaction = false;
json_ws(p);
if (**p != '[') return false;
(*p)++;
Expand Down Expand Up @@ -3720,6 +3722,7 @@ static bool parse_responses_input(const char **p, chat_msgs *msgs,
!strcmp(t, "tool_search_call") || !strcmp(t, "image_generation_call");
bool is_bookkeeping =
!strcmp(t, "compaction") || !strcmp(t, "context_compaction");
if (is_bookkeeping && last_was_compaction) *last_was_compaction = true;
if (!consumes_reasoning && !is_bookkeeping && pending_reasoning.len) {
chat_msg flush_msg = {0};
flush_msg.role = xstrdup("assistant");
Expand Down Expand Up @@ -4021,6 +4024,7 @@ static bool parse_responses_request(ds4_engine *e, server *s, const char *body,
const char *p = body;
bool got_input = false;
bool tool_choice_none = false;
bool last_was_compaction = false;
bool got_thinking = false;
bool thinking_enabled = true;
ds4_think_mode reasoning_effort = DS4_THINK_HIGH;
Expand Down Expand Up @@ -4058,7 +4062,7 @@ static bool parse_responses_request(ds4_engine *e, server *s, const char *body,
msg.content = plain;
chat_msgs_push(&msgs, msg);
} else if (!parse_responses_input(&p, &msgs, &loaded_tool_schemas,
&r->tool_orders)) {
&r->tool_orders, &last_was_compaction)) {
free(key);
goto bad;
}
Expand Down Expand Up @@ -4240,7 +4244,7 @@ static bool parse_responses_request(ds4_engine *e, server *s, const char *body,
const char *active_tool_schemas =
(!tool_choice_none && combined_tool_schemas.len) ?
combined_tool_schemas.ptr : NULL;
r->has_tools = active_tool_schemas && active_tool_schemas[0];
r->has_tools = active_tool_schemas && active_tool_schemas[0] && !last_was_compaction;
if (!got_thinking && model_alias_disables_thinking(r->model)) thinking_enabled = false;
if (!got_thinking && model_alias_enables_thinking(r->model)) thinking_enabled = true;
r->think_mode = ds4_think_mode_for_context(
Expand Down Expand Up @@ -13371,7 +13375,7 @@ static void test_responses_input_tool_search_output_loads_tools(void) {
chat_msgs msgs = {0};
buf loaded = {0};
tool_schema_orders orders = {0};
TEST_ASSERT(parse_responses_input(&p, &msgs, &loaded, &orders));
TEST_ASSERT(parse_responses_input(&p, &msgs, &loaded, &orders, NULL));
TEST_ASSERT(loaded.ptr && strstr(loaded.ptr, "\"name\":\"mcp__perplexity__perplexity_search\""));
const tool_schema_order *order =
tool_schema_orders_find(&orders, "mcp__perplexity__perplexity_search");
Expand All @@ -13396,7 +13400,7 @@ static void test_responses_input_tool_search_output_rejects_bad_tools(void) {
chat_msgs msgs = {0};
buf loaded = {0};
tool_schema_orders orders = {0};
TEST_ASSERT(!parse_responses_input(&p, &msgs, &loaded, &orders));
TEST_ASSERT(!parse_responses_input(&p, &msgs, &loaded, &orders, NULL));
buf_free(&loaded);
tool_schema_orders_free(&orders);
chat_msgs_free(&msgs);
Expand All @@ -13419,7 +13423,7 @@ static void test_responses_input_function_call_namespace_round_trips_to_dsml(voi
"\"arguments\":{\"query\":\"deepseek\"}}]";
const char *input_p = input_json;
chat_msgs msgs = {0};
TEST_ASSERT(parse_responses_input(&input_p, &msgs, NULL, NULL));
TEST_ASSERT(parse_responses_input(&input_p, &msgs, NULL, NULL, NULL));
TEST_ASSERT(msgs.len == 1);
TEST_ASSERT(msgs.v[0].calls.len == 1);
TEST_ASSERT(!strcmp(msgs.v[0].calls.v[0].name,
Expand Down