Skip to content

Commit ac82266

Browse files
authored
Merge pull request #488 from shareAI-lab/fix/s10-use-dynamic-context-in-prompt
fix(s10): assemble system prompt from dynamic context instead of static strings
2 parents 2f4d02d + b4e7269 commit ac82266

4 files changed

Lines changed: 25 additions & 21 deletions

File tree

‎s10_system_prompt/README.en.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ Split the monolithic string into a dictionary, each key is a topic:
6868
```python
6969
PROMPT_SECTIONS = {
7070
"identity": "You are a coding agent. Act, don't explain.",
71-
"tools": "Available tools: bash, read_file, write_file.",
72-
"workspace": f"Working directory: {WORKDIR}",
73-
"memory": "Relevant memories are injected below when available.",
7471
}
7572
```
7673

@@ -86,8 +83,12 @@ def assemble_system_prompt(context: dict) -> str:
8683

8784
# Always loaded
8885
sections.append(PROMPT_SECTIONS["identity"])
89-
sections.append(PROMPT_SECTIONS["tools"])
90-
sections.append(PROMPT_SECTIONS["workspace"])
86+
87+
# Dynamic — tools and workspace from context
88+
tools = ", ".join(context.get("enabled_tools", []))
89+
if tools:
90+
sections.append(f"Available tools: {tools}.")
91+
sections.append(f"Working directory: {context.get("workspace", WORKDIR)}")
9192

9293
# On-demand — based on real state, not keywords
9394
memories = context.get("memories", "")

‎s10_system_prompt/README.ja.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ s10 は prompt アセンブリ機構に焦点を当てる。s08-s09 の能力を
6868
```python
6969
PROMPT_SECTIONS = {
7070
"identity": "You are a coding agent. Act, don't explain.",
71-
"tools": "Available tools: bash, read_file, write_file.",
72-
"workspace": f"Working directory: {WORKDIR}",
73-
"memory": "Relevant memories are injected below when available.",
7471
}
7572
```
7673

@@ -86,8 +83,12 @@ def assemble_system_prompt(context: dict) -> str:
8683

8784
# 常にロード
8885
sections.append(PROMPT_SECTIONS["identity"])
89-
sections.append(PROMPT_SECTIONS["tools"])
90-
sections.append(PROMPT_SECTIONS["workspace"])
86+
87+
# context から動的に tools と workspace を取得
88+
tools = ", ".join(context.get("enabled_tools", []))
89+
if tools:
90+
sections.append(f"Available tools: {tools}.")
91+
sections.append(f"Working directory: {context.get("workspace", WORKDIR)}")
9192

9293
# オンデマンド — 実際の状態に基づく、キーワードではない
9394
memories = context.get("memories", "")

‎s10_system_prompt/README.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ s10 聚焦 prompt 组装机制。以 s08-s09 的能力为背景,但不重复
6868
```python
6969
PROMPT_SECTIONS = {
7070
"identity": "You are a coding agent. Act, don't explain.",
71-
"tools": "Available tools: bash, read_file, write_file.",
72-
"workspace": f"Working directory: {WORKDIR}",
73-
"memory": "Relevant memories are injected below when available.",
7471
}
7572
```
7673

@@ -86,8 +83,12 @@ def assemble_system_prompt(context: dict) -> str:
8683

8784
# 始终加载
8885
sections.append(PROMPT_SECTIONS["identity"])
89-
sections.append(PROMPT_SECTIONS["tools"])
90-
sections.append(PROMPT_SECTIONS["workspace"])
86+
87+
# 从 context 动态获取 tools 和 workspace
88+
tools = ", ".join(context.get("enabled_tools", []))
89+
if tools:
90+
sections.append(f"Available tools: {tools}.")
91+
sections.append(f"Working directory: {context.get("workspace", WORKDIR)}")
9192

9293
# 按需加载 — 基于真实状态,不是关键词
9394
memories = context.get("memories", "")

‎s10_system_prompt/code.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,21 @@
4141

4242
PROMPT_SECTIONS = {
4343
"identity": "You are a coding agent. Act, don't explain.",
44-
"tools": "Available tools: bash, read_file, write_file.",
45-
"workspace": f"Working directory: {WORKDIR}",
46-
"memory": "Relevant memories are injected below when available.",
4744
}
4845

4946

5047
def assemble_system_prompt(context: dict) -> str:
5148
"""Select and join prompt sections based on current context."""
5249
sections = []
5350

54-
# Always loaded — identity, tools, workspace
51+
# Always loaded — identity
5552
sections.append(PROMPT_SECTIONS["identity"])
56-
sections.append(PROMPT_SECTIONS["tools"])
57-
sections.append(PROMPT_SECTIONS["workspace"])
53+
54+
# Dynamic — tools and workspace from context
55+
tools = ", ".join(context.get("enabled_tools", []))
56+
if tools:
57+
sections.append(f"Available tools: {tools}.")
58+
sections.append(f"Working directory: {context.get("workspace", WORKDIR)}")
5859

5960
# Conditional — memory loaded when MEMORY.md exists and has content
6061
memories = context.get("memories", "")

0 commit comments

Comments
 (0)