Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

Conversation

Understand the sealed Conversation interface and its four legal turns.

developer

Conversation is the closed union accepted by AgenticMessages. The unexported marker prevents an external package from pretending that an unrelated value is a conversation turn.

API surface

type Conversation interface{ isMessage() }

func (*UserMessage) isMessage()
func (*AIMessage) isMessage()
func (*SystemMessage) isMessage()
func (*ToolResultMessage) isMessage()

The marker methods are intentionally not callable outside content; the declarations above show the complete set of variants. Handle them with a type switch:

func blocksOf(m content.Conversation) []content.Block {
	switch typed := m.(type) {
	case *content.UserMessage:
		return typed.Blocks
	case *content.AIMessage:
		return typed.Blocks
	case *content.SystemMessage:
		return typed.Blocks
	case *content.ToolResultMessage:
		return typed.Blocks
	default:
		return nil
	}
}

Do not use the role string as the only discriminator. A role is a field and can be populated incorrectly; the concrete message type carries the package’s closed-world guarantee.

Proof

Related: Messages, Traverse content safely.

← back to documentation