@@ -82,12 +82,21 @@ export class AnthropicProvider implements LLMProvider {
8282 description : fn . description ,
8383 input_schema : fn . parameters ,
8484 } ) ) ;
85- console . log ( 'Tools for Anthropic:' , JSON . stringify ( tools , null , 2 ) ) ;
8685 ( requestOptions as any ) . tools = tools ;
8786 }
8887
88+ console . log (
89+ 'Input Messages for Anthropic:' ,
90+ JSON . stringify ( requestOptions . messages , null , 2 ) ,
91+ ) ;
92+
8993 const response = await this . client . messages . create ( requestOptions ) ;
9094
95+ console . log (
96+ 'Response from Anthropic:' ,
97+ JSON . stringify ( response . content , null , 2 ) ,
98+ ) ;
99+
91100 // Extract content and tool calls
92101 const content =
93102 response . content . find ( ( c ) => c . type === 'text' ) ?. text || '' ;
@@ -144,21 +153,32 @@ export class AnthropicProvider implements LLMProvider {
144153 role : 'assistant' ,
145154 content : msg . content ,
146155 } ;
147- } else if ( msg . role === 'tool ' ) {
156+ } else if ( msg . role === 'tool_result ' ) {
148157 // Anthropic expects tool responses as an assistant message with tool_results
149158 return {
150- role : 'assistant ' ,
159+ role : 'user ' ,
151160 content : [
152161 {
153162 type : 'tool_result' ,
154- tool_use_id : msg . name , // Use name as the tool_use_id
163+ tool_use_id : msg . tool_use_id , // Use name as the tool_use_id
155164 content : msg . content ,
165+ is_error : msg . is_error ,
166+ } ,
167+ ] ,
168+ } ;
169+ } else if ( msg . role === 'tool_use' ) {
170+ return {
171+ role : 'assistant' ,
172+ content : [
173+ {
174+ type : 'tool_use' ,
175+ name : msg . name ,
176+ id : msg . id ,
177+ input : JSON . parse ( msg . content ) ,
156178 } ,
157179 ] ,
158180 } ;
159181 }
160-
161- // Default fallback
162182 return {
163183 role : 'user' ,
164184 content : msg . content ,
0 commit comments