|
| 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