haive.core.schema.prebuilt.messages.utils

Utility classes and functions for message processing in Haive.

This module provides common utilities used by various implementations of MessagesState, enabling advanced message analysis, transformation, and tracking features.

Classes

MessageRound

Information about a conversation round.

ToolCallInfo

Information about a completed tool call.

Functions

extract_tool_calls(message)

Extract tool calls from an AI message.

has_agent_metadata_attribute(msg)

Check if message has agent-related metadata.

has_engine_metadata_attribute(msg)

Check if message has engine-related metadata.

inject_state_into_tool_calls(tool_calls[, state_data])

Inject state data into tool call arguments.

is_real_human_message(msg)

Check if a human message is real (not transformed).

is_tool_error(msg)

Check if a tool message represents an error.

Module Contents

class haive.core.schema.prebuilt.messages.utils.MessageRound(/, **data)[source]

Bases: pydantic.BaseModel

Information about a conversation round.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

class haive.core.schema.prebuilt.messages.utils.ToolCallInfo(/, **data)[source]

Bases: pydantic.BaseModel

Information about a completed tool call.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

haive.core.schema.prebuilt.messages.utils.extract_tool_calls(message)[source]

Extract tool calls from an AI message.

Parameters:

message (langchain_core.messages.AIMessage) – The AI message to extract tool calls from

Returns:

List of tool call dictionaries

Return type:

list[dict[str, Any]]

haive.core.schema.prebuilt.messages.utils.has_agent_metadata_attribute(msg)[source]

Check if message has agent-related metadata.

Parameters:

msg (langchain_core.messages.BaseMessage) – The message to check

Returns:

True if the message has agent metadata, False otherwise

Return type:

bool

haive.core.schema.prebuilt.messages.utils.has_engine_metadata_attribute(msg)[source]

Check if message has engine-related metadata.

Parameters:

msg (langchain_core.messages.BaseMessage) – The message to check

Returns:

True if the message has engine metadata, False otherwise

Return type:

bool

haive.core.schema.prebuilt.messages.utils.inject_state_into_tool_calls(tool_calls, state_data=None)[source]

Inject state data into tool call arguments.

Parameters:
  • tool_calls (list[dict]) – List of tool call dictionaries

  • state_data (dict[str, Any] | None) – Optional state data to inject

Returns:

Modified tool calls with injected state

Return type:

list[dict]

haive.core.schema.prebuilt.messages.utils.is_real_human_message(msg)[source]

Check if a human message is real (not transformed).

Parameters:

msg (langchain_core.messages.HumanMessage) – The message to check

Returns:

True if the message is from a real human, False if transformed

Return type:

bool

haive.core.schema.prebuilt.messages.utils.is_tool_error(msg)[source]

Check if a tool message represents an error.

Parameters:

msg (langchain_core.messages.ToolMessage) – The tool message to check

Returns:

True if the message indicates an error, False otherwise

Return type:

bool