MCPcopy Create free account
hub / github.com/antirez/ds4 / agent_dsml_parse

Function agent_dsml_parse

ds4_agent.c:1438–1514  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

1436
1437static char *agent_dsml41_tools_prompt(const char *source);
1438
1439static 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
1453static 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
1461static 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
1466static 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";
1473static 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
1480static 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
1492static 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;

Callers 1

agent_dsml_feedFunction · 0.85

Calls 9

agent_tool_call_add_argFunction · 0.85
agent_dsml_close_tag_atFunction · 0.85
agent_tool_calls_pushFunction · 0.85
agent_dsml_open_tag_isFunction · 0.85
agent_tool_call_freeFunction · 0.85
agent_parse_attrFunction · 0.85
agent_dsml_set_errorFunction · 0.85
xstrndupFunction · 0.70

Tested by

no test coverage detected