# Class LittleGhost::Message

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Message.html

A Message carries one participant's contribution to an agent conversation. Its
content can combine text, attachments, tool activity, and model reasoning.

Content is normalized into [Content](Content.md) blocks
held in a frozen Array. Strings become Content::Text blocks, and hashes use
the serialized content shape accepted by Content.normalize. Nested values
supplied by the caller are retained rather than defensively copied.

    message = LittleGhost::Message.new(role: :user, content: "Hello")
    message.text # => "Hello"

## Inheritance

`LittleGhost::Message < Object`

## Constants

### `ROLES`

Participant roles accepted by Message.new.

## Attributes

<a id="attribute-i-content"></a>
### `content` (R)

Participant role, normalized Content blocks, and application metadata.

<a id="attribute-i-metadata"></a>
### `metadata` (R)

Participant role, normalized Content blocks, and application metadata.

<a id="attribute-i-role"></a>
### `role` (R)

Participant role, normalized Content blocks, and application metadata.

## Class methods

<a id="method-c-coerce"></a>
### `.coerce`

```ruby
.coerce(value)
```

Keeps `value` when it is already a message, or creates a message from a hash
with string or symbol keys.

<a id="method-c-new"></a>
### `.new`

```ruby
.new(role:, content:, metadata: {})
```

Creates a frozen message with a supported `role`, normalized `content`, and
application-defined `metadata`. Metadata becomes a frozen DataMap, so String
and Symbol keys address the same JSON-compatible value.

## Instance methods

<a id="method-i-text"></a>
### `#text`

```ruby
#text()
```

Joins the visible text blocks without including reasoning or tool content.

<a id="method-i-to_h"></a>
### `#to_h`

```ruby
#to_h()
```

Produces the JSON-safe message representation.

<a id="method-i-to_json"></a>
### `#to_json`

```ruby
#to_json(*arguments)
```

Encodes #to_h as JSON, forwarding generator `arguments`.

<a id="method-i-without_reasoning"></a>
### `#without_reasoning`

```ruby
#without_reasoning()
```

Removes Content::Reasoning blocks, or keeps `self` when none are present.
