Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

DocumentBlock

Carry binary or extracted-text documents through provider-neutral messages.

developer

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
}
FieldUse
MediaTypeMediaTypeDocumentPDF, MediaTypeDocumentText, MediaTypeDocumentHTML, MediaTypeDocumentCSV, MediaTypeDocumentMarkdown, MediaTypeDocumentDOCX, or MediaTypeDocumentXLSX
NameFilename or user-facing label
DataBinary document bytes
TextExtracted 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

Related: Content blocks, ToolResultBlock.

← back to documentation