Xingyao Wang 98d4884ced fix(controller): stop when run into loop (#4579) hai 1 ano
..
agenthub c4f5c07be1 Refactor: shorter syntax (#4558) hai 1 ano
controller 98d4884ced fix(controller): stop when run into loop (#4579) hai 1 ano
core 1f23dc89b6 fix(eval): add runtime.connect to all eval harness (#4565) hai 1 ano
events d4e3982a6b Small refactor : EventStream as a dataclass (#4557) hai 1 ano
linter ec3152b6e1 linter: only lint on updated lines in the new file (#4409) hai 1 ano
llm 7340b78962 feat(eval): rewrite log_completions to save completions to directory (#4566) hai 1 ano
memory da23189e4c refactor: move get_pairs from memory to shared utils (#4411) hai 1 ano
runtime 1f23dc89b6 fix(eval): add runtime.connect to all eval harness (#4565) hai 1 ano
security ee2c2ff2b8 Feat changed "is_confirmed" to "confirmation_state" (#4508) hai 1 ano
server c3da25febc Fix for docker leak (#4560) hai 1 ano
storage 641a15356f Better AWS S3 storage support (#4195) hai 1 ano
utils da548d308c [agent] LLM-based editing (#3985) hai 1 ano
README.md dc0a1f3940 Fix wrong doc url (#3531) hai 1 ano
__init__.py 568c8ce993 Runtime build fixes for OpenHands as a python library (#3989) hai 1 ano
py.typed 6ce77e157b Fix pypi build (#3548) hai 1 ano

README.md

OpenHands Architecture

This directory contains the core components of OpenHands.

This diagram provides an overview of the roles of each component and how they communicate and collaborate. OpenHands System Architecture Diagram (July 4, 2024)

Classes

The key classes in OpenHands are:

  • LLM: brokers all interactions with large language models. Works with any underlying completion model, thanks to LiteLLM.
  • Agent: responsible for looking at the current State, and producing an Action that moves one step closer toward the end-goal.
  • AgentController: initializes the Agent, manages State, and drive the main loop that pushes the Agent forward, step by step
  • State: represents the current state of the Agent's task. Includes things like the current step, a history of recent events, the Agent's long-term plan, etc
  • EventStream: a central hub for Events, where any component can publish Events, or listen for Events published by other components
    • Event: an Action or Observeration
      • Action: represents a request to e.g. edit a file, run a command, or send a message
      • Observation: represents information collected from the environment, e.g. file contents or command output
  • Runtime: responsible for performing Actions, and sending back Observations
    • Sandbox: the part of the runtime responsible for running commands, e.g. inside of Docker
  • Server: brokers OpenHands sessions over HTTP, e.g. to drive the frontend
    • Session: holds a single EventStream, a single AgentController, and a single Runtime. Generally represents a single task (but potentially including several user prompts)
    • SessionManager: keeps a list of active sessions, and ensures requests are routed to the correct Session

Control Flow

Here's the basic loop (in pseudocode) that drives agents.

while True:
  prompt = agent.generate_prompt(state)
  response = llm.completion(prompt)
  action = agent.parse_response(response)
  observation = runtime.run(action)
  state = state.update(action, observation)

In reality, most of this is achieved through message passing, via the EventStream. The EventStream serves as the backbone for all communication in OpenHands.

flowchart LR
  Agent--Actions-->AgentController
  AgentController--State-->Agent
  AgentController--Actions-->EventStream
  EventStream--Observations-->AgentController
  Runtime--Observations-->EventStream
  EventStream--Actions-->Runtime
  Frontend--Actions-->EventStream

Runtime

Please refer to the documentation to learn more about Runtime.