Skip to main content

Messaging System

Egregore’s messaging system provides universal message handling through ProviderThread containers and ContentBlocks. This architecture enables seamless communication with 30+ AI providers using a single, consistent interface.

The Problem with Provider-Specific Formats

Traditional approaches require different message formats for each provider:
Egregore solves this with a universal message system that works identically across all providers.

Core Concepts

ProviderThread

A ProviderThread is a container that organizes messages into three categories:
  1. SystemHeader - System instructions and configuration
  2. ProviderResponse - AI model responses
  3. ClientRequest - User messages
ProviderThread automatically formats messages for any provider. You work with a universal structure, and Egregore handles provider-specific conversion.

ContentBlocks

ContentBlocks are the atomic units of content within messages:

The 3-Message-Type System

1. SystemHeader

System-level instructions that guide AI behavior:
Characteristics:
  • One per thread
  • Contains system instructions
  • Never expires (permanent)
  • Lives at depth -1 in PACT tree

2. ClientRequest

User messages sent to the AI:
Characteristics:
  • Multiple per thread
  • Contains user input
  • Can include multimedia (images, audio, etc.)
  • Stored at position 0 in PACT tree

3. ProviderResponse

AI model responses:
Characteristics:
  • Multiple per thread
  • Contains AI output
  • Can include tool calls
  • Stored at position 0 in PACT tree

ContentBlock Types

TextContent

Plain text messages:
Used in:
  • User messages
  • AI responses
  • System instructions

ImageContent

Image data in various formats:
Supported formats:
  • JPEG, PNG, GIF, WebP
  • Base64 encoded or URLs
  • Automatic provider-specific formatting

AudioContent

Audio files for speech-to-text or audio analysis:
Supported formats:
  • MP3, WAV, M4A, FLAC
  • Provider-dependent support

VideoContent

Video files for multimodal models:
Supported formats:
  • MP4, MOV, AVI
  • Provider-dependent support

DocumentContent

Documents like PDFs for document analysis:
Supported formats:
  • PDF, DOCX, TXT
  • Provider-dependent support

ToolCallContent

Function call requests from AI:
Used for:
  • AI requests to execute tools
  • Part of provider responses
  • Automatically generated by providers

ToolResultContent

Function execution results:
Used for:
  • Tool execution results
  • Sent back to AI for synthesis
  • Part of client requests

Message Flow

Basic Request-Response

Tool Call Flow

Multimedia Message Flow

ProviderThread API

Accessing Messages

Message Order

Messages are stored in chronological order:

Historical Thread Access

Access thread state from past episodes:

Provider-Specific Formatting

Automatic Format Conversion

Egregore handles conversion automatically:

Format Methods

Providers implement format methods:
You rarely need to call format methods directly. Egregore handles formatting automatically during agent.call().

Usage Tracking

Per-Message Tracking

Each message tracks token usage:

Aggregate Usage

Track total usage across conversation:

Multimodal Messages

Sending Images

Sending Multiple Content Types

Provider Support

Different providers support different content types:
Check provider capabilities before sending multimedia content. Unsupported content types will raise an error.

Message Persistence

Messages in PACT Context

Messages are stored in the PACT tree:

Serialization

ProviderThread is PACT-compliant and serializable:

Best Practices

ContentBlocks provide type safety and automatic formatting:
Verify provider support before using advanced features:
Use thread accessors instead of direct context access:
Track usage to control costs:

Common Patterns

Conversation with Context

Tool-Augmented Responses

Multimodal Analysis

Message History Export

Integration with Context System

Messages as PACT Components

Messages are stored in the context tree:

Message Metadata

Messages can have additional context components:

What’s Next?

Providers

Learn about the provider system and 30+ supported models

Multimedia Support

Deep dive into working with images, audio, and video

Context Management

Understand how messages fit into the PACT tree

Message API Reference

Complete API documentation for messaging system