Skip to content

Commit 37f9a18

Browse files
committed
add migration script
1 parent 52efa94 commit 37f9a18

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/cli.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from src.agent_factory import AgentFactory
1616
from src.helpers import print_h_bar
1717
from src.langgraph.langgraph_agent import LangGraphAgent
18+
from src.migration_script import migrate_config
1819

1920
# Configure logging
2021
logging.basicConfig(level=logging.INFO, format='%(message)s')
@@ -156,6 +157,17 @@ def _initialize_commands(self) -> None:
156157
)
157158
)
158159

160+
# Migrate agent config command
161+
self._register_command(
162+
Command(
163+
name="migrate",
164+
description="Migrate agent configuration from old to new format.",
165+
tips=["Use this command to convert old agent JSON files to the new format"],
166+
handler=self.migrate_agent_config,
167+
aliases=['migrate-config']
168+
)
169+
)
170+
159171
################## CONNECTIONS ##################
160172
# List actions command
161173
self._register_command(
@@ -544,6 +556,17 @@ def chat_session(self, input_list: List[str]) -> None:
544556

545557
except KeyboardInterrupt:
546558
break
559+
560+
def migrate_agent_config(self, input_list: List[str]) -> None:
561+
"""Migrate agent configuration from old to new format."""
562+
print_h_bar()
563+
564+
agent_file_name = input("Enter the name of the agent file to migrate: ").strip()
565+
agent_type_input = input("Enter the agent type (a for autonomous, l for legacy): ").strip().lower()
566+
567+
agent_type = "autonomous" if agent_type_input == "a" else "legacy"
568+
569+
migrate_config(agent_file_name, agent_type)
547570

548571
def exit(self, input_list: List[str]) -> None:
549572
"""Exit the CLI gracefully"""

src/migration_script.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import json
2+
3+
#Easily convert the old JSON format to the new agent configuration format
4+
5+
def migrate_old_to_new(old_json, conversion_type="legacy"):
6+
new_json = {
7+
"config": {
8+
"name": old_json["name"],
9+
"type": conversion_type,
10+
"loop_delay": old_json["loop_delay"],
11+
},
12+
"llms": {
13+
"character": {
14+
"name": old_json["name"],
15+
"bio": old_json["bio"],
16+
"traits": old_json["traits"],
17+
"examples": old_json["examples"],
18+
"example_accounts": old_json["example_accounts"],
19+
"model_provider": "openai",
20+
"model": "gpt-3.5-turbo",
21+
}
22+
},
23+
"connections": [],
24+
}
25+
26+
if conversion_type == "autonomous":
27+
new_json["llms"]["executor"] = {
28+
"model_provider": "openai", # openai or anthropic for langchain
29+
"model": "gpt-4o-mini",
30+
}
31+
elif conversion_type == "legacy":
32+
new_json["config"]["time_based_multipliers"] = old_json["time_based_multipliers"]
33+
new_json["tasks"] = old_json.get("tasks", [])
34+
35+
new_json["connections"] = [
36+
{"name": item["name"], "config": {k: v for k, v in item.items() if k != "name"}}
37+
for item in old_json["config"]
38+
]
39+
40+
return new_json
41+
42+
def migrate_config(agent_file_name,agent_type):
43+
with open("agents/{}.json".format(agent_file_name), "r") as f:
44+
old_data = json.load(f)
45+
46+
new_data = migrate_old_to_new(old_data, agent_type)
47+
48+
# Save new JSON to a file
49+
new_file_name = "agents/{}-migrated.json".format(agent_file_name)
50+
with open(new_file_name, "w") as f:
51+
json.dump(new_data, f, indent=2)
52+
53+
print("Migration complete. New agent configuration of type {} saved to {}".format(agent_type,new_file_name))

0 commit comments

Comments
 (0)