Commit c615ed3
committed
feat(AnthropicProvider): forced tool-use for schema-enforced structured output
Anthropic doesn't have an OpenAI-style response_format with json_schema.
The equivalent is forced tool-use: declare a single tool whose
input_schema matches the desired output shape, then force tool_choice
to that tool. The model returns a tool_use block whose input is
JSON-validated against the schema by Anthropic's own enforcement.
Two changes in AnthropicProvider:
1) Request build (buildRequestPayload): when responseFormat carries
_agentosUseToolForStructuredOutput: true plus a tool: { name,
input_schema }, prepend that tool to payload.tools and force
tool_choice: { type: 'tool', name }. Caller-provided tools survive
alongside the forced one.
2) Response mapping (mapResponseToCompletion): accept an optional
structuredOutputName. When set, find the matching tool_use block
in the response and surface JSON.stringify(block.input) as
choice.message.content. This keeps result.text semantics uniform
with OpenAI's json_schema response so session.send consumers
reading result.text get valid JSON regardless of provider.
Existing tool-call flows (caller-provided tools, normal tool_choice,
multi-step agentic loops) are unchanged; the schema mode triggers
only when the marker is set on responseFormat by the
buildResponseFormat adapter (Task 1).1 parent 3ca839a commit c615ed3
1 file changed
Lines changed: 54 additions & 3 deletions
Lines changed: 54 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
440 | 440 | | |
441 | 441 | | |
442 | 442 | | |
443 | | - | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
444 | 454 | | |
445 | 455 | | |
446 | 456 | | |
| |||
849 | 859 | | |
850 | 860 | | |
851 | 861 | | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
852 | 886 | | |
853 | 887 | | |
854 | 888 | | |
| |||
1018 | 1052 | | |
1019 | 1053 | | |
1020 | 1054 | | |
1021 | | - | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
1022 | 1059 | | |
1023 | 1060 | | |
1024 | 1061 | | |
1025 | 1062 | | |
1026 | | - | |
| 1063 | + | |
1027 | 1064 | | |
1028 | 1065 | | |
1029 | 1066 | | |
| |||
1037 | 1074 | | |
1038 | 1075 | | |
1039 | 1076 | | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
1040 | 1091 | | |
1041 | 1092 | | |
1042 | 1093 | | |
| |||
0 commit comments