import os

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.anthropic import Claude
from agno.os import AgentOS
from agno.tools.mcp import MCPTools

clickup_agent = Agent(
    name="ClickUp Assistant",
    model=Claude(id="claude-sonnet-4-5"),
    instructions=[
        "You are a ClickUp assistant. Help the user manage their ClickUp workspace.",
        "You can list spaces, folders, lists, tasks, comments, and more.",
        "You can create, update, and delete tasks, add comments, manage assignees, etc.",
        "Always confirm before performing destructive actions (deleting tasks, etc.).",
        "IMPORTANT: ClickUp has a hierarchy: Workspace > Spaces > Folders > Lists > Tasks.",
        "When the user refers to something by name, always navigate the hierarchy to resolve it:",
        "  1. First get the workspace/team hierarchy to find the correct IDs.",
        "  2. Then drill down through spaces, folders, and lists as needed.",
        "  3. Never guess IDs — always look them up by navigating from the top of the hierarchy.",
        "The user's workspace structure: Workspace='Codebuddy PVT LTD', it contains spaces like 'Dragon', folders like 'Intelbuddy', and lists like 'LAST MILE'.",
    ],
    db=SqliteDb(db_file="agno.db"),
    tools=[
        MCPTools(
            server_params={
                "command": "npx",
                "args": ["-y", "@taazkareem/clickup-mcp-server"],
                "env": {
                    "CLICKUP_API_KEY": os.getenv("CLICKUP_API_TOKEN", ""),
                    "CLICKUP_TEAM_ID": os.getenv("CLICKUP_TEAM_ID", ""),
                },
            }
        ),
    ],
    add_datetime_to_context=True,
    add_history_to_context=True,
    num_history_runs=3,
    markdown=True,
)

agent_os = AgentOS(agents=[clickup_agent], tracing=True)
app = agent_os.get_app()
