ShallowCodeResearch_agent_citation_formatter
Format citations from URLs in text blocks into APA-style references using a citation formatter agent.
Instructions
Wrapper for CitationFormatterAgent to format citations. Returns: Formatted citations result with APA-style references
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text_block | No | The text containing URLs to cite |
Implementation Reference
- app.py:1008-1015 (registration)Gradio Interface registration for the citation formatter tool, exposing it as an MCP tool with api_name 'agent_citation_formatter_service' which likely corresponds to the queried tool name in the ShallowCodeResearch context.gr.Interface( fn=agent_citation_formatter, inputs=[gr.Textbox(label="Text Block with Citations", lines=12, placeholder="Enter text to format citations…")], outputs=gr.JSON(label="Formatted Citations", height=305), title="Citation Formatter Agent", description="Extracts and formats APA-style citations from text blocks.", api_name="agent_citation_formatter_service", )
- app.py:764-774 (handler)Wrapper handler function in app.py that calls the CitationFormatterAgent's format_citations method, serving as the direct MCP tool handler.def agent_citation_formatter(text_block: str) -> dict: """ Wrapper for CitationFormatterAgent to format citations. Args: text_block (str): The text containing URLs to cite Returns: dict: Formatted citations result with APA-style references """ return citation_formatter.format_citations(text_block)
- Core implementation of the citation formatting logic in CitationFormatterAgent.format_citations, extracting URLs and generating APA citations.@with_performance_tracking("citation_formatting") def format_citations(self, text_block: str) -> Dict[str, Any]: """ Extract URLs from text and produce APA-style citations. Analyzes the provided text block to identify URLs and automatically generates properly formatted academic citations following APA style guidelines for web sources. Args: text_block (str): The text content containing URLs to be cited Returns: Dict[str, Any]: A dictionary containing formatted citations array or error information if extraction fails """ try: validate_non_empty_string(text_block, "Text block") logger.info("Formatting citations from text block") urls = extract_urls_from_text(text_block) if not urls: return {"error": "No URLs found to cite.", "formatted_citations": []} citations = [] for url in urls: citation = create_apa_citation(url) citations.append(citation) logger.info(f"Successfully formatted {len(citations)} citations") return {"formatted_citations": citations, "error": None} except ValidationError as e: logger.error(f"Citation formatting validation failed: {str(e)}") return {"error": str(e), "formatted_citations": []} except Exception as e: logger.error(f"Citation formatting failed: {str(e)}") return {"error": f"Unexpected error: {str(e)}", "formatted_citations": []}
- mcp_hub/utils.py:432-452 (helper)Helper function to create individual APA-style citations from URLs, used by the citation formatter.def create_apa_citation(url: str, year: str = None) -> str: """Create a simple APA-style citation from a URL.""" if not year: year = api_config.current_year try: domain = url.split("/")[2] title = domain.replace("www.", "").split(".")[0].capitalize() return f"{title}. ({year}). Retrieved from {url}" except (IndexError, AttributeError): return f"Unknown Source. ({year}). Retrieved from {url}"