mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
* simplified get * resolved merge conflicts * removed default param for get * add dood setup * add readme * better build process * multi-stage build * revert makefile * rm entrypoint.sh * adjust ssh box for docker * update readme * update readme * fix hostname * change workspace setting * add workspace_mount_base * fixes for workspace dir * clean up frontend * refactor dockerfile * try download.py * change docker order a bit * remove workspace_dir from frontend settings * fix merge issues * Update opendevin/config.py * remove relpath logic from server * rename workspace_mount_base to workspace_base * remove workspace dir plumbing for now * delint * delint * move workspace base dir * remove refs to workspace_dir * factor out constant * fix local directory usage * dont require dir * fix docs * fix arg parsing for task * implement WORKSPACE_MOUNT_PATH * fix workspace dir * fix ports * fix merge issues * add makefile * revert settingsService * fix string * Add address * Update Dockerfile * Update local_box.py * fix lint * move to port 3000 --------- Co-authored-by: மனோஜ்குமார் பழனிச்சாமி <smartmanoj42857@gmail.com> Co-authored-by: enyst <engel.nyst@gmail.com>
106 lines
2.9 KiB
Python
106 lines
2.9 KiB
Python
import asyncio
|
|
import argparse
|
|
import sys
|
|
from typing import Type
|
|
|
|
import agenthub # noqa F401 (we import this to get the agents registered)
|
|
from opendevin import config
|
|
from opendevin.schema import ConfigType
|
|
from opendevin.agent import Agent
|
|
from opendevin.controller import AgentController
|
|
from opendevin.llm.llm import LLM
|
|
|
|
|
|
def read_task_from_file(file_path: str) -> str:
|
|
"""Read task from the specified file."""
|
|
with open(file_path, 'r', encoding='utf-8') as file:
|
|
return file.read()
|
|
|
|
|
|
def read_task_from_stdin() -> str:
|
|
"""Read task from stdin."""
|
|
return sys.stdin.read()
|
|
|
|
|
|
def parse_arguments():
|
|
"""Parse command-line arguments."""
|
|
parser = argparse.ArgumentParser(
|
|
description='Run an agent with a specific task')
|
|
parser.add_argument(
|
|
'-d',
|
|
'--directory',
|
|
type=str,
|
|
help='The working directory for the agent',
|
|
)
|
|
parser.add_argument(
|
|
'-t', '--task', type=str, default='', help='The task for the agent to perform'
|
|
)
|
|
parser.add_argument(
|
|
'-f',
|
|
'--file',
|
|
type=str,
|
|
help='Path to a file containing the task. Overrides -t if both are provided.',
|
|
)
|
|
parser.add_argument(
|
|
'-c',
|
|
'--agent-cls',
|
|
default='MonologueAgent',
|
|
type=str,
|
|
help='The agent class to use',
|
|
)
|
|
parser.add_argument(
|
|
'-m',
|
|
'--model-name',
|
|
default=config.get(ConfigType.LLM_MODEL),
|
|
type=str,
|
|
help='The (litellm) model name to use',
|
|
)
|
|
parser.add_argument(
|
|
'-i',
|
|
'--max-iterations',
|
|
default=config.get(ConfigType.MAX_ITERATIONS),
|
|
type=int,
|
|
help='The maximum number of iterations to run the agent',
|
|
)
|
|
parser.add_argument(
|
|
'-n',
|
|
'--max-chars',
|
|
default=config.get(ConfigType.MAX_CHARS),
|
|
type=int,
|
|
help='The maximum number of characters to send to and receive from LLM per task',
|
|
)
|
|
args, _ = parser.parse_known_args()
|
|
return args
|
|
|
|
|
|
async def main():
|
|
"""Main coroutine to run the agent controller with task input flexibility."""
|
|
args = parse_arguments()
|
|
|
|
# Determine the task source
|
|
if args.file:
|
|
task = read_task_from_file(args.file)
|
|
elif args.task:
|
|
task = args.task
|
|
elif not sys.stdin.isatty():
|
|
task = read_task_from_stdin()
|
|
else:
|
|
raise ValueError(
|
|
'No task provided. Please specify a task through -t, -f.')
|
|
|
|
print(
|
|
f'Running agent {args.agent_cls} (model: {args.model_name}, directory: {args.directory}) with task: "{task}"'
|
|
)
|
|
llm = LLM(args.model_name)
|
|
AgentCls: Type[Agent] = Agent.get_cls(args.agent_cls)
|
|
agent = AgentCls(llm=llm)
|
|
controller = AgentController(
|
|
agent=agent, max_iterations=args.max_iterations, max_chars=args.max_chars
|
|
)
|
|
|
|
await controller.start_loop(task)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(main())
|