mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
fix templates
This commit is contained in:
parent
fc30ac32f0
commit
b3a02bae4f
@ -9,34 +9,33 @@ template:
|
||||
system_prompt:
|
||||
file: "system_prompt" # path to the system template file
|
||||
blocks:
|
||||
- system_prefix
|
||||
- python_capabilities
|
||||
- bash_capabilities
|
||||
- browsing_capabilities
|
||||
- pip_capabilities
|
||||
- agent_skills
|
||||
- system_rules
|
||||
- SYSTEM_PREFIX
|
||||
- PYTHON_CAPABILITIES
|
||||
- BASH_CAPABILITIES
|
||||
- BROWSING_CAPABILITIES
|
||||
- PIP_CAPABILITIES
|
||||
- AGENT_SKILLS
|
||||
- SYSTEM_RULES
|
||||
|
||||
agent_skills:
|
||||
file: "agent_skills"
|
||||
blocks:
|
||||
- skill_docs
|
||||
|
||||
examples:
|
||||
file: "examples"
|
||||
blocks:
|
||||
- default_example
|
||||
- micro_agent_guidelines
|
||||
|
||||
micro_agent:
|
||||
file: "micro_agent"
|
||||
blocks:
|
||||
- micro_agent_guidelines
|
||||
- SKILL_DOCS
|
||||
|
||||
user_prompt:
|
||||
file: "user_prompt"
|
||||
blocks:
|
||||
- user_prompt
|
||||
- USER_PROMPT
|
||||
|
||||
examples:
|
||||
file: "examples"
|
||||
blocks:
|
||||
- DEFAULT_EXAMPLE
|
||||
|
||||
micro_agent:
|
||||
file: "micro_agent"
|
||||
blocks:
|
||||
- MICRO_AGENT_GUIDELINES
|
||||
|
||||
# agent-specific variables (can be accessed within templates)
|
||||
use_tools: false # whether to use tool-based implementations
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
{% set DEFAULT_EXAMPLE %}
|
||||
{% block DEFAULT_EXAMPLE %}
|
||||
--- START OF EXAMPLE ---
|
||||
|
||||
USER: Create a list of numbers from 1 to 10, and display them in a web page at port 5000.
|
||||
@ -212,13 +212,4 @@ The server is running on port 5000 with PID 126. You can access the list of numb
|
||||
<finish></finish>
|
||||
|
||||
--- END OF EXAMPLE ---
|
||||
{% endset %}
|
||||
Here is an example of how you can interact with the environment for task solving:
|
||||
{{ DEFAULT_EXAMPLE }}
|
||||
{% if micro_agent %}
|
||||
--- BEGIN OF GUIDELINE ---
|
||||
The following information may assist you in completing your task:
|
||||
|
||||
{{ micro_agent }}
|
||||
--- END OF GUIDELINE ---
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
{% block micro_agent_guidelines %}
|
||||
{% block MICRO_AGENT_GUIDELINES %}
|
||||
{% if micro_agent %}
|
||||
--- BEGIN OF GUIDELINE ---
|
||||
The following information may assist you in completing your task:
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
{# Core system components for the CodeAct Agent #}
|
||||
|
||||
{# Base system identity and core abilities #}
|
||||
{% block system_prefix %}
|
||||
{% block SYSTEM_PREFIX %}
|
||||
A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed answers to the user's questions.
|
||||
{% endblock %}
|
||||
|
||||
{% block python_capabilities %}
|
||||
{% block PYTHON_CAPABILITIES %}
|
||||
You can use a Python environment with <execute_ipython>, e.g.:
|
||||
<execute_ipython>
|
||||
print("Hello World!")
|
||||
@ -13,7 +13,7 @@ print("Hello World!")
|
||||
{% endblock %}
|
||||
|
||||
{# Bash execution capabilities #}
|
||||
{% block bash_capabilities %}
|
||||
{% block BASH_CAPABILITIES %}
|
||||
[2] The assistant can execute bash commands wrapped with <execute_bash>, e.g. <execute_bash> ls </execute_bash>.
|
||||
If a bash command returns exit code `-1`, this means the process is not yet finished.
|
||||
The assistant must then send a second <execute_bash>. The second <execute_bash> can be empty
|
||||
@ -145,19 +145,19 @@ print(MyClass().y)
|
||||
{% endblock %}
|
||||
|
||||
{# Web browsing #}
|
||||
{% block browsing_capabilities %}
|
||||
{% block BROWSING_CAPABILITIES %}
|
||||
The assistant can browse the Internet with <execute_browse> and </execute_browse>.
|
||||
For example, <execute_browse> Tell me the USA's president using Google search </execute_browse>.
|
||||
Or <execute_browse> Tell me what is in http://example.com </execute_browse>.
|
||||
{% endblock %}
|
||||
|
||||
{# Package management #}
|
||||
{% block pip_capabilities %}
|
||||
{% block PIP_CAPABILITIES %}
|
||||
The assistant can install Python packages using the %pip magic command in an IPython environment by using the following syntax: <execute_ipython> %pip install [package needed] </execute_ipython> and should always import packages and define variables before starting to use them.
|
||||
{% endblock %}
|
||||
|
||||
{# Agent skills documentation #}
|
||||
{% block agent_skills %}
|
||||
{% block AGENT_SKILLS %}
|
||||
{% if use_tools %}
|
||||
{# Tool-based implementation #}
|
||||
The following tools are available:
|
||||
@ -177,7 +177,7 @@ IMPORTANT:
|
||||
{% endblock %}
|
||||
|
||||
{# System behavior rules #}
|
||||
{% block system_rules %}
|
||||
{% block SYSTEM_RULES %}
|
||||
Responses should be concise.
|
||||
The assistant should attempt fewer things at a time instead of putting too many commands OR too much code in one "execute" block.
|
||||
Include ONLY ONE <execute_ipython>, <execute_bash>, or <execute_browse> per response, unless the assistant is finished with the task or needs more input or action from the user in order to proceed.
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
{% block user_prompt %}
|
||||
Here is an example of how you can interact with the environment for task solving:
|
||||
{% block USER_PROMPT %}
|
||||
{{ examples }}
|
||||
|
||||
{{ micro_agent_content }}
|
||||
|
||||
@ -118,7 +118,6 @@ class PromptManager:
|
||||
# example interactions
|
||||
templates['examples'] = {
|
||||
'template': self._load_template('examples'),
|
||||
'blocks': ['default_example', 'micro_agent_guidelines'],
|
||||
}
|
||||
|
||||
# micro-agent guidelines
|
||||
@ -130,7 +129,7 @@ class PromptManager:
|
||||
# user prompt combining everything
|
||||
templates['user_prompt'] = {
|
||||
'template': self._load_template('user_prompt'),
|
||||
'blocks': ['user_prompt'],
|
||||
'blocks': ['user_prompt', 'default_example', 'micro_agent_guidelines'],
|
||||
}
|
||||
|
||||
return templates
|
||||
@ -156,10 +155,10 @@ class PromptManager:
|
||||
context = template_info['template'].new_context(kwargs)
|
||||
|
||||
# render each block using the shared context
|
||||
for block_name in template_info['blocks']:
|
||||
for block_name in template_info.get('blocks', []):
|
||||
try:
|
||||
logger.debug(f"Rendering block '{template_name}.{block_name}'")
|
||||
block = template_info['template'].blocks[block_name]
|
||||
# Convert generator to string by joining its contents
|
||||
rendered = ''.join(block(context))
|
||||
rendered_blocks.append(rendered)
|
||||
except KeyError:
|
||||
@ -195,14 +194,14 @@ class PromptManager:
|
||||
These additional context will convert the current generic agent
|
||||
into a more specialized agent that is tailored to the user's task.
|
||||
"""
|
||||
# Render each component's blocks
|
||||
# render each component's blocks
|
||||
rendered_examples = self._render_blocks('examples').strip()
|
||||
rendered_micro_agent = self._render_blocks(
|
||||
'micro_agent',
|
||||
micro_agent=self.micro_agent.content if self.micro_agent else None,
|
||||
).strip()
|
||||
|
||||
# Combine in user prompt
|
||||
# combine in user prompt
|
||||
rendered = self._render_blocks(
|
||||
'user_prompt',
|
||||
examples=rendered_examples,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user