π OpenHands: AI-Driven Development
feat: prompt instructions for runtimes (#6943)
Ivan Dagelic1ffee80dcbd5
diff --git a/openhands/agenthub/codeact_agent/prompts/additional_info.j2 b/openhands/agenthub/codeact_agent/prompts/additional_info.j2index 0289ded25e..74f6e30e4e 100644--- a/openhands/agenthub/codeact_agent/prompts/additional_info.j2+++ b/openhands/agenthub/codeact_agent/prompts/additional_info.j2@@ -8,8 +8,9 @@ At the user's request, repository {{ repository_info.repo_name }} has been clone{{ repository_instructions }}</REPOSITORY_INSTRUCTIONS>{% endif %}-{% if runtime_info and runtime_info.available_hosts -%}+{% if runtime_info and (runtime_info.available_hosts or runtime_info.additional_agent_instructions) -%}<RUNTIME_INFORMATION>+{% if runtime_info.available_hosts %}The user has access to the following hosts for accessing a web application,each of which has a corresponding port:{% for host, port in runtime_info.available_hosts.items() -%}@@ -18,5 +19,7 @@ each of which has a corresponding port:When starting a web server, use the corresponding ports. You should alsoset any options to allow iframes and CORS requests, and allow the server tobe accessed from any host (e.g. 0.0.0.0).+{% endif %}+{{ runtime_info.additional_agent_instructions }}</RUNTIME_INFORMATION>{% endif %}diff --git a/openhands/runtime/base.py b/openhands/runtime/base.pyindex fd3eab0a93..921d3b471d 100644--- a/openhands/runtime/base.py+++ b/openhands/runtime/base.py@@ -487,3 +487,7 @@ class Runtime(FileEditRuntimeMixin):@propertydef web_hosts(self) -> dict[str, int]:return {}++ @property+ def additional_agent_instructions(self) -> str:+ return ''diff --git a/openhands/runtime/impl/daytona/daytona_runtime.py b/openhands/runtime/impl/daytona/daytona_runtime.pyindex 437f6eeebf..bdf1df9c54 100644--- a/openhands/runtime/impl/daytona/daytona_runtime.py+++ b/openhands/runtime/impl/daytona/daytona_runtime.py@@ -260,3 +260,7 @@ class DaytonaRuntime(ActionExecutionClient):)return self._vscode_url++ @property+ def additional_agent_instructions(self) -> str:+ return f'When showing endpoints to access applications for any port, e.g. port 3000, instead of localhost:3000, use this format: {self._construct_api_url(3000)}.'diff --git a/openhands/utils/prompt.py b/openhands/utils/prompt.pyindex 62f29eee0a..171d7f991c 100644--- a/openhands/utils/prompt.py+++ b/openhands/utils/prompt.py@@ -19,6 +19,7 @@ from openhands.runtime.base import Runtime@dataclassclass RuntimeInfo:available_hosts: dict[str, int]+ additional_agent_instructions: str@dataclass@@ -56,7 +57,9 @@ class PromptManager:self.user_template: Template = self._load_template('user_prompt')self.additional_info_template: Template = self._load_template('additional_info')self.microagent_info_template: Template = self._load_template('microagent_info')- self.runtime_info = RuntimeInfo(available_hosts={})+ self.runtime_info = RuntimeInfo(+ available_hosts={}, additional_agent_instructions=''+ )self.knowledge_microagents: dict[str, KnowledgeMicroAgent] = {}self.repo_microagents: dict[str, RepoMicroAgent] = {}@@ -113,6 +116,9 @@ class PromptManager:def set_runtime_info(self, runtime: Runtime) -> None:self.runtime_info.available_hosts = runtime.web_hosts+ self.runtime_info.additional_agent_instructions = (+ runtime.additional_agent_instructions+ )def set_repository_info(self,