Minor fix save agents (#645)

Co-authored-by: Aymeric Roucher <69208727+aymeric-roucher@users.noreply.github.com>
This commit is contained in:
Parteek 2025-02-17 13:39:40 +05:30 committed by GitHub
parent 4755c39e14
commit 345f1c35ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View File

@ -876,6 +876,10 @@ You have been provided with these additional arguments, that you can access usin
}
if hasattr(self, "authorized_imports"):
agent_dict["authorized_imports"] = self.authorized_imports
if hasattr(self, "use_e2b_executor"):
agent_dict["use_e2b_executor"] = self.use_e2b_executor
if hasattr(self, "max_print_outputs_length"):
agent_dict["max_print_outputs_length"] = self.max_print_outputs_length
return agent_dict
@classmethod
@ -971,6 +975,8 @@ You have been provided with these additional arguments, that you can access usin
)
if cls.__name__ == "CodeAgent":
args["additional_authorized_imports"] = agent_dict["authorized_imports"]
args["use_e2b_executor"] = agent_dict["use_e2b_executor"]
args["max_print_outputs_length"] = agent_dict["max_print_outputs_length"]
args.update(kwargs)
return cls(**args)

View File

@ -784,6 +784,7 @@ class MultiAgentsTests(unittest.TestCase):
tools=[],
additional_authorized_imports=["pandas", "datetime"],
managed_agents=[web_agent, code_agent],
max_print_outputs_length=1000,
)
agent.save("agent_export")
@ -820,6 +821,8 @@ class MultiAgentsTests(unittest.TestCase):
agent2 = CodeAgent.from_folder("agent_export", planning_interval=5)
assert agent2.planning_interval == 5 # Check that kwargs are used
assert set(agent2.authorized_imports) == set(["pandas", "datetime"] + BASE_BUILTIN_MODULES)
assert agent2.max_print_outputs_length == 1000
assert agent2.use_e2b_executor is False
assert (
agent2.managed_agents["web_agent"].tools["web_search"].max_results == 10
) # For now tool init parameters are forgotten