Middleware to inject binary content (images, PDFs, audio) as HumanMessage.
The gth_read_binary tool returns binary data as a special string format:
gth_read_binary;type:${type};path:${encodedPath};data:${media_type};base64,${data}
where path is URL-encoded to handle special characters like semicolons.
This middleware:
Detects the gth_read_binary tool calls
Parses the special string format from ToolMessage content
Injects HumanMessage with binary content blocks before next model call
This works around LangChain's limitation where ToolMessage doesn't properly
support binary content blocks for most providers.
Middleware to inject binary content (images, PDFs, audio) as HumanMessage.
The gth_read_binary tool returns binary data as a special string format: gth_read_binary;type:${type};path:${encodedPath};data:${media_type};base64,${data} where path is URL-encoded to handle special characters like semicolons.
This middleware:
This works around LangChain's limitation where ToolMessage doesn't properly support binary content blocks for most providers.