Stream the tool calling rounds of the Anthropic messages API

This commit is contained in:
Thorsten Sommer committed 2026-09-20 10:03:20 +02:00
1 parent f951bedcc8
commit 1be0a6bfc3
9 files changed
+485 -35

No files matched your search

@@ -10,8 +10,19 @@ public sealed record AnthropicToolUse
public JsonElement Input { get; init; }
/// <summary>
/// The arguments as they came off the wire, set only when they never parsed into an object.
/// </summary>
/// <remarks>
/// Only a streamed round can have these: the arguments arrive in fragments there, and a
/// stream which ends mid-fragment leaves text which is not an object. The block carries an
/// empty object in that case, because that is what may go back to the provider -- while the
/// call itself has to be rejected rather than run without the arguments it asked for.
/// </remarks>
public string? UnparsableArguments { get; init; }
/// <summary>
/// The arguments as JSON text, which is what the tool executor works with.
/// </summary>
public string Arguments => this.Input.ValueKind is JsonValueKind.Undefined ? "{}" : this.Input.GetRawText();
public string Arguments => this.UnparsableArguments ?? (this.Input.ValueKind is JsonValueKind.Undefined ? "{}" : this.Input.GetRawText());
}