""" Export Agent - Generates formatted reports and exports """ import logging from typing import List, Dict from datetime import datetime from agents.base_agent import BaseAgent from models.document import Summary logger = logging.getLogger(__name__) class ExportAgent(BaseAgent): """Agent that exports summaries and reports in various formats""" def __init__(self, llm_client=None, model: str = "llama3.2"): """ Initialize export agent Args: llm_client: Optional shared LLM client model: Ollama model name """ super().__init__(name="ExportAgent", llm_client=llm_client, model=model) logger.info(f"{self.name} initialized") def process(self, content: Dict, format: str = "markdown") -> str: """ Export content in specified format Args: content: Content dictionary to export format: Export format ('markdown', 'text', 'html') Returns: Formatted content string """ logger.info(f"{self.name} exporting as {format}") if format == "markdown": return self._export_markdown(content) elif format == "text": return self._export_text(content) elif format == "html": return self._export_html(content) else: return str(content) def _export_markdown(self, content: Dict) -> str: """Export as Markdown""" md = [] md.append(f"# Knowledge Report") md.append(f"\n*Generated: {datetime.now().strftime('%Y-%m-%d %H:%M')}*\n") if 'title' in content: md.append(f"## {content['title']}\n") if 'summary' in content: md.append(f"### Summary\n") md.append(f"{content['summary']}\n") if 'key_points' in content and content['key_points']: md.append(f"### Key Points\n") for point in content['key_points']: md.append(f"- {point}") md.append("") if 'sections' in content: for section in content['sections']: md.append(f"### {section['title']}\n") md.append(f"{section['content']}\n") if 'sources' in content and content['sources']: md.append(f"### Sources\n") for i, source in enumerate(content['sources'], 1): md.append(f"{i}. {source}") md.append("") return "\n".join(md) def _export_text(self, content: Dict) -> str: """Export as plain text""" lines = [] lines.append("=" * 60) lines.append("KNOWLEDGE REPORT") lines.append(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M')}") lines.append("=" * 60) lines.append("") if 'title' in content: lines.append(content['title']) lines.append("-" * len(content['title'])) lines.append("") if 'summary' in content: lines.append("SUMMARY:") lines.append(content['summary']) lines.append("") if 'key_points' in content and content['key_points']: lines.append("KEY POINTS:") for i, point in enumerate(content['key_points'], 1): lines.append(f" {i}. {point}") lines.append("") if 'sections' in content: for section in content['sections']: lines.append(section['title'].upper()) lines.append("-" * 40) lines.append(section['content']) lines.append("") if 'sources' in content and content['sources']: lines.append("SOURCES:") for i, source in enumerate(content['sources'], 1): lines.append(f" {i}. {source}") lines.append("") lines.append("=" * 60) return "\n".join(lines) def _export_html(self, content: Dict) -> str: """Export as HTML""" html = [] html.append("") html.append("") html.append("
") html.append(" ") html.append("{content['summary']}
") if 'key_points' in content and content['key_points']: html.append("{section['content']}
") if 'sources' in content and content['sources']: html.append("