Skip to main content
Glama
utils.py1.38 kB
"""Utilities for file persistence and helpers.""" import json import logging import re from datetime import datetime from pathlib import Path from typing import Any from .config import settings logger = logging.getLogger(__name__) def save_execution_result( content: str, prefix: str = "result", metadata: dict[str, Any] | None = None, ) -> Path: """Save execution result to a file in the results directory. Args: content: The text content to save (markdown/text). prefix: Filename prefix (e.g., 'agent', 'research'). metadata: Optional metadata to save alongside in a .json file. Returns: Path to the saved file. """ results_dir = settings.get_results_dir() timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") # Sanitize prefix for filesystem safe_prefix = re.sub(r"[^\w\-]", "_", prefix)[:30] filename = f"{timestamp}_{safe_prefix}.md" file_path = results_dir / filename file_path.write_text(content, encoding="utf-8") if metadata: meta_path = file_path.with_suffix(".json") meta_full = { "timestamp": datetime.now().isoformat(), "file": filename, **metadata, } meta_path.write_text(json.dumps(meta_full, indent=2), encoding="utf-8") logger.info(f"Saved result to {file_path}") return file_path

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Saik0s/mcp-browser-use'

If you have feedback or need assistance with the MCP directory API, please join our Discord server