"""smolagents (Hugging Face): ToolCallingAgent with JSON tool calls. Docstrings need an Args section."""

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "shared"))
from support import MODEL, SYSTEM_PROMPT, USER_PROMPT, get_order_status, refund_order  # noqa: E402

import litellm  # noqa: E402
from smolagents import LiteLLMModel, ToolCallingAgent, tool  # noqa: E402

# ToolCallingAgent asks for forced tool use (tool_choice="required"). Some newer Claude models reject
# forced tool choice; drop_params makes LiteLLM downgrade it to "auto" instead of raising an error.
litellm.drop_params = True


@tool
def lookup_order(order_id: str) -> str:
    """
    Look up the item, status and shipping state of an order.

    Args:
        order_id: The order ID, e.g. A-1001.
    """
    return get_order_status(order_id)


@tool
def refund(order_id: str, reason: str) -> str:
    """
    Refund an order that has not shipped yet.

    Args:
        order_id: The order ID, e.g. A-1001.
        reason: Why the customer wants a refund.
    """
    return refund_order(order_id, reason)


agent = ToolCallingAgent(
    tools=[lookup_order, refund],
    model=LiteLLMModel(model_id=f"anthropic/{MODEL}"),     # requires: pip install "smolagents[litellm]"
    instructions=SYSTEM_PROMPT,
)

if __name__ == "__main__":
    print(agent.run(USER_PROMPT))
