Skip to content

Commit 7ca09cd

Browse files
committed
Report global memories in system prompt instead of at each project activation
1 parent 376849e commit 7ca09cd

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/serena/agent.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from sensai.util import logging
1414
from sensai.util.logging import LogTime
15+
from sensai.util.string import list_string
1516

1617
from interprompt.jinja_template import JinjaTemplate
1718
from serena import serena_version
@@ -26,7 +27,7 @@
2627
)
2728
from serena.dashboard import SerenaDashboardAPI
2829
from serena.ls_manager import LanguageServerManager
29-
from serena.project import Project
30+
from serena.project import MemoriesManager, Project
3031
from serena.prompt_factory import SerenaPromptFactory
3132
from serena.task_executor import TaskExecutor
3233
from serena.tools import ActivateProjectTool, GetCurrentConfigTool, OpenDashboardTool, ReplaceContentTool, Tool, ToolMarker, ToolRegistry
@@ -565,12 +566,15 @@ def _format_prompt(self, prompt_template: str) -> str:
565566
def create_system_prompt(self) -> str:
566567
available_tools = self._active_tools
567568
available_markers = available_tools.tool_marker_names
569+
global_memory_names = MemoriesManager.list_global_memories()
570+
global_memories_list = list_string(global_memory_names) if global_memory_names else ""
568571
log.info("Generating system prompt with available_tools=(see active tools), available_markers=%s", available_markers)
569572
system_prompt = self.prompt_factory.create_system_prompt(
570573
context_system_prompt=self._format_prompt(self._context.prompt),
571574
mode_system_prompts=[self._format_prompt(mode.prompt) for mode in self.get_active_modes()],
572575
available_tools=available_tools.tool_names,
573576
available_markers=available_markers,
577+
global_memories_list=global_memories_list,
574578
)
575579

576580
# If a project is active at startup, append its activation message

src/serena/generated/generated_prompt_factory.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ def create_prepare_for_new_conversation(self) -> str:
3333
return self._render_prompt("prepare_for_new_conversation", locals())
3434

3535
def create_system_prompt(
36-
self, *, available_markers: Any, available_tools: Any, context_system_prompt: Any, mode_system_prompts: Any
36+
self,
37+
*,
38+
available_markers: Any,
39+
available_tools: Any,
40+
context_system_prompt: Any,
41+
global_memories_list: Any,
42+
mode_system_prompts: Any,
3743
) -> str:
3844
return self._render_prompt("system_prompt", locals())

src/serena/project.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,11 @@ def get_activation_message(self) -> str:
304304
languages_str = ", ".join([lang.value for lang in self.project_config.languages])
305305
msg += f"\nProgramming languages: {languages_str}; file encoding: {self.project_config.encoding}"
306306
project_memories = self.memories_manager.list_project_memories()
307-
global_memories = self.memories_manager.list_global_memories()
308307
if project_memories:
309308
msg += (
310309
f"\nAvailable project memories: {json.dumps(project_memories)}\n"
311310
+ "Use the `read_memory` tool to read these memories later if they are relevant to the task."
312311
)
313-
if global_memories:
314-
msg += f"\nAvailable global memories (shared across all projects): {json.dumps(global_memories)}\n"
315312
if self.project_config.initial_prompt:
316313
msg += f"\nAdditional project-specific instructions:\n {self.project_config.initial_prompt}"
317314
return msg

src/serena/resources/config/prompt_templates/system_prompt.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ prompts:
3535
You can understand relationships between symbols by using the `find_referencing_symbols` tool.
3636
{% endif %}
3737
38-
{% if 'read_memory' in available_tools %}
38+
{% if 'read_memory' in available_tools -%}
3939
You generally have access to memories and it may be useful for you to read them.
4040
You infer whether memories are relevant based on their names.
41-
{% endif %}
41+
{% if global_memories_list -%}
42+
The following global (not project-specific) memories are available to you: {{ global_memories_list }}
43+
{%- endif -%}
44+
{%- endif %}
4245
4346
The context and modes of operation are described below. These determine how to interact with your user
4447
and which kinds of interactions are expected of you.

0 commit comments

Comments
 (0)