@@ -64,4 +64,78 @@ describe("LangChain callback handler integration tests", () => {
6464 "The result is: 100" ,
6565 ) ;
6666 } ) ;
67+
68+ it ( "should include tools and tool choice in generation input" , async ( ) => {
69+ const handler = new CallbackHandler ( ) ;
70+ const runId = "generation-with-tools" ;
71+ const tools = [
72+ {
73+ type : "function" ,
74+ function : {
75+ name : "validate_customer" ,
76+ description : "Validates a customer" ,
77+ parameters : {
78+ type : "object" ,
79+ properties : { id : { type : "string" } } ,
80+ } ,
81+ } ,
82+ } ,
83+ ] ;
84+
85+ await handler . handleGenerationStart (
86+ { id : [ "ChatOpenAI" ] } ,
87+ [ { role : "user" , content : "hi" } ] ,
88+ runId ,
89+ undefined ,
90+ {
91+ invocation_params : {
92+ model : "gpt-4.1-mini" ,
93+ temperature : 0.2 ,
94+ tools,
95+ tool_choice : "auto" ,
96+ } ,
97+ } ,
98+ ) ;
99+ await handler . handleLLMEnd ( { generations : [ [ { text : "ok" } ] ] } , runId ) ;
100+
101+ await waitForSpanExport ( testEnv . mockExporter , 1 ) ;
102+
103+ assertions . expectSpanAttributeContains (
104+ "ChatOpenAI" ,
105+ LangfuseOtelSpanAttributes . OBSERVATION_INPUT ,
106+ '"name":"validate_customer"' ,
107+ ) ;
108+ assertions . expectSpanAttributeContains (
109+ "ChatOpenAI" ,
110+ LangfuseOtelSpanAttributes . OBSERVATION_INPUT ,
111+ '"tool_choice":"auto"' ,
112+ ) ;
113+ assertions . expectSpanAttributeContains (
114+ "ChatOpenAI" ,
115+ LangfuseOtelSpanAttributes . OBSERVATION_MODEL_PARAMETERS ,
116+ '"temperature":0.2' ,
117+ ) ;
118+ } ) ;
119+
120+ it ( "should preserve message-array input without tool configuration" , async ( ) => {
121+ const handler = new CallbackHandler ( ) ;
122+ const runId = "generation-without-tools" ;
123+
124+ await handler . handleGenerationStart (
125+ { id : [ "ChatOpenAI" ] } ,
126+ [ { role : "user" , content : "hi" } ] ,
127+ runId ,
128+ undefined ,
129+ { invocation_params : { model : "gpt-4.1-mini" } } ,
130+ ) ;
131+ await handler . handleLLMEnd ( { generations : [ [ { text : "ok" } ] ] } , runId ) ;
132+
133+ await waitForSpanExport ( testEnv . mockExporter , 1 ) ;
134+
135+ assertions . expectSpanAttribute (
136+ "ChatOpenAI" ,
137+ LangfuseOtelSpanAttributes . OBSERVATION_INPUT ,
138+ '[{"role":"user","content":"hi"}]' ,
139+ ) ;
140+ } ) ;
67141} ) ;
0 commit comments