@@ -152,7 +152,10 @@ def __init__(
152
152
model : models .Model | models .KnownModelName | str | None = None ,
153
153
* ,
154
154
output_type : type [OutputDataT ] | ToolOutput [OutputDataT ] = str ,
155
- instructions : str | _system_prompt .SystemPromptFunc [AgentDepsT ] | None = None ,
155
+ instructions : str
156
+ | _system_prompt .SystemPromptFunc [AgentDepsT ]
157
+ | Sequence [str | _system_prompt .SystemPromptFunc [AgentDepsT ]]
158
+ | None = None ,
156
159
system_prompt : str | Sequence [str ] = (),
157
160
deps_type : type [AgentDepsT ] = NoneType ,
158
161
name : str | None = None ,
@@ -175,7 +178,10 @@ def __init__(
175
178
model : models .Model | models .KnownModelName | str | None = None ,
176
179
* ,
177
180
result_type : type [OutputDataT ] = str ,
178
- instructions : str | _system_prompt .SystemPromptFunc [AgentDepsT ] | None = None ,
181
+ instructions : str
182
+ | _system_prompt .SystemPromptFunc [AgentDepsT ]
183
+ | Sequence [str | _system_prompt .SystemPromptFunc [AgentDepsT ]]
184
+ | None = None ,
179
185
system_prompt : str | Sequence [str ] = (),
180
186
deps_type : type [AgentDepsT ] = NoneType ,
181
187
name : str | None = None ,
@@ -197,7 +203,10 @@ def __init__(
197
203
* ,
198
204
# TODO change this back to `output_type: type[OutputDataT] | ToolOutput[OutputDataT] = str,` when we remove the overloads
199
205
output_type : Any = str ,
200
- instructions : str | _system_prompt .SystemPromptFunc [AgentDepsT ] | None = None ,
206
+ instructions : str
207
+ | _system_prompt .SystemPromptFunc [AgentDepsT ]
208
+ | Sequence [str | _system_prompt .SystemPromptFunc [AgentDepsT ]]
209
+ | None = None ,
201
210
system_prompt : str | Sequence [str ] = (),
202
211
deps_type : type [AgentDepsT ] = NoneType ,
203
212
name : str | None = None ,
@@ -296,10 +305,16 @@ def __init__(
296
305
)
297
306
self ._output_validators = []
298
307
299
- self ._instructions_functions = (
300
- [_system_prompt .SystemPromptRunner (instructions )] if callable (instructions ) else []
301
- )
302
- self ._instructions = instructions if isinstance (instructions , str ) else None
308
+ self ._instructions = ''
309
+ self ._instructions_functions = []
310
+ if isinstance (instructions , (str , Callable )):
311
+ instructions = [instructions ]
312
+ for instruction in instructions or []:
313
+ if isinstance (instruction , str ):
314
+ self ._instructions += instruction + '\n '
315
+ else :
316
+ self ._instructions_functions .append (_system_prompt .SystemPromptRunner (instruction ))
317
+ self ._instructions = self ._instructions .strip () or None
303
318
304
319
self ._system_prompts = (system_prompt ,) if isinstance (system_prompt , str ) else tuple (system_prompt )
305
320
self ._system_prompt_functions = []
@@ -625,8 +640,8 @@ async def get_instructions(run_context: RunContext[AgentDepsT]) -> str | None:
625
640
626
641
instructions = self ._instructions or ''
627
642
for instructions_runner in self ._instructions_functions :
628
- instructions += await instructions_runner .run (run_context )
629
- return instructions
643
+ instructions += ' \n ' + await instructions_runner .run (run_context )
644
+ return instructions . strip ()
630
645
631
646
graph_deps = _agent_graph .GraphAgentDeps [AgentDepsT , RunOutputDataT ](
632
647
user_deps = deps ,
0 commit comments