Skip to content

symfonic.core.state

state

BaseAgentState — typed conversation + context state contract.

Per TDD §2.2: Nodes never mutate state directly. They return partial dicts that LangGraph merges via reducers.

BaseAgentState

Bases: TypedDict

Typed state contract for all nodes in the graph.

Used as a TypedDict schema for LangGraph's StateGraph. total=False makes all fields optional at construction time.

add_context

add_context(
    state: dict[str, Any], key: str, value: Any
) -> dict[str, Any]

Returns partial state dict. Caller is responsible for non-overlapping keys.

Source code in src/symfonic/core/state.py
def add_context(state: dict[str, Any], key: str, value: Any) -> dict[str, Any]:
    """Returns partial state dict. Caller is responsible for non-overlapping keys."""
    return {key: value}

append_message

append_message(
    state: dict[str, Any], message: BaseMessage
) -> dict[str, Any]

Returns partial state dict for LangGraph merge. Never mutates state directly.

Source code in src/symfonic/core/state.py
def append_message(state: dict[str, Any], message: BaseMessage) -> dict[str, Any]:
    """Returns partial state dict for LangGraph merge. Never mutates state directly."""
    return {"messages": [message]}

set_final_response

set_final_response(
    state: dict[str, Any], text: str
) -> dict[str, Any]

Returns partial state dict setting final_response.

Source code in src/symfonic/core/state.py
def set_final_response(state: dict[str, Any], text: str) -> dict[str, Any]:
    """Returns partial state dict setting final_response."""
    return {"final_response": text}