@@ -1907,6 +1907,180 @@ Use pandas and summarize findings.`.split("\n"),
19071907 return [ ...messages ] . reverse ( ) . find ( ( message ) => message . role === "assistant" ) ;
19081908 } ;
19091909
1910+ it ( "should use temperature 0 by default when generating conversation titles" , async ( ) => {
1911+ const memory = new Memory ( {
1912+ storage : new InMemoryStorageAdapter ( ) ,
1913+ generateTitle : true ,
1914+ } ) ;
1915+ const agent = new Agent ( {
1916+ name : "TestAgent" ,
1917+ instructions : "Test" ,
1918+ model : mockModel as any ,
1919+ memory,
1920+ } ) ;
1921+ const span = {
1922+ end : vi . fn ( ) ,
1923+ setStatus : vi . fn ( ) ,
1924+ setAttribute : vi . fn ( ) ,
1925+ setAttributes : vi . fn ( ) ,
1926+ recordException : vi . fn ( ) ,
1927+ } ;
1928+ const context = {
1929+ operationId : "test-operation-id" ,
1930+ logger : {
1931+ debug : vi . fn ( ) ,
1932+ info : vi . fn ( ) ,
1933+ warn : vi . fn ( ) ,
1934+ error : vi . fn ( ) ,
1935+ trace : vi . fn ( ) ,
1936+ fatal : vi . fn ( ) ,
1937+ child : vi . fn ( ) . mockReturnThis ( ) ,
1938+ } ,
1939+ context : new Map ( ) ,
1940+ systemContext : new Map ( ) ,
1941+ isActive : true ,
1942+ traceContext : {
1943+ createChildSpan : vi . fn ( ) . mockReturnValue ( span ) ,
1944+ withSpan : vi . fn ( ) . mockImplementation ( async ( _span , fn ) => await fn ( ) ) ,
1945+ } ,
1946+ abortController : new AbortController ( ) ,
1947+ startTime : new Date ( ) ,
1948+ } ;
1949+
1950+ vi . mocked ( ai . generateText ) . mockResolvedValue ( {
1951+ text : "Rome Weekend Plan" ,
1952+ content : [ { type : "text" , text : "Rome Weekend Plan" } ] ,
1953+ reasoning : [ ] ,
1954+ files : [ ] ,
1955+ sources : [ ] ,
1956+ toolCalls : [ ] ,
1957+ toolResults : [ ] ,
1958+ finishReason : "stop" ,
1959+ usage : providerUsage ,
1960+ warnings : [
1961+ {
1962+ type : "unsupported" ,
1963+ feature : "temperature" ,
1964+ details : "temperature is not supported for reasoning models" ,
1965+ } ,
1966+ ] ,
1967+ request : { } ,
1968+ response : {
1969+ id : "test-response" ,
1970+ modelId : "test-model" ,
1971+ timestamp : new Date ( ) ,
1972+ messages : createAssistantResponseMessages ( "Rome Weekend Plan" ) ,
1973+ } ,
1974+ steps : [ ] ,
1975+ } as any ) ;
1976+
1977+ const titleGenerator = ( agent as any ) . createConversationTitleGenerator ( memory ) ;
1978+ const title = await titleGenerator ( {
1979+ input : "Plan a weekend trip to Rome." ,
1980+ context,
1981+ defaultTitle : "Conversation" ,
1982+ } ) ;
1983+
1984+ expect ( title ) . toBe ( "Rome Weekend Plan" ) ;
1985+ const generateTextCall = vi . mocked ( ai . generateText ) . mock . calls [ 0 ] [ 0 ] as Record <
1986+ string ,
1987+ unknown
1988+ > ;
1989+ expect ( generateTextCall . temperature ) . toBe ( 0 ) ;
1990+ expect ( generateTextCall . maxOutputTokens ) . toBe ( 32 ) ;
1991+ const createChildSpanCall = context . traceContext . createChildSpan . mock . calls [ 0 ] [ 2 ] as {
1992+ attributes : Record < string , unknown > ;
1993+ } ;
1994+ expect ( createChildSpanCall . attributes [ "llm.temperature" ] ) . toBe ( 0 ) ;
1995+ expect ( context . logger . warn ) . toHaveBeenCalledWith (
1996+ "[Memory] Conversation title generation model does not support temperature" ,
1997+ expect . objectContaining ( {
1998+ hint : expect . stringContaining ( "generateTitle.temperature" ) ,
1999+ warning : expect . stringContaining ( "temperature" ) ,
2000+ } ) ,
2001+ ) ;
2002+ } ) ;
2003+
2004+ it ( "should omit temperature when title generation temperature is null" , async ( ) => {
2005+ const memory = new Memory ( {
2006+ storage : new InMemoryStorageAdapter ( ) ,
2007+ generateTitle : { enabled : true , temperature : null } ,
2008+ } ) ;
2009+ const agent = new Agent ( {
2010+ name : "TestAgent" ,
2011+ instructions : "Test" ,
2012+ model : mockModel as any ,
2013+ memory,
2014+ } ) ;
2015+ const span = {
2016+ end : vi . fn ( ) ,
2017+ setStatus : vi . fn ( ) ,
2018+ setAttribute : vi . fn ( ) ,
2019+ setAttributes : vi . fn ( ) ,
2020+ recordException : vi . fn ( ) ,
2021+ } ;
2022+ const context = {
2023+ operationId : "test-operation-id" ,
2024+ logger : {
2025+ debug : vi . fn ( ) ,
2026+ info : vi . fn ( ) ,
2027+ warn : vi . fn ( ) ,
2028+ error : vi . fn ( ) ,
2029+ trace : vi . fn ( ) ,
2030+ fatal : vi . fn ( ) ,
2031+ child : vi . fn ( ) . mockReturnThis ( ) ,
2032+ } ,
2033+ context : new Map ( ) ,
2034+ systemContext : new Map ( ) ,
2035+ isActive : true ,
2036+ traceContext : {
2037+ createChildSpan : vi . fn ( ) . mockReturnValue ( span ) ,
2038+ withSpan : vi . fn ( ) . mockImplementation ( async ( _span , fn ) => await fn ( ) ) ,
2039+ } ,
2040+ abortController : new AbortController ( ) ,
2041+ startTime : new Date ( ) ,
2042+ } ;
2043+
2044+ vi . mocked ( ai . generateText ) . mockResolvedValue ( {
2045+ text : "Rome Weekend Plan" ,
2046+ content : [ { type : "text" , text : "Rome Weekend Plan" } ] ,
2047+ reasoning : [ ] ,
2048+ files : [ ] ,
2049+ sources : [ ] ,
2050+ toolCalls : [ ] ,
2051+ toolResults : [ ] ,
2052+ finishReason : "stop" ,
2053+ usage : providerUsage ,
2054+ warnings : [ ] ,
2055+ request : { } ,
2056+ response : {
2057+ id : "test-response" ,
2058+ modelId : "test-model" ,
2059+ timestamp : new Date ( ) ,
2060+ messages : createAssistantResponseMessages ( "Rome Weekend Plan" ) ,
2061+ } ,
2062+ steps : [ ] ,
2063+ } as any ) ;
2064+
2065+ const titleGenerator = ( agent as any ) . createConversationTitleGenerator ( memory ) ;
2066+ const title = await titleGenerator ( {
2067+ input : "Plan a weekend trip to Rome." ,
2068+ context,
2069+ defaultTitle : "Conversation" ,
2070+ } ) ;
2071+
2072+ expect ( title ) . toBe ( "Rome Weekend Plan" ) ;
2073+ const generateTextCall = vi . mocked ( ai . generateText ) . mock . calls [ 0 ] [ 0 ] as Record <
2074+ string ,
2075+ unknown
2076+ > ;
2077+ expect ( generateTextCall ) . not . toHaveProperty ( "temperature" ) ;
2078+ const createChildSpanCall = context . traceContext . createChildSpan . mock . calls [ 0 ] [ 2 ] as {
2079+ attributes : Record < string , unknown > ;
2080+ } ;
2081+ expect ( createChildSpanCall . attributes ) . not . toHaveProperty ( "llm.temperature" ) ;
2082+ } ) ;
2083+
19102084 it ( "should initialize with memory" , ( ) => {
19112085 const memory = new Memory ( {
19122086 storage : new InMemoryStorageAdapter ( ) ,
0 commit comments