@@ -4,7 +4,7 @@ import { getAuthorizedUserInfo } from "@/lib/auth.rsc";
44import { createPostHogClient } from "@/lib/posthog.rsc" ;
55import { anthropic , type AnthropicProviderOptions } from "@ai-sdk/anthropic" ;
66import { withTracing } from "@posthog/ai" ;
7- import { convertToModelMessages , stepCountIs , streamText , tool , type UIMessage } from "ai" ;
7+ import { convertToModelMessages , pruneMessages , stepCountIs , streamText , tool , type UIMessage } from "ai" ;
88import { NextResponse } from "next/server" ;
99import { z } from "zod" ;
1010
@@ -106,11 +106,18 @@ export async function POST(req: Request) {
106106 posthogDistinctId : userInfo . sub ,
107107 } ) ;
108108
109+ const prunedMessages = pruneMessages ( {
110+ messages : convertToModelMessages ( messages ) ,
111+ reasoning : 'none' ,
112+ toolCalls : 'before-last-message' ,
113+ emptyMessages : 'remove' ,
114+ } ) ;
115+
109116 const result = streamText ( {
110117 model : tracedModel ,
111118 providerOptions : {
112119 anthropic : {
113- thinking : { type : "enabled" , budgetTokens : 12000 } ,
120+ thinking : { type : "enabled" , budgetTokens : 2000 } ,
114121 } satisfies AnthropicProviderOptions ,
115122 } ,
116123 messages : [
@@ -134,7 +141,7 @@ export async function POST(req: Request) {
134141 } satisfies AnthropicProviderOptions ,
135142 } ,
136143 } ,
137- ...convertToModelMessages ( messages ) ,
144+ ...prunedMessages ,
138145 ] ,
139146 stopWhen : stepCountIs ( 10 ) ,
140147 tools : {
0 commit comments