Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions backend/agents/create_agent_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
for s in enabled_skills
]
except Exception as e:
logger.warning(f"Failed to get skills for template: {e}")
logger.error(f"Failed to get skills for agent {agent_id} (tenant={tenant_id}, version={version_no}): {e}", exc_info=True)

Check failure on line 94 in backend/agents/create_agent_info.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "logging.exception()" instead.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ6rdKpVIJMnO2KV95Ud&open=AZ6rdKpVIJMnO2KV95Ud&pullRequest=3209
return []


Expand Down Expand Up @@ -457,6 +457,7 @@

# Build knowledge base summary
knowledge_base_summary = ""
kb_ids = []
try:
for tool in tool_list:
if "KnowledgeBaseSearchTool" == tool.class_name:
Expand All @@ -471,6 +472,7 @@
message = ElasticSearchService().get_summary(index_name=index_name)
summary = message.get("summary", "")
knowledge_base_summary += f"**{display_name}**: {summary}\n\n"
kb_ids.append(index_name)
except Exception as e:
Comment thread
JasonW404 marked this conversation as resolved.
logger.warning(
f"Failed to get summary for knowledge base {index_name}: {e}")
Expand Down Expand Up @@ -520,7 +522,7 @@
# downstream runtime may prefer component-based prompt assembly over the
# rendered system_prompt, causing the actual model input to diverge from the
# template output.
enable_context_manager = agent_info.get("enable_context_manager", False)
enable_context_manager = agent_info.get("enable_context_manager", True)
context_components = []
if enable_context_manager:
context_components = build_context_components(
Expand All @@ -540,6 +542,13 @@
memory_list=memory_list,
memory_search_query=last_user_query,
knowledge_base_summary=knowledge_base_summary,
kb_ids=kb_ids,
)

