Skip to content

Keep the system_prompt as an attribute of the agent. #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 10, 2025
Merged
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
10 changes: 7 additions & 3 deletions src/sdialog/personas.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,29 @@ def print(self, *a, **kw):
color="white")
cprint("--- Persona Ends ---", color="magenta", format="bold")

def json(self, string: bool = False, indent=2):
def json(self, string: bool = False, indent=2, output_metadata: bool = True):
"""
Serializes the persona to JSON.
:param string: If True, returns a JSON string; otherwise, returns a dict.
:type string: bool
:param indent: Indentation level for pretty-printing.
:type indent: int
:param output_metadata: Include the metadata in the serialization.
:type output_metadata: bool
:return: The serialized persona.
:rtype: Union[str, dict]
"""
data = {key: value for key, value in self.__dict__.items() if value not in [None, ""]}
if self._metadata:
if self._metadata and output_metadata:
data["_metadata"] = self._metadata.model_dump()
return json.dumps(data, indent=indent) if string else data

def prompt(self) -> str:
"""
Returns the textual representation of the persona, used as part of the system prompt.
"""
return self.json(string=True)
return self.json(string=True, output_metadata=False)

def to_file(self, path: str, makedir: bool = True):
"""
Expand Down Expand Up @@ -486,6 +488,8 @@ def __init__(self,
stop_word=self.STOP_WORD
)

self.system_prompt = system_prompt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to have the self.system_prompt as an attribute that is never used inside the class? the self.prompt() will return exactly the same as self.system_prompt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, if self.prompt() returns exactly that, there is no point in adding it as an attribute.


llm_config_params = {k: v for k, v in config["llm"].items() if k != "model" and v is not None}
llm_kwargs = {**llm_config_params, **llm_kwargs}
self.hf_model = False
Expand Down