serena.config.context_mode#
Source code: serena/config/context_mode.py
Context and Mode configuration loader
- class SerenaAgentMode(
- excluded_tools=(),
- included_optional_tools=(),
- fixed_tools=(),
- *,
- name,
- prompt,
- description='',
- _yaml_path=None,
Bases:
ToolInclusionDefinition,ToStringMixinRepresents a mode of operation for the agent, typically read off a YAML file. An agent can be in multiple modes simultaneously as long as they are not mutually exclusive. The modes can be adjusted after the agent is running, for example for switching from planning to editing.
- Parameters:
excluded_tools (Sequence[str])
included_optional_tools (Sequence[str])
fixed_tools (Sequence[str])
name (str)
prompt (str)
description (str)
_yaml_path (Path | None)
- prompt: str#
a Jinja2 template for the generation of the system prompt. It is formatted by the agent (see SerenaAgent._format_prompt()).
- classmethod from_yaml(yaml_path)[source]#
Load a mode from a YAML file.
- Parameters:
yaml_path (str | Path)
- Return type:
Self
- classmethod get_path(name, instance=None)[source]#
Get the path to the YAML file for a mode.
- Parameters:
name (str) – The name of the mode
instance (Self | None) – Optional mode instance. If provided and it has a stored path, that path is returned.
- Returns:
The path to the mode’s YAML file
- Return type:
str
- classmethod from_name(name)[source]#
Load a registered Serena mode.
- Parameters:
name (str)
- Return type:
Self
- classmethod from_name_internal(name)[source]#
Loads an internal Serena mode
- Parameters:
name (str)
- Return type:
Self
- classmethod list_registered_mode_names(include_user_modes=True)[source]#
Names of all registered modes (from the corresponding YAML files in the serena repo).
- Parameters:
include_user_modes (bool)
- Return type:
list[str]
- class SerenaAgentContext(
- excluded_tools=(),
- included_optional_tools=(),
- fixed_tools=(),
- *,
- name,
- prompt,
- description='',
- tool_description_overrides=<factory>,
- _yaml_path=None,
- single_project=False,
- structured_tool_output=None,
Bases:
ToolInclusionDefinition,ToStringMixinRepresents a context where the agent is operating (an IDE, a chat, etc.), typically read off a YAML file. An agent can only be in a single context at a time. The contexts cannot be changed after the agent is running.
- Parameters:
excluded_tools (Sequence[str])
included_optional_tools (Sequence[str])
fixed_tools (Sequence[str])
name (str)
prompt (str)
description (str)
tool_description_overrides (dict[str, str])
_yaml_path (Path | None)
single_project (bool)
structured_tool_output (bool | None)
- name: str#
the name of the context
- prompt: str#
a Jinja2 template for the generation of the system prompt. It is formatted by the agent (see SerenaAgent._format_prompt()).
- tool_description_overrides: dict[str, str]#
maps tool names to custom descriptions, default descriptions are extracted from the tool docstrings.
- single_project: bool = False#
whether to assume that Serena shall only work on a single project in this context (provided that a project is given when Serena is started). If set to true and a project is provided at startup, the set of tools is limited to those required by the project’s concrete configuration, and other tools are excluded completely, allowing the set of tools to be minimal. The activate_project tool will, therefore, be disabled in this case, as project switching is not allowed.
- structured_tool_output: bool | None = None#
whether to use structured output for tools (None = auto)
- classmethod from_yaml(yaml_path)[source]#
Load a context from a YAML file.
- Parameters:
yaml_path (str | Path)
- Return type:
Self
- classmethod get_path(name, instance=None)[source]#
Get the path to the YAML file for a context.
- Parameters:
name (str) – The name of the context
instance (Self | None) – Optional context instance. If provided and it has a stored path, that path is returned.
- Returns:
The path to the context’s YAML file
- Return type:
str
- classmethod from_name(name)[source]#
Load a registered Serena context.
- Parameters:
name (str)
- Return type:
Self
- classmethod list_registered_context_names(include_user_contexts=True)[source]#
Names of all registered contexts (from the corresponding YAML files in the serena repo).
- Parameters:
include_user_contexts (bool)
- Return type:
list[str]