
from typing import List, Any

def system_prompt(tools: List[Any]) -> str:
    """
    Build the system message that lists every available tool.
    The LLM is forced to reply with pure JSON (no markdown).
    """
    tool_desc = "\n".join(
        f"- **{t.name}**: {t.description}" for t in tools
    )
    return f"""You are a helpful AI that can solve user requests by **calling tools** when needed.
You may only reply with **valid JSON** (no extra text, no markdown).

Two possible JSON schemas:

1. Request a tool:
```json
{{
    "tool": "<tool_name>",
    "args": {{ ... }}
}}
```
   * ``tool`` must be one of the names listed below.
   * ``args`` must contain the arguments the tool expects (see its description).

2. Declare that the problem is solved:
```json
{{
    "final_answer": "Your answer to the user."
}}
```

**Available tools**:
{tool_desc}

When a tool will help, call it. When you have the answer, return ``final_answer``.
"""