# Profiles

Profiles define the agent's identity, tools, and behaviour for a specific domain.

## Profile definition (`navi/profiles/base.py`)

Each profile is loaded from a directory under `navi/profiles/<id>/`:
- `config.json` — all fields below
- `system_prompt.txt` — domain-specific instructions
- `subagent_system_prompt.txt` — injected into subagents spawned from this profile (optional)

```python
@dataclass
class AgentProfile:
    id: str                        # unique identifier
    name: str
    description: str
    system_prompt: str             # loaded from system_prompt.txt
    enabled_tools: list[str]       # tools available in the main loop
    llm_backend: str = "ollama"
    model: str = "gemma4:31b-cloud"
    max_iterations: int = 10
    temperature: float = 0.7
    planning_enabled: bool = False
    short_description: str = ""    # 1-line summary shown to all profiles
    full_description: dict = {}    # keys: specialization, when_to_use, key_tools

    # Thinking mechanics (see docs/agent.md for details)
    think_enabled: bool = True
    iteration_budget_enabled: bool = True
    planning_reflect_enabled: bool = False
    goal_anchoring_enabled: bool = True
    goal_anchoring_interval: int = 5
    anti_stall_enabled: bool = True
    anti_stall_threshold: int = 8
    step_validation_enabled: bool = False
    adaptive_replan_enabled: bool = False

    # Sub-agent configuration
    subagent_tools: list[str] = []
    subagent_planning_enabled: bool = False
    subagent_system_prompt: str = ""  # loaded from subagent_system_prompt.txt
```

---

## Active profiles

| ID | Name | Model | Temp | Planning |
|---|---|---|---|---|
| `secretary` | Personal Secretary | gemma4:31b-cloud | 0.7 | Yes |
| `server_admin` | Server Administrator | gemma4:31b-cloud | 0.2 | Yes |
| `developer` | Developer | gemma4:31b-cloud | 0.2 | Yes |
| `tool_developer` | Tool Developer | gemma4:31b-cloud | 0.2 | Yes |

All profiles share a base tool set. User tools from `tools/enabled.json` are merged in at runtime.

---

## System prompt construction

The LLM sees (injected fresh on every call, never stored in session):

```
{persona.txt content}

---

{profile system_prompt.txt content}
```

`persona.txt` — global layer: personality, CONTEXT FIRST principle, self-extension rules, scratchpad/todo/memory instructions, delegation rules.

`system_prompt.txt` — domain layer: tool priorities, workflow, safety rules for this profile.

---

## Adding a profile

1. Create directory `navi/profiles/my_profile/`
2. Add `config.json`:
```json
{
  "id": "my_profile",
  "name": "My Profile",
  "description": "...",
  "short_description": "...",
  "model": "gemma4:31b-cloud",
  "temperature": 0.5,
  "max_iterations": 30,
  "planning_enabled": true,
  "think_enabled": true,
  "iteration_budget_enabled": true,
  "planning_reflect_enabled": false,
  "goal_anchoring_enabled": true,
  "goal_anchoring_interval": 5,
  "anti_stall_enabled": true,
  "anti_stall_threshold": 8,
  "step_validation_enabled": false,
  "adaptive_replan_enabled": false,
  "subagent_planning_enabled": false,
  "subagent_tools": ["todo", "filesystem", "terminal"],
  "enabled_tools": ["todo", "scratchpad", "web_search", "filesystem"]
}
```
3. Add `system_prompt.txt` with domain-specific instructions.
4. Optionally add `subagent_system_prompt.txt`.
5. The profile is auto-discovered at startup — no registration needed.

---

## Profile switching

`switch_profile` tool updates `session.profile_id` in the DB. After each tool execution batch, `run_stream()` checks for a profile change and reloads profile + tools. Takes effect on the next LLM call.

Rules (in persona): don't switch for a single off-topic question; switch when the domain clearly changes; never switch back and forth repeatedly.
