Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Doc: o1, prompt caching (#951)

Kilian Lierete49d4db0f3c3
diff --git a/docs/config/models.md b/docs/config/models.md
index 7d2377d0..a97c2adf 100644
--- a/docs/config/models.md
+++ b/docs/config/models.md
@@ -1,5 +1,61 @@
# Models
-* See [the model section](../installation/keys.md) in the installation guide for more details on how to configure models.
-* See [the model config reference](../reference/model_config.md) for the full list of model options
-* To control how the agent extracts the actions from the model response, see the [action parsers](../reference/parsers.md) reference
+!!! tip "Required reading"
+
+ See [the model section](../installation/keys.md) in the installation guide for a primer before reading the rest of this page.
+
+!!! tip "Related pages"
+
+ * See [the model config reference](../reference/model_config.md) for the full list of model options
+ * To control how the agent extracts the actions from the model response, see the [action parsers](../reference/parsers.md) reference
+
+## Notes for specific models
+
+### Local models
+
+See [the model section](../installation/keys.md) in the installation guide.
+Remember to unset spending limits and configure the action parser if you cannot support function calling.
+
+### Anthropic Claude
+
+Prompt caching makes SWE-agent several times more affordable. While this is done automatically for models like gpt-4o,
+care has to be taken for Anthropic Claude. Anthropic Claude gives you 4 cache break points per key.
+You need two of them for a single agent run (because the break points are both used to retrieve and set the cache).
+Therefore, you can only run two parallel instances of SWE-agent with [`run-batch`](../usage/batch_mode.md) per key.
+To support more parallel running instances, supply multiple keys as described below.
+
+We recommend that you check how often you hit the cache. A very simple way is to go to your trajectory directory and grep like so:
+
+```bash
+grep -o "cached_tokens=[0-9]*" django__django-11299.debug.log
+```
+
+### o1
+
+Make sure to set
+
+```yaml
+agent:
+ model:
+ top_p: null
+ temperature: 1.
+```
+
+as other values aren't supported by `o1`.
+
+## Using multiple keys
+
+We support rotating through multiple keys for [`run-batch`](../usage/batch_mode.md). For this, concatenate all keys with `:::` and set them via the `--agent.model.api_key` flag.
+Every thread (i.e., every parallel running agent that is working on one task instance) will stick to one key during the entire run, i.e., this does not break prompt caching.
+
+
+## Models for testing
+
+We also provide models for testing SWE-agent without spending any credits
+
+* `HumanModel` and `HumanThoughtModel` will prompt for input from the user that stands in for the output of the LM. This can be used to create new [demonstrations](../config/demonstrations.md#manual).
+* `ReplayModel` takes a trajectory as input and "replays it"
+* `InstantEmptySubmitTestModel` will create an empty `reproduce.py` and then submit
+
+
+% include-markdown "../_footer.md" %}
\ No newline at end of file
diff --git a/docs/installation/keys.md b/docs/installation/keys.md
index dfd816e1..58ad1fdf 100644
--- a/docs/installation/keys.md
+++ b/docs/installation/keys.md
@@ -8,11 +8,11 @@ There are two options to do this:
1. Set the corresponding [environment variables](https://www.cherryservers.com/blog/how-to-set-list-and-manage-linux-environment-variables).
2. Create a `.env` file at the root of this repository. All of the variables defined there will take the place of environment variables.
-
+3. Use `--agent.model.api_key` to set the key
Here's an example
-```
+```bash
# Remove the comment '#' in front of the line for all keys that you have set
# GITHUB_TOKEN='GitHub Token for access to private repos'
# OPENAI_API_KEY='OpenAI API Key Here if using OpenAI Model'
@@ -22,6 +22,10 @@ Here's an example
See the following links for tutorials on obtaining [Anthropic](https://docs.anthropic.com/en/api/getting-started), [OpenAI](https://platform.openai.com/docs/quickstart/step-2-set-up-your-api-key), and [Github](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) tokens.
+!!! tip "Advanced settings"
+
+ See [model config](../config/models.md) for more details on advanced settings.
+
## Supported API models
We support all models supported by [litellm](https://github.com/BerriAI/litellm), see their list [here](https://docs.litellm.ai/docs/providers).
@@ -45,13 +49,17 @@ Here are a few options for `--agent.model.name`:
Remember to document the tools in your prompt as the model will not be able to see the function signature
like with function calling.
+!!! tip "Specific models"
+
+ See [model config](../config/models.md) for more details on specific models.
+
## Using local models
We currently support all models that serve to an endpoint with an OpenAI-compatible API.
For example, to use llama, you can folloow the [litellm instructions](https://docs.litellm.ai/docs/providers/ollama) and set
-```
+```yaml
agent:
model:
name: ollama/llama2
@@ -66,21 +74,14 @@ Please use the `per_instance_call_limit` instead to limit the runtime per issue.
Please see the above note about using a config that uses the `thought_action` parser instead of the function calling parser.
-## Complete model options
+## Further reads
-!!! hint "Complete model options"
+!!! hint "Further reads"
See [our API docs](../reference/model_config.md) for all available options.
+ Our [model config page](../config/models.md) has more details on specific models and tips and tricks.
-## Models for testing
-
-We also provide models for testing SWE-agent without spending any credits
-
-* `HumanModel` and `HumanThoughtModel` will prompt for input from the user that stands in for the output of the LM. This can be used to create new [demonstrations](../config/demonstrations.md#manual).
-* `ReplayModel` takes a trajectory as input and "replays it"
-* `InstantEmptySubmitTestModel` will create an empty `reproduce.py` and then submit
-
-### Debugging
+## Debugging
* If you get `Error code: 404`, please check your configured keys, in particular
whether you set `OPENAI_API_BASE_URL` correctly (if you're not using it, the