Skip to content

Commit

Permalink
feat: prompt instructions for runtimes (All-Hands-AI#6943)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Dagelic <[email protected]>
  • Loading branch information
idagelic authored Mar 5, 2025
1 parent 43bc944 commit 1ffee80
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion openhands/agenthub/codeact_agent/prompts/additional_info.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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() -%}
Expand All @@ -18,5 +19,7 @@ each of which has a corresponding port:
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_agent_instructions }}
</RUNTIME_INFORMATION>
{% endif %}
4 changes: 4 additions & 0 deletions openhands/runtime/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,7 @@ def vscode_url(self) -> str | None:
@property
def web_hosts(self) -> dict[str, int]:
return {}

@property
def additional_agent_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_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)}.'
8 changes: 7 additions & 1 deletion 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_agent_instructions: str


@dataclass
Expand Down Expand Up @@ -56,7 +57,9 @@ def __init__(
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] = {}
Expand Down Expand Up @@ -113,6 +116,9 @@ 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_agent_instructions = (
runtime.additional_agent_instructions
)

def set_repository_info(
self,
Expand Down

0 comments on commit 1ffee80

Please sign in to comment.