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: Anthropic, cache control and more (#970)
Kilian Lieret1a78be6fc706
diff --git a/docs/config/models.md b/docs/config/models.mdindex a97c2adf..4517db90 100644--- a/docs/config/models.md+++ b/docs/config/models.md@@ -18,8 +18,26 @@ Remember to unset spending limits and configure the action parser if you cannot### 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.+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, as you need to manually set the cache break points.++For this, include the following history processor:++```yaml+agent:+ history_processors:+ - type: cache_control+ last_n_messages: 2+```++!!! warning "Other history processors"++ Other history processors might interfere with the prompt caching+ if you are not careful.+ However, if your history processor is only modifying the last observation,+ you can combine as done [here](https://github.com/SWE-agent/SWE-agent/blob/main/config/sweagent_heavy.yaml).++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.diff --git a/docs/reference/history_processor_config.md b/docs/reference/history_processor_config.mdindex 59e65063..e3246dbd 100644--- a/docs/reference/history_processor_config.md+++ b/docs/reference/history_processor_config.md@@ -1,8 +1,14 @@# History processor configuration+History processors can filter the history/trajectory to query the model.+For example, a very simple history processor would be one that strips away old observations to reduce context when querying the model.+::: sweagent.agent.history_processors.DefaultHistoryProcessor::: sweagent.agent.history_processors.LastNObservations::: sweagent.agent.history_processors.TagToolCallObservations+::: sweagent.agent.history_processors.CacheControlHistoryProcessor++::: sweagent.agent.history_processors.RemoveRegex\ No newline at end of filediff --git a/sweagent/agent/history_processors.py b/sweagent/agent/history_processors.pyindex 35fe9025..84d9b017 100644--- a/sweagent/agent/history_processors.py+++ b/sweagent/agent/history_processors.py@@ -223,6 +223,10 @@ class ClosedWindowHistoryProcessor(BaseModel):class CacheControlHistoryProcessor(BaseModel):+ """This history processor adds manual cache control marks to the history.+ Use this when running with anthropic claude.+ """+type: Literal["cache_control"] = "cache_control""""Do not change. Used for (de)serialization."""@@ -263,8 +267,13 @@ class CacheControlHistoryProcessor(BaseModel):class RemoveRegex(BaseModel):+ """This history processor can remove arbitrary content from history items"""+remove: list[str] = ["<diff>.*</diff>"]+ """Regex patterns to remove from history items"""+keep_last: int = 0+ """Keep the last n history items unchanged"""type: Literal["remove_regex"] = "remove_regex""""Do not change. Used for (de)serialization."""