|
|
11 月之前 | |
|---|---|---|
| .. | ||
| config | 11 月之前 | |
| data_models | 1 年之前 | |
| mock | 11 月之前 | |
| routes | 11 月之前 | |
| session | 11 月之前 | |
| README.md | 1 年之前 | |
| __init__.py | 1 年之前 | |
| app.py | 11 月之前 | |
| auth.py | 11 月之前 | |
| file_config.py | 1 年之前 | |
| listen.py | 1 年之前 | |
| listen_socket.py | 11 月之前 | |
| middleware.py | 11 月之前 | |
| shared.py | 11 月之前 | |
| static.py | 1 年之前 | |
| types.py | 11 月之前 | |
This is a WebSocket server that executes tasks using an agent.
brew install python for those using homebrew)brew install pipx followed by pipx ensurepath)pipx install poetry)First build a distribution of the frontend code (From the project root directory):
cd frontend
npm install
npm run build
cd ..
Next run poetry shell (So you don't have to repeat poetry run)
uvicorn openhands.server.listen:app --reload --port 3000
You can use websocat to test the server.
websocat ws://127.0.0.1:3000/ws
{"action": "start", "args": {"task": "write a bash script that prints hello"}}
LLM_API_KEY=sk-... # Your Anthropic API Key
LLM_MODEL=claude-3-5-sonnet-20241022 # Default model for the agent to use
WORKSPACE_BASE=/path/to/your/workspace # Default absolute path to workspace
There are two types of messages that can be sent to, or received from, the server:
An action has three parts:
action: The action to be takenargs: The arguments for the actionmessage: A friendly message that can be put in the chat logThere are several kinds of actions. Their arguments are listed below. This list may grow over time.
initialize - initializes the agent. Only sent by client.
model - the name of the model to usedirectory - the path to the workspaceagent_cls - the class of the agent to usestart - starts a new development task. Only sent by the client.
task - the task to startread - reads the content of a file.
path - the path of the file to readwrite - writes the content to a file.
path - the path of the file to writecontent - the content to write to the filerun - runs a command.
command - the command to runbrowse - opens a web page.
url - the URL to openthink - Allows the agent to make a plan, set a goal, or record thoughts
thought - the thought to recordfinish - agent signals that the task is completedAn observation has four parts:
observation: The observation typecontent: A string representing the observed dataextras: additional structured datamessage: A friendly message that can be put in the chat logThere are several kinds of observations. Their extras are listed below. This list may grow over time.
read - the content of a file
path - the path of the file readbrowse - the HTML content of a url
url - the URL openedrun - the output of a command
command - the command runexit_code - the exit code of the commandchat - a message from the userThe following section describes the server-side components of the OpenHands project.
The session.py file defines the Session class, which represents a WebSocket session with a client. Key features include:
The agent.py file contains the AgentSession class, which manages the lifecycle of an agent within a session. Key features include:
The manager.py file defines the SessionManager class, which is responsible for managing multiple client sessions. Key features include:
The listen.py file is the main server file that sets up the FastAPI application and defines various API endpoints. Key features include:
Server Initialization:
listen.py.SessionManager is initialized.Client Connection:
Session is created or an existing one is restarted.Session initializes an AgentSession, which sets up the runtime environment and agent controller.Agent Initialization:
Event Handling:
Session manages the event stream between the client and the agent.File Operations:
Security Analysis:
Session Management:
SessionManager periodically cleans up inactive sessions.API Endpoints:
This server architecture allows for managing multiple client sessions, each with its own agent instance, runtime environment, and security analyzer. The event-driven design facilitates real-time communication between clients and agents, while the modular structure allows for easy extension and maintenance of different components.