Parse as much of the accumulated DSML buffer as possible. The parser can be * called after every streamed byte: incomplete input leaves state unchanged * until enough bytes arrive, while malformed completed input switches to * AGENT_DSML_ERROR so the model gets a retryable tool error. */
| 1436 | |
| 1437 | static char *agent_dsml41_tools_prompt(const char *source); |
| 1438 | |
| 1439 | static char *agent_build_tools_prompt(ds4_engine *engine, bool edit_upto) { |
| 1440 | if (agent_tool_syntax_for_engine(engine) == AGENT_TOOL_SYNTAX_QWEN) |
| 1441 | return agent_build_qwen_tools_prompt(edit_upto, ds4_engine_has_vision(engine)); |
| 1442 | if (agent_tool_syntax_for_engine(engine) == AGENT_TOOL_SYNTAX_GLM) |
| 1443 | return agent_build_glm_tools_prompt(edit_upto, ds4_engine_has_vision(engine)); |
| 1444 | char *prompt = agent_build_dsml_tools_prompt(edit_upto, ds4_engine_has_vision(engine)); |
| 1445 | if (ds4_engine_is_deepseek41(engine)) { |
| 1446 | char *next = agent_dsml41_tools_prompt(prompt); |
| 1447 | free(prompt); |
| 1448 | prompt = next; |
| 1449 | } |
| 1450 | return prompt; |
| 1451 | } |
| 1452 | |
| 1453 | static const char agent_dsml_syntax_reminder[] = |
| 1454 | "DSML syntax reminder:\n" |
| 1455 | "<|DSML|tool_calls>\n" |
| 1456 | "<|DSML|invoke name=\"$TOOL_NAME\">\n" |
| 1457 | "<|DSML|parameter name=\"$PARAMETER_NAME\" string=\"true|false\">$PARAMETER_VALUE</|DSML|parameter>\n" |
| 1458 | "</|DSML|invoke>\n" |
| 1459 | "</|DSML|tool_calls>\n"; |
| 1460 | |
| 1461 | static const char agent_glm_syntax_reminder[] = |
| 1462 | "GLM tool-call syntax reminder:\n" |
| 1463 | "<tool_call>$TOOL_NAME<arg_key>$PARAMETER_NAME</arg_key>" |
| 1464 | "<arg_value>$PARAMETER_VALUE</arg_value></tool_call>\n"; |
| 1465 | |
| 1466 | static const char agent_dsml41_syntax_reminder[] = |
| 1467 | "DSML syntax reminder:\n" |
| 1468 | "<|DSML| calls>\n" |
| 1469 | "<|DSML| invoke name=\"$TOOL_NAME\">\n" |
| 1470 | "<|DSML| parameter name=\"$PARAMETER_NAME\" string=\"true|false\">$PARAMETER_VALUE</|DSML| parameter>\n" |
| 1471 | "</|DSML| invoke>\n" |
| 1472 | "</|DSML| calls>\n"; |
| 1473 | static const char agent_qwen_syntax_reminder[] = |
| 1474 | "Tool-call syntax reminder:\n" |
| 1475 | "<tool_call>\n<function=$TOOL_NAME>\n<parameter=$PARAMETER_NAME>\n$PARAMETER_VALUE\n</parameter>\n" |
| 1476 | "</function>\n</tool_call>\n"; |
| 1477 | |
| 1478 | #define AGENT_SYSTEM_PROMPT_REMINDER_TOKENS 50000 |
| 1479 | |
| 1480 | static const char agent_hints_prompt[] = |
| 1481 | "The user enabled programming hints. Occasionally explain a useful concept " |
| 1482 | "behind the current work: a design choice, failure mechanism, trade-off, " |
| 1483 | "or way to verify correctness. Base each hint on code or results you have " |
| 1484 | "actually examined. Write one or two sentences as a normal Markdown " |
| 1485 | "blockquote starting with > **Hint:**. Hints are prose, not tool calls. " |
| 1486 | "Put them after the relevant discovery, including between tool calls. " |
| 1487 | "Prefer no hint to routine narration, repetition, or generic advice. " |
| 1488 | "Do not invent personal experience or a learner profile. Keep working " |
| 1489 | "without waiting for an answer. Later system notes may enable or disable " |
| 1490 | "hints; follow the latest setting.\n"; |
| 1491 | |
| 1492 | static bool agent_parse_hints(const char *arg, bool *enabled) { |
| 1493 | if (!strcmp(arg, "on")) *enabled = true; |
| 1494 | else if (!strcmp(arg, "off")) *enabled = false; |
| 1495 | else return false; |
no test coverage detected