agent -> autopilot

This commit is contained in:
Nate Sesti 2023-06-02 00:57:57 -04:00
parent 23bceb8cbd
commit f82ccddd3b
9 changed files with 61 additions and 61 deletions

View file

@ -14,7 +14,7 @@ from .sdk import ContinueSDK
import asyncio
class Agent(ContinueBaseModel):
class Autopilot(ContinueBaseModel):
policy: Policy
ide: AbstractIdeProtocolServer
history: History = History.from_empty()
@ -116,7 +116,7 @@ class Agent(ContinueBaseModel):
async def run_from_step(self, step: "Step"):
# if self._active:
# raise RuntimeError("Agent is already running")
# raise RuntimeError("Autopilot is already running")
self._active = True
next_step = step

View file

@ -14,7 +14,7 @@ from ..libs.steps.core.core import *
from .env import get_env_var, make_sure_env_exists
class Agent:
class Autopilot:
pass
@ -43,17 +43,17 @@ class ContinueSDK:
ide: AbstractIdeProtocolServer
steps: ContinueSDKSteps
models: Models
__agent: Agent
__autopilot: Autopilot
def __init__(self, agent: Agent):
self.ide = agent.ide
self.__agent = agent
def __init__(self, autopilot: Autopilot):
self.ide = autopilot.ide
self.__autopilot = autopilot
self.steps = ContinueSDKSteps(self)
self.models = Models(self)
@property
def history(self) -> History:
return self.__agent.history
return self.__autopilot.history
async def _ensure_absolute_path(self, path: str) -> str:
if os.path.isabs(path):
@ -61,13 +61,13 @@ class ContinueSDK:
return os.path.join(await self.ide.getWorkspaceDirectory(), path)
async def run_step(self, step: Step) -> Coroutine[Observation, None, None]:
return await self.__agent._run_singular_step(step)
return await self.__autopilot._run_singular_step(step)
async def apply_filesystem_edit(self, edit: FileSystemEdit):
return await self.run_step(FileSystemEditStep(edit=edit))
async def wait_for_user_input(self) -> str:
return await self.__agent.wait_for_user_input()
return await self.__autopilot.wait_for_user_input()
async def wait_for_user_confirmation(self, prompt: str):
return await self.run_step(WaitForUserConfirmationStep(prompt=prompt))
@ -136,5 +136,5 @@ class ContinueSDK:
return ContinueConfig()
def set_loading_message(self, message: str):
# self.__agent.set_loading_message(message)
# self.__autopilot.set_loading_message(message)
raise NotImplementedError()

View file

