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

Function json_args_parse

ds4_server.c:2089–2132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2087 "</|DSML|tool_calls>\n\n"
2088 "String parameters should be specified as raw text and set `string=\"true\"`. "
2089 "Preserve characters such as `>`, `&`, and `&&` exactly; never replace normal string characters with XML or HTML entity escapes. "
2090 "Only if a string value itself contains the exact closing parameter tag `</|DSML|parameter>`, write that tag as `&lt;/|DSML|parameter>` inside the value. "
2091 "For all other types (numbers, booleans, arrays, objects), pass the value in JSON format and set `string=\"false\"`.\n\n"
2092 "When thinking mode is enabled, finish reasoning with </think> before any tool calls or final response.\n\n"
2093 "Otherwise, output directly after </think> with tool calls or final response.\n\n"
2094 "### Available Tool Schemas\n\n");
2095 buf_puts(b, tool_schemas);
2096 buf_puts(b, "\n\nYou MUST strictly follow the above defined tool name and parameter schemas to invoke tool calls. "
2097 "Use the exact parameter names from the schemas.");
2098}
2099
2100static void append_glm_tools_prompt_text(buf *b, const char *tool_schemas) {
2101 if (!tool_schemas || !tool_schemas[0]) return;
2102 buf_puts(b,
2103 "## Tools\n\n"
2104 "You may call one or more functions to help answer the user question.\n\n"
2105 "You are provided with function signatures within <tools></tools> XML tags:\n"
2106 "<tools>\n");
2107 buf_puts(b, tool_schemas);
2108 buf_puts(b,
2109 "\n</tools>\n\n"
2110 "For each function call, use exactly this XML format:\n"
2111 "<tool_call>{function-name}"
2112 "<arg_key>{argument-name}</arg_key>"
2113 "<arg_value>{argument-value}</arg_value>"
2114 "</tool_call>\n\n"
2115 "Emit one <tool_call> block per function call. Use the exact tool and argument names from the schemas.");
2116}
2117
2118static void json_escape(buf *b, const char *s);
2119
2120typedef struct {
2121 char *key;
2122 char *value;
2123 bool is_string;
2124 bool used;
2125} json_arg;
2126
2127typedef struct {
2128 json_arg *v;
2129 int len;
2130 int cap;
2131} json_args;
2132
2133static void json_args_free(json_args *args) {
2134 for (int i = 0; i < args->len; i++) {
2135 free(args->v[i].key);

Callers 2

Calls 6

json_wsFunction · 0.85
json_stringFunction · 0.85
json_raw_valueFunction · 0.85
json_minify_raw_valueFunction · 0.85
json_args_pushFunction · 0.85
json_args_freeFunction · 0.85

Tested by

no test coverage detected