haive.core.schema.prebuilt.messages.compatibility

Compatibility layer for MessagesState implementations.

This module provides adapter classes and utilities that enable backward compatibility while adding new features from the enhanced MessagesState implementation. It serves as a bridge between the old and new architectures.

Classes

MessagesStateAdapter

Adapter that enables old MessagesState instances to use new features.

Module Contents

class haive.core.schema.prebuilt.messages.compatibility.MessagesStateAdapter(messages_state)[source]

Adapter that enables old MessagesState instances to use new features. with minimal changes to their API.

This adapter wraps an existing MessagesState instance and provides methods that implement the enhanced functionality from the new MessagesState architecture.

Initialize the adapter with an existing MessagesState instance.

Parameters:

messages_state – The MessagesState instance to adapt

deduplicate_tool_calls()[source]

Remove duplicate tool calls based on tool call ID.

This is useful when the same API call might be made multiple times due to agent or LLM quirks.

Returns:

Number of duplicates removed

Return type:

int

get_completed_tool_calls()[source]

Get all completed tool calls with their responses.

This method matches tool calls in AI messages with their corresponding tool responses.

Returns:

List of ToolCallInfo objects with tool call details

Return type:

list[haive.core.schema.prebuilt.messages.utils.ToolCallInfo]

get_conversation_rounds()[source]

Get detailed information about each conversation round.

A conversation round typically consists of a human message, followed by one or more AI responses and possibly tool calls/responses.

Returns:

List of MessageRound objects with round details

Return type:

list[haive.core.schema.prebuilt.messages.utils.MessageRound]

send_tool_calls(node_name='tools')[source]

Convert tool calls from the last AI message into Send objects for LangGraph routing.

Parameters:

node_name (str) – The name of the node to send tool calls to

Returns:

Either a string (if no tool calls) or a list of Send objects

Return type:

str | list[langgraph.types.Send]

transform_ai_to_human(preserve_metadata=True, engine_id=None, engine_name=None)[source]

Transform AI messages to Human messages in place.

This is useful for agent-to-agent communication or for creating synthetic conversations.

Parameters:
  • preserve_metadata (bool) – Whether to preserve message metadata

  • engine_id (str | None) – Optional engine ID to add to transformed messages

  • engine_name (str | None) – Optional engine name to add to transformed messages

Return type:

None