@@ -112,9 +112,8 @@ func generateFallback() TaskName {
112112// We have a 5 character suffix `-ffff`.
113113// This leaves us with 27 characters for the name.
114114//
115- // Unfortunately, `namesgenerator.GetRandomName(0)` will
116- // generate names that are longer than 27 characters, so
117- // we just trim these down to length.
115+ // `namesgenerator.GetRandomName(0)` can generate names
116+ // up to 27 characters, but we truncate defensively.
118117name := strings .ReplaceAll (namesgenerator .GetRandomName (0 ),"_" ,"-" )
119118name = name [:min (len (name ),27 )]
120119name = strings .TrimSuffix (name ,"-" )
@@ -297,8 +296,15 @@ func anthropicDataStream(ctx context.Context, client anthropic.Client, model ant
297296}
298297
299298return aisdk .AnthropicToDataStream (client .Messages .NewStreaming (ctx , anthropic.MessageNewParams {
300- Model :model ,
301- MaxTokens :50 ,
299+ Model :model ,
300+ // MaxTokens is set to 100 based on the maximum expected output size.
301+ // The worst-case JSON output is 134 characters:
302+ // - Base structure: 43 chars (including formatting)
303+ // - task_name: 27 chars max
304+ // - display_name: 64 chars max
305+ // Using Anthropic's token counting API, this worst-case output tokenizes to 70 tokens.
306+ // We set MaxTokens to 100 to provide a safety buffer.
307+ MaxTokens :100 ,
302308System :system ,
303309Messages :messages ,
304310})),nil