docs: 📝 custom policies documentation

This commit is contained in:
Nate Sesti 2023-08-01 10:55:38 -07:00
parent 2447182803
commit c4d88a8d22

View file

@ -192,3 +192,42 @@ config = ContinueConfig(
]
)
```
## Custom Policies
Policies can be used to deeply change the behavior of Continue, or to build agents that take longer sequences of actions on their own. The [`DefaultPolicy`](https://github.com/continuedev/continue/blob/main/continuedev/src/continuedev/plugins/policies/default.py) handles the parsing of slash commands, and otherwise always chooses the `SimpleChatStep`, but you could customize by for example always taking a "review" step after editing code. To do so, create a new `Policy` subclass that implements the `next` method:
```python
class ReviewEditsPolicy(Policy):
default_step: Step = SimpleChatStep()
def next(self, config: ContinueConfig, history: History) -> Step:
# Get the last step
last_step = history.get_current()
# If it edited code, then review the changes
if isinstance(last_step, EditHighlightedCodeStep):
return ReviewStep() # Not implemented
# Otherwise, choose between EditHighlightedCodeStep and SimpleChatStep based on slash command
if observation is not None and isinstance(last_step.observation, UserInputObservation):
if user_input.startswith("/edit"):
return EditHighlightedCodeStep(user_input=user_input[5:])
else:
return SimpleChatStep()
return self.default_step.copy()
# Don't do anything until the user enters something else
return None
```
Then, in `~/.continue/config.py`, override the default policy:
```python
config=ContinueConfig(
...
policy_override=ReviewEditsPolicy()
)
```