@ -5,7 +5,7 @@ from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
from ..models.main import FileEdit, DeleteDirectory, DeleteFile, AddDirectory, AddFile, FileSystemEdit, Position, Range, RenameFile, RenameDirectory, SequentialFileSystemEdit
from ..models.filesystem import FileSystem
from ..libs.main import Agent
from ..libs.main import Autopilot
from ..libs.map_path import map_path
from ..libs.steps.main import ManualEditAction
import shutil
@ -65,15 +65,15 @@ def calculate_diff(filepath: str, original: str, updated: str) -> List[FileEdit]
# The whole usage of watchdog here should only be specific to RealFileSystem, you want to have a different "Observer" class for VirtualFileSystem, which would depend on being sent notifications
class CopyCodebaseEventHandler(PatternMatchingEventHandler):
def __init__(self, ignore_directories: List[str], ignore_patterns: List[str], agent: Agent, orig_root: str, copy_root: str, filesystem: FileSystem):
def __init__(self, ignore_directories: List[str], ignore_patterns: List[str], autopilot: Autopilot, orig_root: str, copy_root: str, filesystem: FileSystem):
super().__init__(ignore_directories=ignore_directories, ignore_patterns=ignore_patterns)
self.agent = agent
self.autopilot = autopilot
self.orig_root = orig_root
self.copy_root = copy_root
self.filesystem = filesystem
# For now, we'll just make the update immediately, but eventually need to sync with agent.
# It should be the agent that makes the update right? It's just another action, everything comes from a single stream.
# For now, we'll just make the update immediately, but eventually need to sync with autopilot.
# It should be the autopilot that makes the update right? It's just another action, everything comes from a single stream.
def _event_to_edit(self, event) -> Union[FileSystemEdit, None]:
# NOTE: You'll need to map paths to create both an action within the copy filesystem (the one you take) and one in the original fileystem (the one you'll record and allow the user to accept). Basically just need a converter built in to the FileSystemEdit class
@ -110,13 +110,13 @@ class CopyCodebaseEventHandler(PatternMatchingEventHandler):
return
edit = edit.with_mapped_paths(self.orig_root, self.copy_root)
action = ManualEditAction(edit)
self.agent.act(action)
self.autopilot.act(action)
def maintain_copy_workspace(agent: Agent, filesystem: FileSystem, orig_root: str, copy_root: str):
def maintain_copy_workspace(autopilot: Autopilot, filesystem: FileSystem, orig_root: str, copy_root: str):
observer = Observer()
event_handler = CopyCodebaseEventHandler(
[".git"], [], agent, orig_root, copy_root, filesystem)
[".git"], [], autopilot, orig_root, copy_root, filesystem)
observer.schedule(event_handler, orig_root, recursive=True)
observer.start()
try:

View file

@ -125,7 +125,7 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
pass
async def setFileOpen(self, filepath: str, open: bool = True):
# Agent needs access to this.
# Autopilot needs access to this.
await self._send_json("setFileOpen", {
"filepath": filepath,
"open": open
@ -147,12 +147,12 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
responses = await asyncio.gather(*[
self._receive_json(ShowSuggestionResponse)
for i in range(len(suggestions))
]) # WORKING ON THIS FLOW HERE. Fine now to just await for response, instead of doing something fancy with a "waiting" state on the agent.
]) # WORKING ON THIS FLOW HERE. Fine now to just await for response, instead of doing something fancy with a "waiting" state on the autopilot.
# Just need connect the suggestionId to the IDE (and the notebook)
return any([r.accepted for r in responses])
# ------------------------------- #
# Here needs to pass message onto the Agent OR Agent just subscribes.
# Here needs to pass message onto the Autopilot OR Autopilot just subscribes.
# This is where you might have triggers: plugins can subscribe to certian events
# like file changes, tracebacks, etc...
@ -160,12 +160,12 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
pass
def onTraceback(self, traceback: Traceback):
# Same as below, maybe not every agent?
# Same as below, maybe not every autopilot?
for _, session in self.session_manager.sessions.items():
session.agent.handle_traceback(traceback)
session.autopilot.handle_traceback(traceback)
def onFileSystemUpdate(self, update: FileSystemEdit):
# Access to Agent (so SessionManager)
# Access to Autopilot (so SessionManager)
pass
def onCloseNotebook(self, session_id: str):
@ -176,10 +176,10 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
pass
def onFileEdits(self, edits: List[FileEditWithFullContents]):
# Send the file edits to ALL agents.
# Send the file edits to ALL autopilots.
# Maybe not ideal behavior
for _, session in self.session_manager.sessions.items():
session.agent.handle_manual_edits(edits)
session.autopilot.handle_manual_edits(edits)
# Request information. Session doesn't matter.
async def getOpenFiles(self) -> List[str]:

View file

