Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions evoagentx/workflow/action_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def from_dict(cls, data: Dict[str, Any], **kwargs) -> "ActionGraph":
"""
Create an ActionGraph from a dictionary.
"""
data = data.copy()
class_name = data.get("class_name", None)
if class_name:
cls = MODULE_REGISTRY.get_module(class_name)
Expand Down
29 changes: 29 additions & 0 deletions tests/src/workflow/test_action_graph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import os
from copy import deepcopy
from typing import Optional
from unittest.mock import Mock, patch

Expand Down Expand Up @@ -106,6 +107,34 @@ def test_from_dict(self):
self.assertEqual(loaded_graph.answer_generate.prompt, "This is a mocked prompt")
self.assertEqual(loaded_graph.sc_ensemble.name, "QAScEnsemble")

def test_from_dict_preserves_reusable_operator_configuration(self):
self.qa_action_graph.answer_generate.set_prompt("Evolved answer: {input}")
self.qa_action_graph.sc_ensemble.set_prompt("Evolved ensemble: {solutions}")
config = self.qa_action_graph.get_config()
original = deepcopy(config)

first = ActionGraph.from_dict(config)
second = ActionGraph.from_dict(config)

self.assertEqual(config, original)
for graph in (first, second):
self.assertEqual(graph.answer_generate.prompt, "Evolved answer: {input}")
self.assertEqual(graph.sc_ensemble.prompt, "Evolved ensemble: {solutions}")

first.answer_generate.set_prompt("A later edit: {input}")
self.assertEqual(config, original)
self.assertEqual(second.answer_generate.prompt, "Evolved answer: {input}")

def test_failed_from_dict_does_not_consume_operator_configuration(self):
config = self.qa_action_graph.get_config()
del config["llm_config"]
original = deepcopy(config)

with self.assertRaises(TypeError):
ActionGraph.from_dict(config)

self.assertEqual(config, original)

def test_save_and_load(self):
self.qa_action_graph.save_module("tests/src/workflow/saved_qa_action_graph.json")
loaded_graph = ActionGraph.from_file("tests/src/workflow/saved_qa_action_graph.json", llm_config=self.llm_config)
Expand Down