1111# See the License for the specific language governing permissions and
1212# limitations under the License.
1313# =========== Copyright 2024 @ CAMEL-AI.org. All Rights Reserved. ===========
14- from copy import copy
15-
16- from crab import Action , ActionOutput
17- from crab .core .agent_policy import AgentPolicy
18- from crab .core .backend_model import (
19- BackendModel ,
20- MessageType ,
14+ from crab .agents .backend_models import BackendModelConfig , create_backend_model
15+ from crab .agents .utils import (
16+ combine_multi_env_action_space ,
17+ decode_combined_action ,
18+ generate_action_prompt ,
2119)
20+ from crab .core import Action , ActionOutput
21+ from crab .core .agent_policy import AgentPolicy
22+ from crab .core .backend_model import MessageType
2223
2324
2425class MultiAgentByFuncPolicy (AgentPolicy ):
@@ -40,11 +41,11 @@ class MultiAgentByFuncPolicy(AgentPolicy):
4041
4142 def __init__ (
4243 self ,
43- main_agent_model_backend : BackendModel ,
44- tool_agent_model_backend : BackendModel ,
44+ main_agent_model_backend : BackendModelConfig ,
45+ tool_agent_model_backend : BackendModelConfig ,
4546 ):
46- self .main_agent_model_backend = copy (main_agent_model_backend )
47- self .tool_agent_model_backend = copy (tool_agent_model_backend )
47+ self .main_agent_model_backend = create_backend_model (main_agent_model_backend )
48+ self .tool_agent_model_backend = create_backend_model (tool_agent_model_backend )
4849 self .reset (task_description = "" , action_spaces = None , env_descriptions = {})
4950
5051 def reset (
@@ -54,11 +55,11 @@ def reset(
5455 env_descriptions : dict [str , str ],
5556 ) -> list [ActionOutput ]:
5657 self .task_description = task_description
57- self .action_space = self . combine_multi_env_action_space (action_spaces )
58+ self .action_space = combine_multi_env_action_space (action_spaces )
5859
5960 main_agent_system_message = self ._system_prompt .format (
6061 task_description = task_description ,
61- action_descriptions = self . generate_action_prompt (self .action_space ),
62+ action_descriptions = generate_action_prompt (self .action_space ),
6263 env_description = str (env_descriptions ),
6364 )
6465 self .main_agent_model_backend .reset (main_agent_system_message , None )
@@ -95,4 +96,4 @@ def chat(
9596 tool_output = self .tool_agent_model_backend .chat (
9697 (output .message , MessageType .TEXT )
9798 )
98- return self . decode_combined_action (tool_output .action_list )
99+ return decode_combined_action (tool_output .action_list )
0 commit comments