# src/agntrick/agents/ollama.py
"""Ollama Agent using local GLM-4.7-Flash model.

This agent uses LocalReasoningLLM to connect to a local Ollama server
running GLM-4.7-Flash with thinking tags automatically stripped from responses.
It serves as a versatile orchestrator capable of delegating to other agents.
"""

from typing import Any, Sequence

from agntrick.agent import AgentBase
from agntrick.llm.local_reasoning import get_local_developer_model
from agntrick.prompts import load_prompt
from agntrick.registry import AgentRegistry
from agntrick.tools import AgentInvocationTool


@AgentRegistry.register("ollama", mcp_servers=["web-forager", "fetch", "hacker-news"])
class OllamaAgent(AgentBase):
    """Agent using local GLM-4.7-Flash model via Ollama.

    A versatile local AI orchestrator that can:
    - Search the web and fetch content via MCP tools
    - Delegate to specialized agents (developer, learning, news, youtube)
    - Handle research, writing, and analysis tasks directly

    MCP Servers:
        web-forager: Web search for current information
        fetch: Extract clean content from URLs
        hacker-news: Access Hacker News stories and discussions

    Server Configuration:
        Make sure your Ollama server is running with:
        ollama serve --port 8080

    Usage:
        agntrick ollama -i "Your question here"
    """

    def __init__(self) -> None:
        """Initialize OllamaAgent with local GLM-4.7-Flash model."""
        # Store custom model before calling parent init
        self._custom_model = get_local_developer_model()
        # Parent sets self.model, so we provide a property to return our custom one
        super().__init__()

    @property
    def system_prompt(self) -> str:
        """Return the orchestrator system prompt."""
        return load_prompt("ollama")

    def local_tools(self) -> Sequence[Any]:
        """Return local tools including agent invocation."""
        return [AgentInvocationTool().to_langchain_tool()]

    @property
    def model(self) -> Any:
        """Return the custom LocalReasoningLLM model.

        Overrides parent's model to use LocalReasoningLLM that strips
        <reasoning>...</reasoning> tags from responses.
        """
        return self._custom_model

    @model.setter
    def model(self, value: Any) -> None:
        """No-op setter to allow parent's __init__ to set self.model."""
        pass
