feat: enhance subagent context with abort flag and implement tool call timeout

This commit is contained in:
asepharyana
2026-07-13 04:59:16 +07:00
parent 3b711bbf3b
commit 2856dd78b8
9 changed files with 272 additions and 131 deletions
+12 -7
View File
@@ -33,21 +33,26 @@ pub struct ToolFunction {
/// than a nested object; if `args` is a string, attempt to parse it as
/// JSON. Objects and other value types pass through unchanged.
///
/// Why: falling back to the raw string on parse failure (rather than
/// erroring) keeps the harness resilient to malformed provider output.
/// Security: on parse failure we wrap the raw string in `{ "_raw": "..." }`
/// instead of passing it through as a raw string, so tools that expect a
/// JSON object (via `args.get("key")`) get `None` rather than unexpectedly
/// receiving a plain string value.
///
/// Return: the parsed `Value`, or the original `args` clone if parsing fails.
/// Return: the parsed `Value`, or a wrapper object on parse failure.
pub fn sanitize_tool_arguments(args: &Value) -> Value {
match args {
Value::String(s) => {
match serde_json::from_str::<Value>(s) {
Ok(v) => v,
Err(e) => {
tracing::warn!(
"warning: tool argument is a JSON string but failed to parse: {}. Using raw string.",
e
tracing::error!(
"tool argument is a JSON string but failed to parse: {}. \
Wrapping in object to prevent tool misbehaviour. Raw was: {}",
e, s.chars().take(200).collect::<String>(),
);
args.clone()
// Wrap in a safe object so tools don't receive a raw
// string that could be misinterpreted as an object key.
serde_json::json!({"_raw": s, "_parse_error": e.to_string()})
}
}
}