File size: 2,371 Bytes
116524e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Async Learning

By default, learning (Reflect, Tag, Update, Apply) runs synchronously after each sample. With async learning, the Agent returns immediately while learning continues in the background.

## Architecture

```mermaid

graph LR

    S1[Sample 1] --> A[Agent]

    S2[Sample 2] --> A

    S3[Sample 3] --> A

    A -->|foreground| E[Environment]

    E -->|background| R1[Reflector 1]

    E --> R2[Reflector 2]

    E --> R3[Reflector 3]

    R1 --> Q[Queue]

    R2 --> Q

    R3 --> Q

    Q -->|serialized| SM[SkillManager]

    SM --> SK[Skillbook]

```

- **Reflectors** run concurrently (safe — they only read the skillbook)
- **SkillManager** runs sequentially (required — it writes to the skillbook)
- The Agent uses whatever skillbook state is available (eventual consistency)

## Basic Usage

Pass `wait=False` to `run()`:

```python

from ace import ACE



runner = ACE.from_roles(

    agent=agent,

    reflector=reflector,

    skill_manager=skill_manager,

    environment=environment,

)



# Agent returns fast — learning continues in background

results = runner.run(samples, epochs=3, wait=False)



# Use results immediately

for r in results:

    print(r)



# Wait before saving

runner.wait_for_background()

runner.save("learned.json")

```

## Monitoring Progress

```python

stats = runner.learning_stats

# {'active': 5, 'completed': 25}

```

## With ACELiteLLM

```python

from ace import ACELiteLLM, Sample, SimpleEnvironment



agent = ACELiteLLM.from_model("gpt-4o-mini")



samples = [Sample(question="...", context="", ground_truth="...")]

results = agent.learn(samples, environment=SimpleEnvironment(), wait=False)



# Agent is immediately available

answer = agent.ask("New question")



# Wait when you need to save

agent.wait_for_background()

agent.save("learned.json")

```

## Why This Architecture

| Component | Parallelizable? | Reason |
|-----------|----------------|--------|
| Reflector | Yes | Only reads the skillbook, produces independent analysis |
| SkillManager | No | Writes to the skillbook, handles deduplication |

This gives ~3x faster learning when the Reflector LLM calls run concurrently.

## What to Read Next

- [Full Pipeline Guide](full-pipeline.md) — synchronous pipeline setup
- [Testing](testing.md) — test async learning with MagicMock