diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-08-01 10:55:38 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-08-01 10:55:38 -0700 |
commit | c4d88a8d22622d7c63ca19ba1945dd82dbc3e008 (patch) | |
tree | 0aff6b4e48878b84e911aea5a1c98697644819e2 /docs | |
parent | 2447182803877ac2d117d8353f652d62cc63d352 (diff) | |
download | sncontinue-c4d88a8d22622d7c63ca19ba1945dd82dbc3e008.tar.gz sncontinue-c4d88a8d22622d7c63ca19ba1945dd82dbc3e008.tar.bz2 sncontinue-c4d88a8d22622d7c63ca19ba1945dd82dbc3e008.zip |
docs: :memo: custom policies documentation
Diffstat (limited to 'docs')
-rw-r--r-- | docs/docs/customization.md | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/docs/docs/customization.md b/docs/docs/customization.md index 22fcbb3d..a09c4ac5 100644 --- a/docs/docs/customization.md +++ b/docs/docs/customization.md @@ -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() +) +``` |