Documentation / guides
DocumentBlock
Carry binary or extracted-text documents through provider-neutral messages.
DocumentBlock carries a document as bytes or extracted text. It also keeps the MIME type and an optional display name so codecs can choose the provider’s document representation.
API surface
type DocumentBlock struct {
MediaType MediaType
Name string
Data []byte
Text string
}
| Field | Use |
|---|---|
MediaType | MediaTypeDocumentPDF, MediaTypeDocumentText, MediaTypeDocumentHTML, MediaTypeDocumentCSV, MediaTypeDocumentMarkdown, MediaTypeDocumentDOCX, or MediaTypeDocumentXLSX |
Name | Filename or user-facing label |
Data | Binary document bytes |
Text | Extracted text when the caller already decoded the document |
Either Data or Text may be populated depending on how the document arrived. Core does not impose a mutual-exclusion validator; the codec decides what its wire dialect supports.
Example
package main
import "github.com/looprig/core/content"
func main() {
block := &content.DocumentBlock{
MediaType: content.MediaTypeDocumentText,
Name: "report.txt",
Text: "Revenue increased.",
}
wire, err := content.MarshalBlock(block)
if err != nil {
panic(err)
}
decoded, err := content.UnmarshalBlock(wire)
if err != nil {
panic(err)
}
_ = decoded.(*content.DocumentBlock)
}
Nested document blocks inside a tool result are found by the same recursive block codec used for top-level blocks.
Proof
- Source:
core/content/block.go,core/content/media_type.go - Tests:
core/content/block_json_test.go - Example:
core/examples/content/example_test.go
Related: Content blocks, ToolResultBlock.