Skip to content

Commit

Permalink
feat: prompt instructions for runtime
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Dagelic <[email protected]>
  • Loading branch information
idagelic committed Feb 25, 2025
1 parent 6ba79c4 commit d245561
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions openhands/runtime/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,7 @@ def vscode_url(self) -> str | None:
@property
def web_hosts(self) -> dict[str, int]:
return {}

@property
def additional_instructions(self) -> str:
return ''
4 changes: 4 additions & 0 deletions openhands/runtime/impl/daytona/daytona_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,7 @@ def vscode_url(self) -> str | None:
)

return self._vscode_url

@property
def additional_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)}.'
9 changes: 7 additions & 2 deletions openhands/utils/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@dataclass
class RuntimeInfo:
available_hosts: dict[str, int]
additional_instructions: str


@dataclass
Expand All @@ -41,8 +42,9 @@ class RepositoryInfo:
{{ 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_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() -%}
Expand All @@ -51,6 +53,8 @@ class RepositoryInfo:
When starting a web server, use the corresponding ports. You should also
set any options to allow iframes and CORS requests, and allow the server to
be accessed from any host (e.g. 0.0.0.0).
{% endif %}
{{ runtime_info.additional_instructions }}
</RUNTIME_INFORMATION>
{% endif %}
"""
Expand Down Expand Up @@ -82,7 +86,7 @@ def __init__(
self.repository_info: RepositoryInfo | None = None
self.system_template: Template = self._load_template('system_prompt')
self.user_template: Template = self._load_template('user_prompt')
self.runtime_info = RuntimeInfo(available_hosts={})
self.runtime_info = RuntimeInfo(available_hosts={}, additional_instructions='')

self.knowledge_microagents: dict[str, KnowledgeMicroAgent] = {}
self.repo_microagents: dict[str, RepoMicroAgent] = {}
Expand Down Expand Up @@ -139,6 +143,7 @@ def get_system_message(self) -> str:

def set_runtime_info(self, runtime: Runtime) -> None:
self.runtime_info.available_hosts = runtime.web_hosts
self.runtime_info.additional_instructions = runtime.additional_instructions

def set_repository_info(
self,
Expand Down

0 comments on commit d245561

Please sign in to comment.