@ -79,26 +79,26 @@ class NotebookProtocolServer(AbstractNotebookProtocolServer):
print(e)
async def send_state_update(self):
state = self.session.agent.get_full_state().dict()
state = self.session.autopilot.get_full_state().dict()
await self._send_json("state_update", {
"state": state
})
def on_main_input(self, input: str):
# Do something with user input
asyncio.create_task(self.session.agent.accept_user_input(input))
asyncio.create_task(self.session.autopilot.accept_user_input(input))
def on_reverse_to_index(self, index: int):
# Reverse the history to the given index
asyncio.create_task(self.session.agent.reverse_to_index(index))
asyncio.create_task(self.session.autopilot.reverse_to_index(index))
def on_step_user_input(self, input: str, index: int):
asyncio.create_task(
self.session.agent.give_user_input(input, index))
self.session.autopilot.give_user_input(input, index))
def on_refinement_input(self, input: str, index: int):
asyncio.create_task(
self.session.agent.accept_refinement_input(input, index))
self.session.autopilot.accept_refinement_input(input, index))
@router.websocket("/ws")

View file

@ -5,7 +5,7 @@ from uuid import uuid4
from ..models.filesystem_edit import FileEditWithFullContents
from ..core.policy import DemoPolicy
from ..core.main import FullState
from ..core.agent import Agent
from ..core.autopilot import Autopilot
from ..libs.steps.nate import ImplementAbstractMethodStep
from .ide_protocol import AbstractIdeProtocolServer
import asyncio
@ -15,16 +15,16 @@ nest_asyncio.apply()
class Session:
session_id: str
agent: Agent
autopilot: Autopilot
ws: Union[WebSocket, None]
def __init__(self, session_id: str, agent: Agent):
def __init__(self, session_id: str, autopilot: Autopilot):
self.session_id = session_id
self.agent = agent
self.autopilot = autopilot
self.ws = None
class DemoAgent(Agent):
class DemoAutopilot(Autopilot):
first_seen: bool = False
cumulative_edit_string = ""
@ -51,18 +51,18 @@ class SessionManager:
return self.sessions[session_id]
def new_session(self, ide: AbstractIdeProtocolServer) -> str:
agent = DemoAgent(policy=DemoPolicy(), ide=ide)
autopilot = DemoAutopilot(policy=DemoPolicy(), ide=ide)
session_id = str(uuid4())
session = Session(session_id=session_id, agent=agent)
session = Session(session_id=session_id, autopilot=autopilot)
self.sessions[session_id] = session
async def on_update(state: FullState):
await session_manager.send_ws_data(session_id, "state_update", {
"state": agent.get_full_state().dict()
"state": autopilot.get_full_state().dict()
})
agent.on_update(on_update)
asyncio.create_task(agent.run_policy())
autopilot.on_update(on_update)
asyncio.create_task(autopilot.run_policy())
return session_id
def remove_session(self, session_id: str):

View file

@ -3,11 +3,12 @@
The `Core` connects the SDK and GUI with the IDE (i.e. in VS Code, a web browser, etc), enabling the steps to make changes to your code and accelerate your software development workflows.
The `Core` includes
- IDE protocol
- GUI protocol
- SDK
- Agent
- Autopilot
There is a two-way sync between an IDE and the GUI that happens through Core.
**Q: does this make sense as a concept?**
**Q: does this make sense as a concept?**

View file

@ -4,4 +4,4 @@
**Q: should we call this LLM? Perhaps just model?**
**Q: should this abstraction be connected to agent?**
**Q: should this abstraction be connected to autopilot?**

View file

@ -13,27 +13,26 @@
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
docsSidebar: [
'intro',
'create-a-recipe',
"intro",
"create-a-recipe",
{
type: 'category',
label: 'Concepts',
type: "category",
label: "Concepts",
items: [
'concepts/agent',
'concepts/core',
'concepts/gui',
'concepts/history',
'concepts/ide',
'concepts/llm',
'concepts/policy',
'concepts/recipes',
'concepts/sdk',
'concepts/step',
"concepts/autopilot",
"concepts/core",
"concepts/gui",
"concepts/history",
"concepts/ide",
"concepts/llm",
"concepts/policy",
"concepts/recipes",
"concepts/sdk",
"concepts/step",
],
},
],
};
module.exports = sidebars;
module.exports = sidebars;