"""Set a value in memory."""

from typing import Any

from _store import set_value

from core.pathways.context import Context
from core.pathways.models.tool import ToolOutput


async def run(
    key: str,
    value: Any,
    namespace: str = "default",
    _context: Context | None = None,
) -> ToolOutput:
    """
    Set a value in memory.

    Args:
        key: The key to store
        value: The value to store (any JSON-serializable)
        namespace: Memory namespace (e.g., "agent_host", "thread_abc")
        context: Execution context

    Returns
    -------
        {"success": bool, "key": str, "namespace": str}
    """
    set_value(namespace, key, value)

    return ToolOutput(
        success=True,
        data={
            "key": key,
            "namespace": namespace,
        },
    )
