Skip to content

Commit

Permalink
webui working for autopilot workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman Gokrani authored and Aman Gokrani committed Dec 10, 2024
1 parent 6b67462 commit 0dcc4c7
Show file tree
Hide file tree
Showing 7 changed files with 352 additions and 159 deletions.
6 changes: 3 additions & 3 deletions aide/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ async def step(self, exec_callback: ExecCallbackType = None, callback_manager=No
"exec", result_node.code, True
)

result_node = self.parse_exec_result(
result_node = await self.parse_exec_result(
node=result_node,
exec_result=exec_result,
exec_callback=exec_callback,
Expand Down Expand Up @@ -604,8 +604,8 @@ async def parse_exec_result(
node.is_buggy = (
response.is_bug
or node.exc_type is not None
or response["metric"] is None
or not response["has_csv_submission"]
or response.metric is None
or not response.has_csv_submission
or not has_csv_submission
)

Expand Down
75 changes: 16 additions & 59 deletions aide/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@
from rich.columns import Columns
from rich.console import Group
from rich.panel import Panel
from omegaconf import OmegaConf
from aide import backend
from aide.agent import Agent
from aide.callbacks.manager import CallbackManager
from aide.interpreter import Interpreter
from aide.journal import Journal
from aide.run import VerboseFilter, journal_to_rich_tree
from aide.utils.config import load_cfg, load_task_desc, prep_agent_workspace
from aide.utils.serialize import load_code_file, load_json
from aide.utils.config import load_cfg
from aide.workflow.autopilot import AutoPilot
from aide.workflow.copilot import CoPilot
from aide.callbacks.stdout import handle_exit, read_input, execute_code
Expand Down Expand Up @@ -84,49 +78,13 @@ def start(mode, config_path=None):
logger.addHandler(file_handler)
logger.addHandler(verbose_file_handler)

task_desc = load_task_desc(cfg)
task_desc_str = backend.compile_prompt_to_md(task_desc)

prep_agent_workspace(cfg)

journal = Journal()
logger.info(f'Starting run "{cfg.exp_name}"')

agent = Agent(
task_desc=task_desc_str,
cfg=cfg,
journal=journal,
)

interpreter = Interpreter(
cfg.workspace_dir, **OmegaConf.to_container(cfg.exec) # type: ignore
)

if cfg.initial_solution.exp_name is not None:
journal_json = (
cfg.log_dir.parent / cfg.initial_solution.exp_name / "journal.json"
).resolve()
prev_journal = load_json(journal_json, Journal)
if cfg.initial_solution.node_id is not None:
node = prev_journal.get(cfg.initial_solution.node_id)
else:
node = prev_journal.get_best_node()
if node is not None:
agent.journal.append(node)
elif cfg.initial_solution.code_file is not None:
assert (
cfg.initial_solution.node_id is None
and cfg.initial_solution.exp_name is None
), "Please specify either code_file or a combination of exp_name and node_id. Specifying both is not allowed."
node = load_code_file(cfg.initial_solution.code_file)
if node:
# TODO: Remove this from here once the proper place to set load this file has been identified
exec_result = interpreter.run(code=node.code)
agent.parse_exec_result(node=node, exec_result=exec_result, max_attempts=0)
agent.journal.append(node)

if mode == "autopilot":
console.print("Starting autopilot run...\n")

callback_manager = CallbackManager()
autopilot = AutoPilot(cfg, callback_manager)

progress = Progress(
TextColumn("[progress.description]{task.description}"),
Expand All @@ -138,8 +96,8 @@ def start(mode, config_path=None):
status = Status("[green]Setting up...")

def generate_display():
tree = journal_to_rich_tree(agent.journal)
progress.update(task_id, completed=len(agent.journal))
tree = journal_to_rich_tree(autopilot.journal)
progress.update(task_id, completed=len(autopilot.journal))

file_paths = [
f"Result visualization:\n[yellow]▶ {str((cfg.log_dir / 'tree_plot.html'))}",
Expand All @@ -148,13 +106,13 @@ def generate_display():
]

# Truncate the task description to a fixed number of lines
task_desc_lines = task_desc_str.strip().split("\n")
task_desc_lines = autopilot.agent.task_desc.strip().split("\n")
max_lines = 10 # Number of lines to display
if len(task_desc_lines) > max_lines:
task_desc_display = "\n".join(task_desc_lines[:max_lines])
task_desc_display += "..."
else:
task_desc_display = task_desc_str.strip()
task_desc_display = autopilot.agent.task_desc.strip()

left = Group(
Panel(Text(task_desc_display), title="Task description"),
Expand All @@ -179,7 +137,7 @@ def generate_display():

def exec_callback(*args, **kwargs):
status.update("[magenta]Executing code...")
res = interpreter.run(*args, **kwargs)
res = autopilot.interpreter.run(*args, **kwargs)
return res

def stage_start(stage_name, message=None):
Expand All @@ -190,13 +148,11 @@ def stage_start(stage_name, message=None):
else:
status.update(f"[green]{message}{stage_name}...[/green]")

callback_manager = CallbackManager()
callback_manager.register_callbacks(

autopilot.callback_manager.register_callbacks(
{"exec": exec_callback, "stage_start": stage_start}
)

autopilot = AutoPilot(agent, interpreter, cfg, callback_manager)

with Live(generate_display(), refresh_per_second=16, screen=True) as live:

def update_display(*args, **kwargs):
Expand All @@ -207,7 +163,6 @@ def update_display(*args, **kwargs):

elif mode == "copilot":
console.print("Starting copilot run...\n")

callback_manager = CallbackManager()

def stage_start(stage_name, message=None):
Expand All @@ -231,14 +186,16 @@ def stage_end():
{
"tool_output": console.print,
"user_input": read_input,
"exec": execute_code(interpreter),
"exit": handle_exit,
"stage_start": stage_start,
"stage_end": stage_end,
}
)

copilot = CoPilot(agent, interpreter, cfg, callback_manager)
copilot = CoPilot(cfg, callback_manager)

# HACK: This is a temporary fix to get the copilot interpreter callback
copilot.callback_manager.register_callback("exec", execute_code(copilot.interpreter))

asyncio.run(copilot.run())


Expand Down
Loading

0 comments on commit 0dcc4c7

Please sign in to comment.