fix(agent-tools): render tool schemas without HTML-safe escapes
minijinja's tojson escapes `<`, `>`, `&` and `'` so its output can ride a script tag. A system prompt is not a script tag, so every apostrophe in a field description reached the model as \u0027 and every `<provider>` as \u003c: harder to read, and more tokens for the same text. The renderer registers a json filter that serializes through serde_json and leaves those characters alone, and both tool sections use it. tojson stays for a user template whose output does feed a page. The serialization is also compact, which drops the spaces tojson puts after every separator. The tool row is `name | arguments` with the description indented underneath, so a multi-line description can no longer push the schema column below another tool's prose, where it read as part of that tool.
This commit is contained in:
1 parent
cfb3178346
commit
1663dee661
3 files changed
+8
-6
No files matched your search
@@ -19,11 +19,12 @@ it, is the reply the user sees.
|
|||||||
{% if tools %}
|
{% if tools %}
|
||||||
## Tools
|
## Tools
|
||||||
|
|
||||||
You act through these tools (name | description | arguments). The
|
You act through these tools: each entry is its name and arguments, then
|
||||||
arguments are the JSON schema a call must satisfy.
|
what it is for. The arguments are the JSON schema a call must satisfy.
|
||||||
|
|
||||||
{% for tool in tools %}
|
{% for tool in tools %}
|
||||||
- {{ tool.name }} | {{ tool.description }} | {{ tool.parameters | tojson }}
|
- {{ tool.name }} | {{ tool.parameters | json }}
|
||||||
|
{{ tool.description | indent(2, true) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|||||||
@@ -518,9 +518,10 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.expect("renders");
|
.expect("renders");
|
||||||
assert!(prompt.contains("- my_tool | its purpose | "), "{prompt}");
|
assert!(prompt.contains("- my_tool | {"), "{prompt}");
|
||||||
|
assert!(prompt.contains("\n its purpose"), "{prompt}");
|
||||||
assert!(
|
assert!(
|
||||||
prompt.contains(r#""required": ["kind"]"#),
|
prompt.contains(r#""required":["kind"]"#),
|
||||||
"the JSON schema rendered: {prompt}"
|
"the JSON schema rendered: {prompt}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1218,7 +1218,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
assert!(
|
assert!(
|
||||||
prompt.contains(r#""required": ["command"]"#),
|
prompt.contains(r#""required":["command"]"#),
|
||||||
"bash's schema renders: {prompt}"
|
"bash's schema renders: {prompt}"
|
||||||
);
|
);
|
||||||
assert!(prompt.contains("final message"), "{prompt}");
|
assert!(prompt.contains("final message"), "{prompt}");
|
||||||
|
|||||||
Reference in new issue
Block a user