Skip to content

OSSS.ai.orchestration.state_bridge

OSSS.ai.orchestration.state_bridge

AgentContextStateBridge: Bidirectional conversion between AgentContext and LangGraph state.

This module provides the architectural foundation for LangGraph integration by enabling seamless conversion between OSSS's rich AgentContext system and LangGraph's dictionary-based state management.

Key Features: - Preserves all AgentContext features (output_map, success/failure tracking, etc.) - Bidirectional conversion with validation - Round-trip integrity testing - Comprehensive error handling

UPDATED: - Ensure execution_state (including wizard + structured_outputs) is mirrored in a non-reserved "execution_state" key for broader orchestrator visibility. - Merge both "_execution_state" and "execution_state" back into AgentContext on import so wizard state survives round-trips.

StateBridgeError

Bases: Exception

Base exception for state bridge conversion errors.

StateConversionError

Bases: StateBridgeError

Raised when state conversion fails.

StateValidationError

Bases: StateBridgeError

Raised when state validation fails.

AgentContextStateBridge

Bidirectional bridge between AgentContext and LangGraph state dictionaries.

This class provides the architectural foundation for LangGraph integration by preserving all AgentContext features while enabling seamless state conversion.

to_langgraph_state(context) staticmethod

Convert AgentContext to LangGraph state dictionary.

This method preserves all AgentContext features by serializing them into a LangGraph-compatible state dictionary format.

Parameters

context : AgentContext The AgentContext to convert

Returns

Dict[str, Any] LangGraph-compatible state dictionary

Raises

StateConversionError If conversion fails

from_langgraph_state(state_dict) staticmethod

Convert LangGraph state dictionary to AgentContext.

This method reconstructs a complete AgentContext from LangGraph state, preserving all original features and metadata.

Parameters

state_dict : Dict[str, Any] LangGraph state dictionary

Returns

AgentContext Reconstructed AgentContext

Raises

StateConversionError If conversion fails StateValidationError If state validation fails

validate_round_trip(context) staticmethod

Validate that conversion preserves all data through a round trip.

This method tests the integrity of the conversion process by converting an AgentContext to LangGraph state and back, then comparing the results.

Parameters

context : AgentContext The AgentContext to test

Returns

bool True if round trip preserves all data, False otherwise

get_state_summary(state_dict) staticmethod

Get a summary of LangGraph state for debugging and monitoring.

Parameters

state_dict : Dict[str, Any] LangGraph state dictionary

Returns

Dict[str, Any] State summary information