> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# praisonai-train Package

> Train agents or fine-tune LLMs without installing the full PraisonAI wrapper

Train agents or fine-tune LLMs without installing the full PraisonAI wrapper.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "praisonai-train"
        Agent[🤖 Agent] --> Train[⚙️ praisonai-train agents]
        Train --> Grade[⭐ Grader / Human]
        Grade --> Better[✅ Improved Agent]
    end

    classDef input fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef grade fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class Agent input
    class Train process
    class Grade grade
    class Better output
```

The `praisonai-train` PyPI package (import: `praisonai_train`) is Tier 2c — it sits on top of `praisonaiagents` and gives you the `train` CLI group and a standalone `praisonai-train` console script.

## Quick Start

<Steps>
  <Step title="Agent Training">
    Improve an agent iteratively — no ML dependencies required.

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent

    agent = Agent(instructions="You are a helpful assistant.")
    ```

    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    pip install praisonai-train

    praisonai-train agents --input "What is Python?"
    ```
  </Step>

  <Step title="LLM Fine-tuning">
    Add the `[llm]` extra to pull the Unsloth/torch stack.

    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    pip install "praisonai-train[llm]"

    praisonai-train llm dataset.json \
        --model unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit
    ```
  </Step>
</Steps>

***

## When to Use `praisonai-train` vs `praisonai train`

Install the standalone package when you only need training; use the wrapper's `praisonai train` when you already run the full stack.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph TB
    Q1{What do I need?}
    Q1 -->|Already have the<br/>full wrapper| P1[praisonai train ...]
    Q1 -->|Just agent training| P2[pip install praisonai-train]
    Q1 -->|Agent training +<br/>LLM fine-tuning| P3["pip install praisonai-train[llm]"]
    Q1 -->|Full stack +<br/>fine-tuning deps| P4["pip install praisonai[train]"]

    classDef question fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef wrapper fill:#10B981,stroke:#7C90A0,color:#fff
    classDef runtime fill:#189AB4,stroke:#7C90A0,color:#fff

    class Q1 question
    class P1,P4 wrapper
    class P2,P3 runtime
```

Both entry points expose the same commands: every `praisonai train <sub>` also runs as `praisonai-train <sub>`.

***

## CLI Subcommands

Five subcommands cover fine-tuning and agent training.

| Subcommand                            | Purpose                                    |
| ------------------------------------- | ------------------------------------------ |
| `praisonai-train llm DATASET`         | Fine-tune an LLM via Unsloth               |
| `praisonai-train agents [AGENT_FILE]` | Iteratively train an agent                 |
| `praisonai-train list`                | List training sessions                     |
| `praisonai-train show SESSION_ID`     | Show a session's iterations and best score |
| `praisonai-train apply SESSION_ID`    | Apply learned suggestions to an agent      |

See [Train CLI](/docs/cli/train) for full flags.

***

## Common Patterns

### Train, review, apply

Run a training session, inspect the iterations, then bake the best one into your agent.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# --iterations N is a max — training stops early on a score >= 9.5 in LLM mode
praisonai-train agents --input "Explain AI" --human
praisonai-train list
praisonai-train show train-abc123 --iterations
praisonai-train apply train-abc123 --run "Explain AI"
```

### Apply in Python

Apply a session's suggestions to an agent directly.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
from praisonai_train.train.agents import apply_training

agent = Agent(instructions="You are a helpful assistant.")
apply_training(agent, session_id="train-abc123")
```

### Train on any console

The same commands run identically on macOS, Linux, and Windows — no encoding configuration needed.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Works identically on macOS/Linux/Windows — no encoding config needed
from praisonaiagents import Agent

agent = Agent(instructions="You are a helpful assistant.")
```

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# On a Windows cp1252 console, the summary renders as plain ASCII
# and the session is still persisted for later review.
praisonai-train agents --input "What is Python?"
praisonai-train show train-abc123
```

### Force all iterations

Benchmarks, regression tests, and demos that need to observe the feedback loop across every iteration should pass `--no-early-stop` (CLI) or `no_early_stop=True` (Python) so the 9.5 threshold is bypassed.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# CLI — always runs all 3 iterations
praisonai-train agents --input "What is Python?" --iterations 3 --no-early-stop
```

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
from praisonai_train.train.agents import AgentTrainer, TrainingScenario

