Skip to content

Commit 3e5773b

Browse files
committed
[Conversation Improvements]
1 parent db53d34 commit 3e5773b

3 files changed

Lines changed: 8 additions & 47 deletions

File tree

example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from swarms import Agent
21
import json
32

3+
from swarms import Agent
4+
45
# Initialize the agent
56
agent = Agent(
67
agent_name="Quantitative-Trading-Agent",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
55

66
[tool.poetry]
77
name = "swarms"
8-
version = "8.5.2"
8+
version = "8.5.3"
99
description = "Swarms - TGSC"
1010
license = "MIT"
1111
authors = ["Kye Gomez <kye@swarms.world>"]

swarms/structs/conversation.py

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ def save_as_json(self, force: bool = True):
562562
)
563563
return
564564

565+
565566
# Ensure we have a valid save path
566567
if not self.save_filepath:
567568
self.save_filepath = os.path.join(
@@ -576,12 +577,7 @@ def save_as_json(self, force: bool = True):
576577

577578
# Save with proper formatting
578579
with open(self.save_filepath, "w", encoding="utf-8") as f:
579-
json.dump(
580-
self.conversation_history,
581-
f,
582-
indent=4,
583-
default=str,
584-
)
580+
json.dump(self.conversation_history, f, indent=4, default=str)
585581

586582
logger.info(f"Conversation saved to {self.save_filepath}")
587583

@@ -591,34 +587,6 @@ def save_as_json(self, force: bool = True):
591587
)
592588
raise # Re-raise to ensure the error is visible to the caller
593589

594-
def get_init_params(self):
595-
data = {
596-
"metadata": {
597-
"id": self.id,
598-
"name": self.name,
599-
"system_prompt": self.system_prompt,
600-
"time_enabled": self.time_enabled,
601-
"autosave": self.autosave,
602-
"save_filepath": self.save_filepath,
603-
"load_filepath": self.load_filepath,
604-
"context_length": self.context_length,
605-
"rules": self.rules,
606-
"custom_rules_prompt": self.custom_rules_prompt,
607-
"user": self.user,
608-
"save_as_yaml_on": self.save_as_yaml_on,
609-
"save_as_json_bool": self.save_as_json_bool,
610-
"token_count": self.token_count,
611-
"message_id_on": self.message_id_on,
612-
"tokenizer_model_name": self.tokenizer_model_name,
613-
"conversations_dir": self.conversations_dir,
614-
"export_method": self.export_method,
615-
"created_at": self.created_at,
616-
},
617-
"conversation_history": self.conversation_history,
618-
}
619-
620-
return data
621-
622590
def save_as_yaml(self, force: bool = True):
623591
"""Save the conversation history and metadata to a YAML file.
624592
@@ -634,9 +602,6 @@ def save_as_yaml(self, force: bool = True):
634602
)
635603
return
636604

637-
# Get the full data including metadata and conversation history
638-
data = self.get_init_params()
639-
640605
# Create directory if it doesn't exist
641606
save_dir = os.path.dirname(self.save_filepath)
642607
if save_dir:
@@ -645,15 +610,10 @@ def save_as_yaml(self, force: bool = True):
645610
# Save with proper formatting
646611
with open(self.save_filepath, "w", encoding="utf-8") as f:
647612
yaml.dump(
648-
data,
649-
f,
650-
indent=4,
651-
default_flow_style=False,
652-
sort_keys=False,
653-
)
654-
logger.info(
655-
f"Conversation saved to {self.save_filepath}"
613+
self.conversation_history,
614+
f, indent=4, default_flow_style=False, sort_keys=False
656615
)
616+
logger.info(f"Conversation saved to {self.save_filepath}")
657617

658618
except Exception as e:
659619
logger.error(

0 commit comments

Comments
 (0)