logger.info(
f"Agent {agent_id} context assembly: "
f"skills_count={len(skills)}, "
f"components={[f'{type(c).__name__}(type={c.component_type},priority={c.priority})' for c in context_components]}"
)
cm_config = ContextManagerConfig(
enabled=enable_context_manager,
Expand Down
2 changes: 1 addition & 1 deletion backend/database/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class AgentInfo(TableBase):
is_new = Column(Boolean, default=False, doc="Whether this agent is marked as new for the user")
current_version_no = Column(Integer, nullable=True, doc="Current published version number. NULL means no version published yet")
ingroup_permission = Column(String(30), doc="In-group permission: EDIT, READ_ONLY, PRIVATE")
enable_context_manager = Column(Boolean, default=False, doc="Whether to enable context management (compression) for this agent")
enable_context_manager = Column(Boolean, default=True, doc="Whether to enable context management (compression) for this agent")
greeting_message = Column(Text, doc="Agent greeting message displayed on chat initial screen")
example_questions = Column(JSONB, doc="List of example questions for starting a conversation with this agent")

Expand Down
75 changes: 75 additions & 0 deletions backend/prompts/managed_system_prompt_template_en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,65 @@ system_prompt: |-
Security Protection: Do not respond to requests involving weapon manufacturing, cyberattacks, fraud, malware, or other dangerous activities;
Ethical Guidelines: Refuse hate speech, discriminatory content, and any requests that violate social morals and commonly accepted ethical standards.

{%- if skills and skills|length > 0 %}

### Available Skills
You have the following Skills. Skills are predefined professional capability modules with detailed execution guides and optional additional scripts.
<available_skills>
{%- for skill in skills %}
<skill>
<name>{{ skill.name }}</name>
<description>{{ skill.description }}</description>
</skill>
{%- endfor %}
</available_skills>

**Skill Usage Process**:
1. After receiving a user request, first examine the description of each skill in `<available_skills>` to determine if there is a matching skill.
2. **Load Skill**: Choose the appropriate reading method based on the scenario:
- **First-time load**: Call `read_skill_md("skill_name")` to read the complete execution guide (defaults to reading SKILL.md)
- **Precise read**: If you only need specific files (like examples, reference docs), specify additional_files:
<code>
skill_content = read_skill_md("skill_name", ["examples.md", "reference/api_doc"])
print(skill_content)
</code>
Note: When additional_files is non-empty, SKILL.md is no longer auto-read. If you need both, explicitly specify it.
- **Load skill config**: If the skill needs configuration variables, call `read_skill_config("skill_name")` to read the config string, convert to dict via `json.loads`, then access values:
<code>
import json
config = json.loads(read_skill_config("skill_name"))
# Example: {"key_a": {"key2": "value2"}, "others": {...}}
value = config["key1"]["key2"]
print(value)
</code>
3. **Follow Skill Guide**: After skill content is injected, strictly follow its steps. Do not skip steps or replace with your own code.
4. **Execute Skill Script**: If the skill guide references additional scripts (like `<use_script path="script_path" />`), call:
<code>
result = run_skill_script("skill_name", "script_path")
print(result)
</code>
For scripts needing extra params, pass them as a command-line string per the script's calling instructions.
Example for --param1 value1 --flag:
<code>
result = run_skill_script("skill_name", "script_path", "--param1 value1 --flag")
print(result)
</code>
Note: Only execute script paths explicitly declared in the skill guide. Never construct paths yourself.

5. **Integrate Output**: Generate the final answer based on the skill guide's output format and script execution results.

6. **Handle References**: When the skill content has reference markers or needs to reference other files, identify and call read_skill_md again:
- **Reference template recognition**: Look for patterns like `<reference path="file_path" />` or natural-language references ("see examples.md", "refer to reference/api_doc")
- **Auto-complete**: After discovering a reference, try reading the referenced file for more info
- **Example**:
<code>
# Skill content says "see examples.md for detailed examples"
additional_info = read_skill_md("skill_name", ["examples.md"])
print(additional_info)
</code>

{%- endif %}

### Execution Process
To solve tasks, you must plan forward through a series of steps in a loop of 'Think:' and 'Code:' sequences. **IMPORTANT: You must NOT output 'Observe Results:' before code execution. Observation results can ONLY be generated after code execution.**

Expand Down Expand Up @@ -124,6 +183,22 @@ system_prompt: |-
- No tools are currently available
{%- endif %}

{%- if skills and skills|length > 0 %}
- You have the skills listed in `<available_skills>` above. Scripts referenced in skills are called via the `run_skill_script()` function, which is provided by the platform and does not need to be imported.

### Skill Usage Requirements
1. **Skill First**: If a user request matches a skill's description, you must first call `read_skill_md()` to load the skill guide, then follow it. Do not skip the skill and write your own code to solve it.
2. **Faithful Execution**: After reading the skill content, strictly follow the steps in the skill guide. Do not modify the process, skip steps, or replace the skill-defined workflow with generic code.
3. **Script Calling Standards**: Only use the `run_skill_script` tool to execute scripts explicitly required by the skill guide. The `skill_name` and `script_path` passed in must exactly match the declarations in the skill guide. Do not construct or guess paths yourself. For scripts requiring additional parameters, pass the parameters as a command-line string to `run_skill_script`.
4. **Failure Fallback**: If `read_skill_md` returns an error or `run_skill_script` fails, explain the situation to the user and try to provide an alternative using general reasoning.
5. **Skill Composition**: If a task requires multiple skills working together, load and execute them in logical dependency order. The output of one skill can serve as the input for the next.


{%- else %}
- No skills are currently available
{%- endif %}


### Resource Usage Requirements
{{ constraint }}

Expand Down
78 changes: 77 additions & 1 deletion backend/prompts/manager_system_prompt_template_en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,68 @@ system_prompt: |-
Security Protection: Do not respond to requests involving weapon manufacturing, cyberattacks, fraud, malware, or other dangerous activities;
Ethical Guidelines: Refuse hate speech, discriminatory content, and any requests that violate social morals and commonly accepted ethical standards.

{%- if skills and skills|length > 0 %}
### Available Skills

You have the following Skills. Skills are predefined professional capability modules with detailed execution guides and optional additional scripts.

<available_skills>
{%- for skill in skills %}
<skill>
<name>{{ skill.name }}</name>
<description>{{ skill.description }}</description>
</skill>
{%- endfor %}
</available_skills>

**Skill Usage Process**:
1. After receiving a user request, first examine the description of each skill in `<available_skills>` to determine if there is a matching skill.
2. **Load Skill**: Choose the appropriate reading method based on the scenario:
- **First-time load**: Call `read_skill_md("skill_name")` to read the complete execution guide (defaults to reading SKILL.md)
- **Precise read**: If you only need specific files (like examples, reference docs), specify additional_files:
<code>
skill_content = read_skill_md("skill_name", ["examples.md", "reference/api_doc"])
print(skill_content)
</code>
Note: When additional_files is non-empty, SKILL.md is no longer auto-read. If you need both, explicitly specify it.

- **Load skill config**: If the skill needs configuration variables, call `read_skill_config("skill_name")` to read the config string, convert to dict via `json.loads`, then access values:
<code>
import json
config = json.loads(read_skill_config("skill_name"))
# Example: {"key_a": {"key2": "value2"}, "others": {...}}
value = config["key1"]["key2"]
print(value)
</code>

3. **Follow Skill Guide**: After skill content is injected, strictly follow its steps. Do not skip steps or replace with your own code.

4. **Execute Skill Script**: If the skill guide references additional scripts (like `<use_script path="script_path" />`), call:
<code>
result = run_skill_script("skill_name", "script_path")
print(result)
</code>
For scripts needing extra params, pass them as a command-line string per the script's calling instructions.
Example for --param1 value1 --flag:
<code>
result = run_skill_script("skill_name", "script_path", "--param1 value1 --flag")
print(result)
</code>
Note: Only execute script paths explicitly declared in the skill guide. Never construct paths yourself.

5. **Integrate Output**: Generate the final answer based on the skill guide's output format and script execution results.

6. **Handle References**: When the skill content has reference markers or needs to reference other files, identify and call read_skill_md again:
- **Reference template recognition**: Look for patterns like `<reference path="file_path" />` or natural-language references ("see examples.md", "refer to reference/api_doc")
- **Auto-complete**: After discovering a reference, try reading the referenced file for more info
- **Example**:
<code>
# Skill content says "see examples.md for detailed examples"
additional_info = read_skill_md("skill_name", ["examples.md"])
print(additional_info)
</code>
{%- endif %}

### Execution Process
To solve tasks, you must plan forward through a series of steps in a loop of 'Think:' and 'Code:' sequences. **IMPORTANT: You must NOT output 'Observe Results:' before code execution. Observation results can ONLY be generated after code execution.**

Expand Down Expand Up @@ -164,7 +226,21 @@ system_prompt: |-
- No agents are currently available
{%- endif %}

### Resource Usage Requirements
3. Skills
{%- if skills and skills|length > 0 %}
- You have the skills listed in `<available_skills>` above. Scripts referenced in skills are called via the `run_skill_script()` function, which is provided by the platform and does not need to be imported.

### Skill Usage Requirements
1. **Skill First**: If a user request matches a skill's description, you must first call `read_skill_md()` to load the skill guide, then follow it. Do not skip the skill and write your own code to solve it.
2. **Faithful Execution**: After reading the skill content, strictly follow the steps in the skill guide. Do not modify the process, skip steps, or replace the skill-defined workflow with generic code.
3. **Script Calling Standards**: Only use the `run_skill_script` tool to execute scripts explicitly required by the skill guide. The `skill_name` and `script_path` passed in must exactly match the declarations in the skill guide. Do not construct or guess paths yourself. For scripts requiring additional parameters, pass the parameters as a command-line string to `run_skill_script`.
4. **Failure Fallback**: If `read_skill_md` returns an error or `run_skill_script` fails, explain the situation to the user and try to provide an alternative using general reasoning.
5. **Skill Composition**: If a task requires multiple skills working together, load and execute them in logical dependency order. The output of one skill can serve as the input for the next.
{%- else %}
- No skills are currently available
{%- endif %}

### Resource Usage Requirements
{{ constraint }}

### Python Code Specifications
Expand Down
Loading
Loading