""" Post-processing utilities for raw agent outputs. """ import json import logging from pathlib import Path from typing import Any, Dict from app.core.schemas import AgentResponse logger = logging.getLogger(__name__) def save_agent_response(response: AgentResponse, output_path: str) -> None: """ Persist an AgentResponse to a JSON file. Args: response: Parsed AgentResponse Pydantic model. output_path: Destination file path. """ path = Path(output_path) path.parent.mkdir(parents=True, exist_ok=True) response_dict = response.model_dump(mode="json") with open(path, "w", encoding="utf-8") as f: json.dump(response_dict, f, indent=4, ensure_ascii=False) logger.info("Saved structured agent response to %s", path.resolve()) def agent_response_to_dict(response: AgentResponse) -> Dict[str, Any]: """ Convert an AgentResponse Pydantic model to a plain dict for JSON serialisation. Args: response: Parsed AgentResponse. Returns: Plain dictionary. """ return response.model_dump(mode="json")