!!! tip "Shortcut"
You can use the shortcut `agl.APO(...)` to create an APO instance.
```python
import agentlightning as agl
agl.APO(...)
```
pip install agentlightning[apo]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.
APO expects the initial prompt to be provided in the initial_resources dictionary. This can be done in two approaches:
- Pass to the [Trainer][agentlightning.Trainer] constructor:
trainer = agl.Trainer(
algorithm=agl.APO(...),
initial_resources={"main_prompt": agl.PromptTemplate(template="You are a helpful assistant.", engine="f-string")},
)- Pass to the
[APO][agentlightning.algorithm.apo.APO].set_initial_resources()method:
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 when you have multiple resources. When the key changes, the agent developer needs to update the key in the rollout method.
- Train the First Agent with APO - A step-by-step guide to training your first agent using APO.
::: agentlightning.algorithm.apo