@@ -88,7 +88,7 @@ class MultiStepAgent:
88
88
Args:
89
89
tools (`list[Tool]`): [`Tool`]s that the agent can use.
90
90
model (`Callable[[list[dict[str, str]]], ChatMessage]`): Model that will generate the agent's actions.
91
- prompts_path (`str `, *optional*): The path from which to load this agent's prompt dictionary .
91
+ prompt_templates (`dict `, *optional*): Prompt templates .
92
92
max_steps (`int`, default `6`): Maximum number of steps the agent can take to solve the task.
93
93
tool_parser (`Callable`, *optional*): Function used to parse the tool calls from the LLM output.
94
94
add_base_tools (`bool`, default `False`): Whether to add the base tools to the agent's tools.
@@ -107,7 +107,7 @@ def __init__(
107
107
self ,
108
108
tools : List [Tool ],
109
109
model : Callable [[List [Dict [str , str ]]], ChatMessage ],
110
- prompts_path : Optional [str ] = None ,
110
+ prompt_templates : Optional [dict ] = None ,
111
111
max_steps : int = 6 ,
112
112
tool_parser : Optional [Callable ] = None ,
113
113
add_base_tools : bool = False ,
@@ -125,6 +125,7 @@ def __init__(
125
125
tool_parser = parse_json_tool_call
126
126
self .agent_name = self .__class__ .__name__
127
127
self .model = model
128
+ self .prompt_templates = prompt_templates or {}
128
129
self .max_steps = max_steps
129
130
self .step_number : int = 0
130
131
self .tool_parser = tool_parser
@@ -633,7 +634,7 @@ class ToolCallingAgent(MultiStepAgent):
633
634
Args:
634
635
tools (`list[Tool]`): [`Tool`]s that the agent can use.
635
636
model (`Callable[[list[dict[str, str]]], ChatMessage]`): Model that will generate the agent's actions.
636
- prompts_path (`str `, *optional*): The path from which to load this agent's prompt dictionary .
637
+ prompt_templates (`dict `, *optional*): Prompt templates .
637
638
planning_interval (`int`, *optional*): Interval at which the agent will run a planning step.
638
639
**kwargs: Additional keyword arguments.
639
640
"""
@@ -642,17 +643,17 @@ def __init__(
642
643
self ,
643
644
tools : List [Tool ],
644
645
model : Callable [[List [Dict [str , str ]]], ChatMessage ],
645
- prompts_path : Optional [str ] = None ,
646
+ prompt_templates : Optional [dict ] = None ,
646
647
planning_interval : Optional [int ] = None ,
647
648
** kwargs ,
648
649
):
649
- self . prompt_templates = yaml .safe_load (
650
+ prompt_templates = prompt_templates or yaml .safe_load (
650
651
importlib .resources .read_text ("smolagents.prompts" , "toolcalling_agent.yaml" )
651
652
)
652
653
super ().__init__ (
653
654
tools = tools ,
654
655
model = model ,
655
- prompts_path = prompts_path ,
656
+ prompt_templates = prompt_templates ,
656
657
planning_interval = planning_interval ,
657
658
** kwargs ,
658
659
)
@@ -755,7 +756,7 @@ class CodeAgent(MultiStepAgent):
755
756
Args:
756
757
tools (`list[Tool]`): [`Tool`]s that the agent can use.
757
758
model (`Callable[[list[dict[str, str]]], ChatMessage]`): Model that will generate the agent's actions.
758
- prompts_path (`str `, *optional*): The path from which to load this agent's prompt dictionary .
759
+ prompt_templates (`dict `, *optional*): Prompt templates .
759
760
grammar (`dict[str, str]`, *optional*): Grammar used to parse the LLM output.
760
761
additional_authorized_imports (`list[str]`, *optional*): Additional authorized imports for the agent.
761
762
planning_interval (`int`, *optional*): Interval at which the agent will run a planning step.
@@ -769,7 +770,7 @@ def __init__(
769
770
self ,
770
771
tools : List [Tool ],
771
772
model : Callable [[List [Dict [str , str ]]], ChatMessage ],
772
- prompts_path : Optional [str ] = None ,
773
+ prompt_templates : Optional [dict ] = None ,
773
774
grammar : Optional [Dict [str , str ]] = None ,
774
775
additional_authorized_imports : Optional [List [str ]] = None ,
775
776
planning_interval : Optional [int ] = None ,
@@ -779,10 +780,13 @@ def __init__(
779
780
):
780
781
self .additional_authorized_imports = additional_authorized_imports if additional_authorized_imports else []
781
782
self .authorized_imports = list (set (BASE_BUILTIN_MODULES ) | set (self .additional_authorized_imports ))
782
- self .prompt_templates = yaml .safe_load (importlib .resources .read_text ("smolagents.prompts" , "code_agent.yaml" ))
783
+ prompt_templates = prompt_templates or yaml .safe_load (
784
+ importlib .resources .read_text ("smolagents.prompts" , "code_agent.yaml" )
785
+ )
783
786
super ().__init__ (
784
787
tools = tools ,
785
788
model = model ,
789
+ prompt_templates = prompt_templates ,
786
790
grammar = grammar ,
787
791
planning_interval = planning_interval ,
788
792
** kwargs ,
0 commit comments