85742ab165
CPU Test / Lint - next (push) Waiting to run
Dashboard / Chromatic (push) Waiting to run
CPU Test / Lint - fast (push) Waiting to run
CPU Test / Build documentation (push) Waiting to run
CPU Test / Test (Store, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Utilities, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Weave, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (AgentOps, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (LLM proxy, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Others, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Store, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Utilities, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (Weave, stable, Python 3.11) (push) Waiting to run
CPU Test / Test (AgentOps, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (LLM proxy, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Others, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Store, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Utilities, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (Weave, stable, Python 3.12) (push) Waiting to run
CPU Test / Test (AgentOps, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (LLM proxy, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (Others, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (Store, latest, Python 3.13) (push) Waiting to run
CPU Test / Lint - slow (push) Waiting to run
CPU Test / Lint - JavaScript (push) Waiting to run
CPU Test / Test (AgentOps, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (LLM proxy, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Others, legacy, Python 3.10) (push) Waiting to run
CPU Test / Test (Utilities, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (Weave, latest, Python 3.13) (push) Waiting to run
CPU Test / Test (JavaScript) (push) Waiting to run
Deploy Documentation / deploy (push) Has been cancelled
56 lines
1.8 KiB
Markdown
56 lines
1.8 KiB
Markdown
# APO
|
|
|
|
!!! tip "Shortcut"
|
|
|
|
You can use the shortcut `agl.APO(...)` to create an APO instance.
|
|
|
|
```python
|
|
import agentlightning as agl
|
|
|
|
agl.APO(...)
|
|
```
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
pip install agentlightning[apo]
|
|
```
|
|
|
|
## Scope of Current Implementation
|
|
|
|
APO is currently scoped to optimize a single prompt template. Optimizing multiple prompt templates is not supported yet.
|
|
|
|
There is however no restriction on the number of variable placeholders in the prompt template (can range from zero to many). It's possible that invalid prompts are created during the optimization process. It is up to the agent developer to ensure that the prompt template is valid for the agent's task.
|
|
|
|
## Initial Prompt
|
|
|
|
APO expects the initial prompt to be provided in the `initial_resources` dictionary. This can be done in two approaches:
|
|
|
|
1. Pass to the [Trainer][agentlightning.Trainer] constructor:
|
|
|
|
```python
|
|
trainer = agl.Trainer(
|
|
algorithm=agl.APO(...),
|
|
initial_resources={"main_prompt": agl.PromptTemplate(template="You are a helpful assistant.", engine="f-string")},
|
|
)
|
|
```
|
|
|
|
2. Pass to the `[APO][agentlightning.algorithm.apo.APO].set_initial_resources()` method:
|
|
|
|
```python
|
|
algo = agl.APO(...)
|
|
algo.set_initial_resources(
|
|
{"this_is_also_valid_key": agl.PromptTemplate(template="You are a helpful assistant.", engine="f-string")}
|
|
)
|
|
```
|
|
|
|
The resource key can be arbitrary, which is used to identify the prompt template in [class-based implementations](../tutorials/write-agents.md) when you have multiple resources. When the key changes, the agent developer needs to update the key in the `rollout` method.
|
|
|
|
## Tutorials Using APO
|
|
|
|
- [Train the First Agent with APO](../how-to/train-first-agent.md) - A step-by-step guide to training your first agent using APO.
|
|
|
|
## References
|
|
|
|
::: agentlightning.algorithm.apo
|