OpenAI wraps tools as {"type":"function","function":{...}}. Anthropic sends * the function schema directly as {"name":...,"input_schema":...}. The DS4 * prompt wants one raw function schema per line, so unwrap OpenAI tools and keep * already-direct schemas unchanged. Responses can additionally group tools in a * namespace item; those are flattened for DSML prompt rendering while preserving *
| 1564 | if (!strcmp(key, "type")) { |
| 1565 | if (!json_string_replace(&p, &type)) { |
| 1566 | free(key); |
| 1567 | goto done; |
| 1568 | } |
| 1569 | } else if (!strcmp(key, "name")) { |
| 1570 | if (!json_string_replace(&p, &name)) { |
| 1571 | free(key); |
| 1572 | goto done; |
| 1573 | } |
| 1574 | } else if (!strcmp(key, "tools")) { |
| 1575 | if (!json_raw_value_replace(&p, &tools)) { |
| 1576 | free(key); |
| 1577 | goto done; |
| 1578 | } |
| 1579 | } else if (!json_skip_value(&p)) { |
| 1580 | free(key); |
| 1581 | goto done; |
| 1582 | } |
| 1583 | free(key); |
| 1584 | json_ws(&p); |
| 1585 | if (*p == ',') p++; |
| 1586 | json_ws(&p); |
| 1587 | } |
| 1588 | |
| 1589 | if (!type || strcmp(type, "namespace") || !name || !tools) goto done; |
| 1590 | |
| 1591 | const char *tp = tools; |
| 1592 | json_ws(&tp); |
| 1593 | if (*tp != '[') goto done; |
| 1594 | tp++; |
| 1595 | json_ws(&tp); |
| 1596 | while (*tp && *tp != ']') { |
| 1597 | char *tool_raw = NULL; |
| 1598 | if (!json_raw_value(&tp, &tool_raw)) goto done; |
| 1599 | char *wire_name = NULL; |
| 1600 | char *schema = |
| 1601 | responses_namespace_function_schema_from_tool(tool_raw, name, &wire_name); |
| 1602 | if (schema) { |
| 1603 | append_raw_json_line(schemas, schema); |
| 1604 | tool_schema_orders_add_json_wire(orders, schema, name, wire_name, false); |
| 1605 | appended = true; |
| 1606 | } |
| 1607 | free(schema); |
| 1608 | free(wire_name); |
| 1609 | free(tool_raw); |
| 1610 | json_ws(&tp); |
| 1611 | if (*tp == ',') tp++; |
| 1612 | json_ws(&tp); |