File size: 4,796 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# LiteLLM Integration

`ACELiteLLM` is the simplest way to get a self-improving agent. It bundles Agent, Reflector, SkillManager, and Skillbook into a single class with `ask()` and `learn()` methods.

## Quick Start

```python

from ace import ACELiteLLM



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



# Ask questions β€” learns patterns across them

answer = agent.ask("If all cats are animals, is Felix (a cat) an animal?")



# Save and reload

agent.save("learned.json")

```

## Parameters

### from_model()



| Parameter | Type | Default | Description |

|-----------|------|---------|-------------|

| `model` | `str` | `"gpt-4o-mini"` | LiteLLM model identifier |

| `max_tokens` | `int` | `2048` | Max tokens for responses |
| `temperature` | `float` | `0.0` | Sampling temperature |
| `api_key` | `str` | `None` | API key (or use env variable) |
| `base_url` | `str` | `None` | Custom API endpoint |
| `skillbook_path` | `str` | `None` | Path to load saved skillbook |
| `environment` | `TaskEnvironment` | `None` | Evaluation environment |
| `dedup_config` | `DeduplicationConfig` | `None` | Skill deduplication config |
| `is_learning` | `bool` | `True` | Enable/disable learning |
| `opik` | `bool` | `False` | Enable Opik observability (pipeline traces + LiteLLM per-call cost tracking) |
| `opik_project` | `str` | `"ace-framework"` | Opik project name for organizing traces |
| `opik_tags` | `list[str]` | `None` | Tags applied to every Opik trace |

## Methods

### ask()

Direct agent call using the current skillbook:

```python

answer = agent.ask("Your question", context="Optional context")

```

### learn()

Run the full ACE learning pipeline over samples:

```python

from ace import Sample, SimpleEnvironment



samples = [

    Sample(question="What is 2+2?", context="", ground_truth="4"),

]

results = agent.learn(samples, environment=SimpleEnvironment(), epochs=3)

```

### learn_from_feedback()

Learn from the last `ask()` interaction:

```python

agent.ask("What is the capital of France?")

agent.learn_from_feedback(feedback="Correct!", ground_truth="Paris")

```

### learn_from_traces()

Learn from pre-recorded execution traces:

```python

results = agent.learn_from_traces(traces, epochs=1)

```

### Lifecycle

```python

agent.save("path.json")               # Save skillbook

agent.load("path.json")               # Load skillbook

agent.enable_learning()               # Turn on learning

agent.disable_learning()              # Turn off learning

agent.wait_for_background()           # Wait for async learning

agent.learning_stats                  # Background progress

agent.skillbook                       # Current Skillbook

agent.get_strategies()                # Formatted strategies

```

## Using a Cheaper Learning Model

Use a strong model for the Agent and a cheaper one for learning:

```python

from ace import ACELiteLLM, Agent, Reflector, SkillManager



ace = ACELiteLLM(

    agent=Agent("gpt-4o"),

    reflector=Reflector("gpt-4o-mini"),

    skill_manager=SkillManager("gpt-4o-mini"),

)

```

## Deduplication

Prevent duplicate skills from accumulating:

```python

from ace import DeduplicationConfig



agent = ACELiteLLM.from_model(

    "gpt-4o-mini",

    dedup_config=DeduplicationConfig(

        enabled=True,

        embedding_model="text-embedding-3-small",

        similarity_threshold=0.85,

    ),

)

```

## Supported Providers

Any model supported by [LiteLLM](https://docs.litellm.ai/):

```python

# OpenAI

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



# Anthropic

agent = ACELiteLLM.from_model("claude-sonnet-4-5-20250929")



# Google

agent = ACELiteLLM.from_model("gemini-pro")



# Local (Ollama)

agent = ACELiteLLM.from_model("ollama/llama2")



# Custom endpoint

agent = ACELiteLLM.from_model("gpt-4o-mini", base_url="https://your-endpoint.com")

```

## Opik Observability

Enable tracing and cost tracking with a single flag:

```python

ace = ACELiteLLM.from_model("gpt-4o-mini", opik=True, opik_project="my-experiment")



# Both tracing modes are enabled:

# 1. Pipeline traces (OpikStep) β€” one trace per sample with ACE context

# 2. LiteLLM callback β€” per-LLM-call token/cost tracking



results = ace.learn(samples, environment=SimpleEnvironment(), epochs=3)

# View traces at http://localhost:5173 β†’ project "my-experiment"

```

See [Opik Observability](opik.md) for full details, environment variables, and manual setup.

## What to Read Next

- [Full Pipeline Guide](../guides/full-pipeline.md) β€” for more control over the pipeline
- [Async Learning](../guides/async-learning.md) β€” background learning with `wait=False`
- [Opik Observability](opik.md) β€” monitor costs and traces