agent = Agent(instructions="You are a helpful assistant.")
trainer = AgentTrainer(agent=agent, iterations=3, no_early_stop=True)
trainer.scenarios.append(TrainingScenario(input_text="What is Python?"))
report = trainer.run()
```

Without this flag, `--iterations` behaves as a **maximum** in LLM-as-Judge mode — training stops as soon as any iteration scores ≥ 9.5.

***

## Windows & non-UTF-8 Consoles

`praisonai-train agents` renders its summary table with emoji (`✅ PASSED`, `❌ NEEDS WORK`, `★` best-iteration marker) when stdout supports UTF-8, and automatically falls back to ASCII (`PASSED`, `NEEDS WORK`, `*`) when it doesn't. It detects the console's encoding at runtime.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph TB
    Start[praisonai-train agents] --> Detect{stdout<br/>encoding?}
    Detect -->|UTF-8| Rich[Rich table + emoji<br/>PASSED tick / star marker]
    Detect -->|cp1252 / ASCII| Safe[Rich table + ASCII labels<br/>PASSED / * marker]
    Safe --> Fallback{Rich still<br/>UnicodeEncodeError?}
    Fallback -->|No| Safe
    Fallback -->|Yes| Plain[Plain-text summary<br/>Key: value lines]

    classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef decision fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef success fill:#10B981,stroke:#7C90A0,color:#fff
    classDef fallback fill:#189AB4,stroke:#7C90A0,color:#fff

    class Start input
    class Detect,Fallback decision
    class Rich success
    class Safe,Plain fallback
```

<Note>
  The ASCII summary is the correct output on a cp1252 Windows console — not a truncation. The session is saved either way; `praisonai-train show <session-id>` re-renders it in whichever encoding your current console supports.
</Note>

***

## Exit Codes

`praisonai-train agents` reports three distinct outcomes.

| Exit  | Meaning                                                                                                                                                           |
| ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `0`   | Training completed and the report was persisted (`praisonai-train list` will show it). A warning is printed if only the console display failed to encode.         |
| `1`   | Training itself failed — the run raised an exception (including encoding errors that hit before `save_report`) or arguments were invalid. No report is persisted. |
| `130` | Interrupted by `Ctrl-C`.                                                                                                                                          |

<Tip>
  On a cp1252 Windows console, a completed training session now exits `0` even if Rich cannot render the summary emoji — you'll see `Training complete but summary could not be displayed: 'charmap' codec can't encode ...`. Run `praisonai-train show <session-id>` to inspect the persisted result. If you want the full emoji summary, run `chcp 65001` first or set `PYTHONIOENCODING=utf-8`.
</Tip>

***

## Best Practices

<AccordionGroup>
  <Accordion title="Install the base package for agent training">
    `pip install praisonai-train` pulls `praisonaiagents` plus `litellm` (needed for LLM-as-Judge grading) — enough for `agents`, `list`, `show`, and `apply`. Add `[llm]` only when you need Unsloth fine-tuning.
  </Accordion>

  <Accordion title="Use the standalone script when you don't want the wrapper">
    The `praisonai-train` console script exposes the full `train` group without installing `praisonai`. Ideal for lightweight training-only environments.
  </Accordion>

  <Accordion title="Old imports keep working">
    Existing `praisonai.train.*`, `praisonai.train_vision`, and `praisonai.upload_vision` imports still resolve to the same module objects in `praisonai_train`. Nothing to migrate.
  </Accordion>
</AccordionGroup>

<Note>
  Backward-compatible: if you already have the wrapper installed, `praisonai.train.*` imports and the `setup-conda-env` entry point continue to work unchanged.
</Note>

***

## Related

<CardGroup cols={2}>
  <Card title="Train" icon="graduation-cap" href="/docs/train">
    Training overview and fine-tuning setup.
  </Card>

  <Card title="Train CLI" icon="terminal" href="/docs/cli/train">
    Full flag reference for the five subcommands.
  </Card>

  <Card title="Installation Extras" icon="puzzle-piece" href="/docs/features/installation-extras">
    The train install matrix.
  </Card>

  <Card title="Package Tiers" icon="layer-group" href="/docs/features/architecture-tiers">
    How the six packages stack.
  </Card>

  <Card title="Windows Terminal Encoding" icon="terminal" href="/docs/features/windows-terminal-encoding">
    Fix Rich crashes and ASCII rendering on legacy Windows consoles.
  </Card>
</CardGroup>
