> ## 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.

# Quality Checking

> Automatic quality assessment for task outputs with memory storage

Tasks with `quality_check=True` score outputs and store high-quality results in memory.

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

agent = Agent(
    name="Writer",
    instructions="Write clear, complete articles.",
    memory=Memory(),
)

task = Task(
    description="Write a short article on AI ethics",
    expected_output="Introduction, three sections, and conclusion",
    agent=agent,
    quality_check=True,
)

AgentTeam(agents=[agent], tasks=[task]).start()
```

The user runs a team task; quality scoring decides whether outputs land in long-term memory.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    T[Task output] --> A[Assess]
    A --> S[Score]
    S -->|"> 0.7"| M[Long-term memory]
    S -->|"≤ 0.7"| X[Short-term only]

    classDef task fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef ok fill:#10B981,stroke:#7C90A0,color:#fff
    classDef skip fill:#F59E0B,stroke:#7C90A0,color:#fff

    class T task
    class A,S process
    class M ok
    class X skip
```

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant QualityChecking

    User->>Agent: Request
    Agent->>QualityChecking: Process
    QualityChecking-->>Agent: Result
    Agent-->>User: Response
```

## Quick Start

<Steps>
  <Step title="Simple Usage">
    Enable quality checking on a task (default is `True`):

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

    agent = Agent(name="Writer", instructions="Be thorough.", memory=Memory())

    task = Task(
        description="Explain quantum computing in plain English",
        expected_output="500-word explanation with examples",
        agent=agent,
        quality_check=True,
    )

    AgentTeam(agents=[agent], tasks=[task]).start()
    ```
  </Step>

  <Step title="With Configuration">
    Disable for fast runs or use execution presets:

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

    agent = Agent(name="Draft", instructions="Quick drafts only.")

    task = Task(
        description="Draft a tweet",
        agent=agent,
        quality_check=False,
    )

    AgentTeam(agents=[agent], tasks=[task]).start()
    ```
  </Step>
</Steps>

***

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Feature as Quality Checking

    User->>Agent: Request
    Agent->>Feature: Process request
    Feature-->>Agent: Result
    Agent-->>User: Response
```

When `quality_check=True` and memory is configured:

1. Agent completes the task
2. `Memory.calculate_quality_metrics()` scores completeness, relevance, clarity, accuracy via LLM
3. `finalize_task_output()` stores in long-term memory only when score exceeds **0.7**
4. Quality metadata attaches to the task result

Memory is required — without it, quality checking logs a warning and skips storage.

***

## Configuration Options

| Option            | Type     | Default | Description                                  |
| ----------------- | -------- | ------- | -------------------------------------------- |
| `quality_check`   | `bool`   | `True`  | Enable LLM quality assessment                |
| `expected_output` | `str`    | `None`  | Benchmark for scoring (strongly recommended) |
| `memory`          | `Memory` | `None`  | Required for quality storage                 |

Execution presets: `"fast"` disables quality check; `"balanced"` and `"thorough"` enable it.

***

## Best Practices

<AccordionGroup>
  <Accordion title="Always set expected_output">
    Clear expectations produce meaningful scores — vague tasks score inconsistently.
  </Accordion>

  <Accordion title="Configure memory first">
    Quality checking stores to memory — attach `memory=Memory()` to the agent or task.
  </Accordion>

  <Accordion title="Disable for drafts">
    Set `quality_check=False` on brainstorming or speed-critical tasks.
  </Accordion>

  <Accordion title="Retrieve high-quality history">
    Search with `min_quality=0.7` to reuse past strong outputs as context.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Quality-Based RAG" icon="star-half-stroke" href="/docs/features/quality-based-rag">
    Quality scoring for retrieval
  </Card>

  <Card title="Memory" icon="brain" href="/docs/features/memory">
    Memory configuration and search
  </Card>
</CardGroup>
