mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
* move agent to langchains_agent * remove old .env * remove the old agent folder * add preliminary version of Agent abstraction * add preliminary version of the main.py * merge controlloop and main into a Agent class * add init * fix json import * fix missing arg * get langchains_agent working after abstraction * rename `research` to `agenthub` * rename: rename research to agenthub --------- Co-authored-by: huybery <huybery@gmail.com>
19 lines
737 B
Python
19 lines
737 B
Python
import subprocess
|
|
import os
|
|
|
|
def run(cmd, agent, background=False):
|
|
if background:
|
|
return run_background(cmd, agent)
|
|
result = subprocess.run(["/bin/bash", "-c", cmd], capture_output=True, text=True)
|
|
output = result.stdout + result.stderr
|
|
exit_code = result.returncode
|
|
if exit_code != 0:
|
|
raise ValueError('Command failed with exit code ' + str(exit_code) + ': ' + output)
|
|
return output
|
|
|
|
def run_background(cmd, agent):
|
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True)
|
|
agent.background_commands.append(process)
|
|
return "Background command started. To stop it, send a `kill` action with id " + str(len(agent.background_commands) - 1)
|
|
|