@@ -94,6 +94,26 @@ import { getToolAsync } from '@/tools/utils.server'
9494
9595const logger = createLogger ( 'AgentBlockHandler' )
9696const MODEL_SAFE_RESPONSE_FORMAT_NAME = 'response_schema'
97+ const AGENT_RAW_PROVIDER_ERROR_INPUT_PATHS : readonly ResolvedSecretInputPath [ ] = [
98+ [ 'model' ] ,
99+ [ 'temperature' ] ,
100+ [ 'maxTokens' ] ,
101+ [ 'apiKey' ] ,
102+ [ 'azureEndpoint' ] ,
103+ [ 'azureApiVersion' ] ,
104+ [ 'vertexProject' ] ,
105+ [ 'vertexLocation' ] ,
106+ [ 'vertexCredential' ] ,
107+ [ 'bedrockAccessKeyId' ] ,
108+ [ 'bedrockSecretKey' ] ,
109+ [ 'bedrockRegion' ] ,
110+ [ 'reasoningEffort' ] ,
111+ [ 'verbosity' ] ,
112+ [ 'thinkingLevel' ] ,
113+ [ 'promptCaching' ] ,
114+ [ 'previousInteractionId' ] ,
115+ ]
116+ const AGENT_MEMORY_ERROR_INPUT_PATHS : readonly ResolvedSecretInputPath [ ] = [ [ 'conversationId' ] ]
97117
98118interface IndexedToolInput {
99119 tool : ToolInput
@@ -193,6 +213,10 @@ export class AgentBlockHandler implements BlockHandler {
193213 block : SerializedBlock ,
194214 inputs : AgentInputs
195215 ) : Promise < BlockOutput | StreamingExecution > {
216+ const providerErrorRegistry = ctx . resolvedSecretTraceRegistry ?. forkForInputPaths (
217+ AGENT_RAW_PROVIDER_ERROR_INPUT_PATHS
218+ )
219+ ctx . errorResolvedSecretTraceRegistry = providerErrorRegistry
196220 const toolIndexByRef = new Map < ToolInput , number > (
197221 ( inputs . tools || [ ] ) . map ( ( tool , index ) => [ tool , index ] as const )
198222 )
@@ -371,7 +395,8 @@ export class AgentBlockHandler implements BlockHandler {
371395 providerRequest ,
372396 block ,
373397 responseFormat ,
374- resultRegistry
398+ resultRegistry ,
399+ providerErrorRegistry
375400 )
376401 if ( resultRegistry ) ctx . resolvedSecretTraceRegistry = resultRegistry
377402
@@ -385,24 +410,30 @@ export class AgentBlockHandler implements BlockHandler {
385410
386411 if ( this . isStreamingExecution ( result ) ) {
387412 const streamingResult = result as StreamingExecution
388- streamingResult . diagnosticResolvedSecretTraceRegistry = settledInputRegistry
413+ streamingResult . diagnosticResolvedSecretTraceRegistry = providerErrorRegistry
414+ const memoryErrorRegistry = settledInputRegistry ?. forkForInputPaths (
415+ AGENT_MEMORY_ERROR_INPUT_PATHS
416+ )
389417 if ( filteredInputs . memoryType && filteredInputs . memoryType !== 'none' ) {
390418 return this . wrapStreamForMemoryPersistence (
391419 ctx ,
392420 filteredInputs ,
393421 streamingResult ,
394- settledInputRegistry
422+ memoryErrorRegistry
395423 )
396424 }
397425 return streamingResult
398426 }
399427
400428 if ( filteredInputs . memoryType && filteredInputs . memoryType !== 'none' ) {
429+ const memoryErrorRegistry = settledInputRegistry ?. forkForInputPaths (
430+ AGENT_MEMORY_ERROR_INPUT_PATHS
431+ )
401432 await this . persistResponseToMemory (
402433 ctx ,
403434 filteredInputs ,
404435 result as BlockOutput ,
405- settledInputRegistry
436+ memoryErrorRegistry
406437 )
407438 }
408439
@@ -2297,7 +2328,8 @@ export class AgentBlockHandler implements BlockHandler {
22972328 providerRequest : any ,
22982329 block : SerializedBlock ,
22992330 responseFormat : any ,
2300- modelRuntimeRegistry : ResolvedSecretTraceRegistry | undefined
2331+ modelRuntimeRegistry : ResolvedSecretTraceRegistry | undefined ,
2332+ providerErrorRegistry : ResolvedSecretTraceRegistry | undefined
23012333 ) : Promise < BlockOutput | StreamingExecution > {
23022334 const providerId = providerRequest . provider
23032335 const model = providerRequest . model
@@ -2369,14 +2401,13 @@ export class AgentBlockHandler implements BlockHandler {
23692401
23702402 return this . processProviderResponse ( response , block , responseFormat , ctx )
23712403 } catch ( error ) {
2372- const sourceRegistry = ctx . resolvedSecretTraceRegistry
2373- if ( sourceRegistry && modelRuntimeRegistry && sourceRegistry !== modelRuntimeRegistry ) {
2374- const diagnosticRegistry = sourceRegistry . forkForToolCall ( )
2375- diagnosticRegistry . mergeToolCallRegistry ( modelRuntimeRegistry )
2376- ctx . resolvedSecretTraceRegistry = diagnosticRegistry
2377- }
2404+ const errorRegistry = this . createErrorRegistry ( providerErrorRegistry , modelRuntimeRegistry )
2405+ ctx . errorResolvedSecretTraceRegistry = errorRegistry
2406+ const diagnosticCtx = errorRegistry
2407+ ? { ...ctx , resolvedSecretTraceRegistry : errorRegistry }
2408+ : ctx
23782409 try {
2379- this . handleExecutionError ( error , providerStartTime , providerId , model , ctx , block )
2410+ this . handleExecutionError ( error , providerStartTime , providerId , model , diagnosticCtx , block )
23802411 } finally {
23812412 if ( modelRuntimeRegistry ) {
23822413 ctx . resolvedSecretTraceRegistry = modelRuntimeRegistry . forkForPropagatedEntries ( )
@@ -2386,6 +2417,17 @@ export class AgentBlockHandler implements BlockHandler {
23862417 }
23872418 }
23882419
2420+ private createErrorRegistry (
2421+ inputRegistry : ResolvedSecretTraceRegistry | undefined ,
2422+ resultRegistry : ResolvedSecretTraceRegistry | undefined
2423+ ) : ResolvedSecretTraceRegistry | undefined {
2424+ const errorRegistry = inputRegistry ?. forkForToolCall ( ) ?? resultRegistry ?. forkForToolCall ( )
2425+ if ( errorRegistry && resultRegistry && resultRegistry !== inputRegistry ) {
2426+ errorRegistry . mergeToolCallRegistry ( resultRegistry )
2427+ }
2428+ return errorRegistry
2429+ }
2430+
23892431 private handleExecutionError (
23902432 error : any ,
23912433 startTime : number ,
@@ -2452,8 +2494,12 @@ export class AgentBlockHandler implements BlockHandler {
24522494 try {
24532495 await memoryService . appendToMemory ( ctx , inputs , { role : 'assistant' , content } )
24542496 } catch ( error ) {
2455- const diagnosticCtx = diagnosticRegistry
2456- ? { ...ctx , resolvedSecretTraceRegistry : diagnosticRegistry }
2497+ const memoryErrorRegistry = this . createErrorRegistry (
2498+ diagnosticRegistry ,
2499+ ctx . resolvedSecretTraceRegistry
2500+ )
2501+ const diagnosticCtx = memoryErrorRegistry
2502+ ? { ...ctx , resolvedSecretTraceRegistry : memoryErrorRegistry }
24572503 : ctx
24582504 logger . error (
24592505 'Failed to persist streaming response' ,
@@ -2485,8 +2531,12 @@ export class AgentBlockHandler implements BlockHandler {
24852531 workflowId : ctx . workflowId ,
24862532 } )
24872533 } catch ( error ) {
2488- const diagnosticCtx = diagnosticRegistry
2489- ? { ...ctx , resolvedSecretTraceRegistry : diagnosticRegistry }
2534+ const memoryErrorRegistry = this . createErrorRegistry (
2535+ diagnosticRegistry ,
2536+ ctx . resolvedSecretTraceRegistry
2537+ )
2538+ const diagnosticCtx = memoryErrorRegistry
2539+ ? { ...ctx , resolvedSecretTraceRegistry : memoryErrorRegistry }
24902540 : ctx
24912541 logger . error (
24922542 'Failed to persist response to memory' ,
0 commit comments