Skip to content

Commit d599924

Browse files
author
baek54321
committed
Extend DBOS, Prefect and Temporal agent. Update docs after review.
1 parent d4ac8c7 commit d599924

File tree

7 files changed

+86
-14
lines changed

7 files changed

+86
-14
lines changed

docs/agents.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -904,17 +904,15 @@ You should use:
904904

905905
In general, we recommend using `instructions` instead of `system_prompt` unless you have a specific reason to use `system_prompt`.
906906

907-
Instructions, like system prompts, fall into two categories:
907+
Instructions, like system prompts, can be specified at different times:
908908

909909
1. **Static instructions**: These are known when writing the code and can be defined via the `instructions` parameter of the [`Agent` constructor][pydantic_ai.Agent.__init__].
910-
2. **Dynamic instructions**: These rely on context that is only available at runtime. Dynamic instructions can be further divided into *temporary* dynamic instructions which are used only for a
911-
single run and *permanent* dynamic instructions, which are used for all runs.
912-
- **Dynamic temporary instructions*: Should be defined via the *instructions* argument to any of the `run` methods and will be effective only for the specific run for which they have been specified
913-
- **Dynamic permanent instructions*: Should be defined using functions decorated with [`@agent.instructions`][pydantic_ai.Agent.instructions]. Unlike dynamic system prompts, which may be reused when `message_history` is present, dynamic instructions are always reevaluated.
910+
2. **Dynamic instructions**: These rely on context that is only available at runtime and should be defined using functions decorated with [`@agent.instructions`][pydantic_ai.Agent.instructions]. Unlike dynamic system prompts, which may be reused when `message_history` is present, dynamic instructions are always reevaluated.
911+
3. **Runtime instructions*:: These can be used to pass additional instructions to the agent at runtime and are valid for that specific run.
914912

915-
Both static and dynamic instructions can be added to a single agent, and they are appended in the order they are defined at runtime.
913+
All three types of instructions can be added to a single agent, and they are appended in the order they are defined at runtime.
916914

917-
Here's an example using a static instruction as well as permanent dynamic instructions:
915+
Here's an example using a static instruction as well as dynamic instructions:
918916

919917
```python {title="instructions.py"}
920918
from datetime import date

pydantic_ai_slim/pydantic_ai/agent/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ async def main():
530530
message_history: History of the conversation so far.
531531
deferred_tool_results: Optional results for deferred tool calls in the message history.
532532
model: Optional model to use for this run, required if `model` was not set when creating the agent.
533-
instructions: Optional instructions to append to the instructions provided at the initialization of the agent and only to be used for this run.
533+
instructions: Optional additional instructions to use for this run.
534534
deps: Optional dependencies to use for this run.
535535
model_settings: Optional settings to use for this model's request.
536536
usage_limits: Optional limits on model request count or token usage.

pydantic_ai_slim/pydantic_ai/agent/abstract.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ async def main():
204204
message_history: History of the conversation so far.
205205
deferred_tool_results: Optional results for deferred tool calls in the message history.
206206
model: Optional model to use for this run, required if `model` was not set when creating the agent.
207-
instructions: Optional instructions to append to the instructions provided at the initialization of the agent and only to be used for this run.
207+
instructions: Optional additional instructions to use for this run.
208208
deps: Optional dependencies to use for this run.
209209
model_settings: Optional settings to use for this model's request.
210210
usage_limits: Optional limits on model request count or token usage.
@@ -327,7 +327,7 @@ def run_sync(
327327
message_history: History of the conversation so far.
328328
deferred_tool_results: Optional results for deferred tool calls in the message history.
329329
model: Optional model to use for this run, required if `model` was not set when creating the agent.
330-
instructions: Optional instructions to append to the instructions provided at the initialization of the agent and only to be used for this run.
330+
instructions: Optional additional instructions to use for this run.
331331
deps: Optional dependencies to use for this run.
332332
model_settings: Optional settings to use for this model's request.
333333
usage_limits: Optional limits on model request count or token usage.
@@ -452,7 +452,7 @@ async def main():
452452
message_history: History of the conversation so far.
453453
deferred_tool_results: Optional results for deferred tool calls in the message history.
454454
model: Optional model to use for this run, required if `model` was not set when creating the agent.
455-
instructions: Optional instructions to append to the instructions provided at the initialization of the agent and only to be used for this run.
455+
instructions: Optional additional instructions to use for this run.
456456
deps: Optional dependencies to use for this run.
457457
model_settings: Optional settings to use for this model's request.
458458
usage_limits: Optional limits on model request count or token usage.
@@ -818,7 +818,7 @@ async def main():
818818
message_history: History of the conversation so far.
819819
deferred_tool_results: Optional results for deferred tool calls in the message history.
820820
model: Optional model to use for this run, required if `model` was not set when creating the agent.
821-
instructions: Optional instructions to append to the instructions provided at the initialization of the agent and only to be used for this run.
821+
instructions: Optional additional instructions to use for this run.
822822
deps: Optional dependencies to use for this run.
823823
model_settings: Optional settings to use for this model's request.
824824
usage_limits: Optional limits on model request count or token usage.
@@ -1028,7 +1028,7 @@ async def main():
10281028
message_history: History of the conversation so far.
10291029
deferred_tool_results: Optional results for deferred tool calls in the message history.
10301030
model: Optional model to use for this run, required if `model` was not set when creating the agent.
1031-
instructions: Optional instructions to append to the instructions provided at the initialization of the agent and only to be used for this run.
1031+
instructions: Optional additional instructions to use for this run.
10321032
deps: Optional dependencies to use for this run.
10331033
model_settings: Optional settings to use for this model's request.
10341034
usage_limits: Optional limits on model request count or token usage.

pydantic_ai_slim/pydantic_ai/agent/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ async def main():
188188
message_history: History of the conversation so far.
189189
deferred_tool_results: Optional results for deferred tool calls in the message history.
190190
model: Optional model to use for this run, required if `model` was not set when creating the agent.
191-
instructions: Optional instructions to append to the instructions provided at the initialization of the agent and only to be used for this run.
191+
instructions: Optional additional instructions to use for this run.
192192
deps: Optional dependencies to use for this run.
193193
model_settings: Optional settings to use for this model's request.
194194
usage_limits: Optional limits on model request count or token usage.

pydantic_ai_slim/pydantic_ai/durable_exec/dbos/_agent.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ async def run(
245245
message_history: Sequence[_messages.ModelMessage] | None = None,
246246
deferred_tool_results: DeferredToolResults | None = None,
247247
model: models.Model | models.KnownModelName | str | None = None,
248+
instructions: Instructions[AgentDepsT] = None,
248249
deps: AgentDepsT = None,
249250
model_settings: ModelSettings | None = None,
250251
usage_limits: _usage.UsageLimits | None = None,
@@ -264,6 +265,7 @@ async def run(
264265
message_history: Sequence[_messages.ModelMessage] | None = None,
265266
deferred_tool_results: DeferredToolResults | None = None,
266267
model: models.Model | models.KnownModelName | str | None = None,
268+
instructions: Instructions[AgentDepsT] = None,
267269
deps: AgentDepsT = None,
268270
model_settings: ModelSettings | None = None,
269271
usage_limits: _usage.UsageLimits | None = None,
@@ -282,6 +284,7 @@ async def run(
282284
message_history: Sequence[_messages.ModelMessage] | None = None,
283285
deferred_tool_results: DeferredToolResults | None = None,
284286
model: models.Model | models.KnownModelName | str | None = None,
287+
instructions: Instructions[AgentDepsT] = None,
285288
deps: AgentDepsT = None,
286289
model_settings: ModelSettings | None = None,
287290
usage_limits: _usage.UsageLimits | None = None,
@@ -316,6 +319,7 @@ async def main():
316319
message_history: History of the conversation so far.
317320
deferred_tool_results: Optional results for deferred tool calls in the message history.
318321
model: Optional model to use for this run, required if `model` was not set when creating the agent.
322+
instructions: Optional additional instructions to use for this run.
319323
deps: Optional dependencies to use for this run.
320324
model_settings: Optional settings to use for this model's request.
321325
usage_limits: Optional limits on model request count or token usage.
@@ -334,6 +338,7 @@ async def main():
334338
message_history=message_history,
335339
deferred_tool_results=deferred_tool_results,
336340
model=model,
341+
instructions=instructions,
337342
deps=deps,
338343
model_settings=model_settings,
339344
usage_limits=usage_limits,
@@ -354,6 +359,7 @@ def run_sync(
354359
message_history: Sequence[_messages.ModelMessage] | None = None,
355360
deferred_tool_results: DeferredToolResults | None = None,
356361
model: models.Model | models.KnownModelName | str | None = None,
362+
instructions: Instructions[AgentDepsT] = None,
357363
deps: AgentDepsT = None,
358364
model_settings: ModelSettings | None = None,
359365
usage_limits: _usage.UsageLimits | None = None,
@@ -373,6 +379,7 @@ def run_sync(
373379
message_history: Sequence[_messages.ModelMessage] | None = None,
374380
deferred_tool_results: DeferredToolResults | None = None,
375381
model: models.Model | models.KnownModelName | str | None = None,
382+
instructions: Instructions[AgentDepsT] = None,
376383
deps: AgentDepsT = None,
377384
model_settings: ModelSettings | None = None,
378385
usage_limits: _usage.UsageLimits | None = None,
@@ -391,6 +398,7 @@ def run_sync(
391398
message_history: Sequence[_messages.ModelMessage] | None = None,
392399
deferred_tool_results: DeferredToolResults | None = None,
393400
model: models.Model | models.KnownModelName | str | None = None,
401+
instructions: Instructions[AgentDepsT] = None,
394402
deps: AgentDepsT = None,
395403
model_settings: ModelSettings | None = None,
396404
usage_limits: _usage.UsageLimits | None = None,
@@ -424,6 +432,7 @@ def run_sync(
424432
message_history: History of the conversation so far.
425433
deferred_tool_results: Optional results for deferred tool calls in the message history.
426434
model: Optional model to use for this run, required if `model` was not set when creating the agent.
435+
instructions: Optional additional instructions to use for this run.
427436
deps: Optional dependencies to use for this run.
428437
model_settings: Optional settings to use for this model's request.
429438
usage_limits: Optional limits on model request count or token usage.
@@ -442,6 +451,7 @@ def run_sync(
442451
message_history=message_history,
443452
deferred_tool_results=deferred_tool_results,
444453
model=model,
454+
instructions=instructions,
445455
deps=deps,
446456
model_settings=model_settings,
447457
usage_limits=usage_limits,
@@ -462,6 +472,7 @@ def run_stream(
462472
message_history: Sequence[_messages.ModelMessage] | None = None,
463473
deferred_tool_results: DeferredToolResults | None = None,
464474
model: models.Model | models.KnownModelName | str | None = None,
475+
instructions: Instructions[AgentDepsT] = None,
465476
deps: AgentDepsT = None,
466477
model_settings: ModelSettings | None = None,
467478
usage_limits: _usage.UsageLimits | None = None,
@@ -482,6 +493,7 @@ def run_stream(
482493
deferred_tool_results: DeferredToolResults | None = None,
483494
model: models.Model | models.KnownModelName | str | None = None,
484495
deps: AgentDepsT = None,
496+
instructions: Instructions[AgentDepsT] = None,
485497
model_settings: ModelSettings | None = None,
486498
usage_limits: _usage.UsageLimits | None = None,
487499
usage: _usage.RunUsage | None = None,
@@ -500,6 +512,7 @@ async def run_stream(
500512
message_history: Sequence[_messages.ModelMessage] | None = None,
501513
deferred_tool_results: DeferredToolResults | None = None,
502514
model: models.Model | models.KnownModelName | str | None = None,
515+
instructions: Instructions[AgentDepsT] = None,
503516
deps: AgentDepsT = None,
504517
model_settings: ModelSettings | None = None,
505518
usage_limits: _usage.UsageLimits | None = None,
@@ -531,6 +544,7 @@ async def main():
531544
message_history: History of the conversation so far.
532545
deferred_tool_results: Optional results for deferred tool calls in the message history.
533546
model: Optional model to use for this run, required if `model` was not set when creating the agent.
547+
instructions: Optional additional instructions to use for this run.
534548
deps: Optional dependencies to use for this run.
535549
model_settings: Optional settings to use for this model's request.
536550
usage_limits: Optional limits on model request count or token usage.
@@ -555,6 +569,7 @@ async def main():
555569
message_history=message_history,
556570
deferred_tool_results=deferred_tool_results,
557571
model=model,
572+
instructions=instructions,
558573
deps=deps,
559574
model_settings=model_settings,
560575
usage_limits=usage_limits,
@@ -576,6 +591,7 @@ def run_stream_events(
576591
message_history: Sequence[_messages.ModelMessage] | None = None,
577592
deferred_tool_results: DeferredToolResults | None = None,
578593
model: models.Model | models.KnownModelName | str | None = None,
594+
instructions: Instructions[AgentDepsT] = None,
579595
deps: AgentDepsT = None,
580596
model_settings: ModelSettings | None = None,
581597
usage_limits: _usage.UsageLimits | None = None,
@@ -594,6 +610,7 @@ def run_stream_events(
594610
message_history: Sequence[_messages.ModelMessage] | None = None,
595611
deferred_tool_results: DeferredToolResults | None = None,
596612
model: models.Model | models.KnownModelName | str | None = None,
613+
instructions: Instructions[AgentDepsT] = None,
597614
deps: AgentDepsT = None,
598615
model_settings: ModelSettings | None = None,
599616
usage_limits: _usage.UsageLimits | None = None,
@@ -611,6 +628,7 @@ def run_stream_events(
611628
message_history: Sequence[_messages.ModelMessage] | None = None,
612629
deferred_tool_results: DeferredToolResults | None = None,
613630
model: models.Model | models.KnownModelName | str | None = None,
631+
instructions: Instructions[AgentDepsT] = None,
614632
deps: AgentDepsT = None,
615633
model_settings: ModelSettings | None = None,
616634
usage_limits: _usage.UsageLimits | None = None,
@@ -660,6 +678,7 @@ async def main():
660678
message_history: History of the conversation so far.
661679
deferred_tool_results: Optional results for deferred tool calls in the message history.
662680
model: Optional model to use for this run, required if `model` was not set when creating the agent.
681+
instructions: Optional additional instructions to use for this run.
663682
deps: Optional dependencies to use for this run.
664683
model_settings: Optional settings to use for this model's request.
665684
usage_limits: Optional limits on model request count or token usage.
@@ -686,6 +705,7 @@ def iter(
686705
message_history: Sequence[_messages.ModelMessage] | None = None,
687706
deferred_tool_results: DeferredToolResults | None = None,
688707
model: models.Model | models.KnownModelName | str | None = None,
708+
instructions: Instructions[AgentDepsT] = None,
689709
deps: AgentDepsT = None,
690710
model_settings: ModelSettings | None = None,
691711
usage_limits: _usage.UsageLimits | None = None,
@@ -705,6 +725,7 @@ def iter(
705725
message_history: Sequence[_messages.ModelMessage] | None = None,
706726
deferred_tool_results: DeferredToolResults | None = None,
707727
model: models.Model | models.KnownModelName | str | None = None,
728+
instructions: Instructions[AgentDepsT] = None,
708729
deps: AgentDepsT = None,
709730
model_settings: ModelSettings | None = None,
710731
usage_limits: _usage.UsageLimits | None = None,
@@ -724,6 +745,7 @@ async def iter(
724745
message_history: Sequence[_messages.ModelMessage] | None = None,
725746
deferred_tool_results: DeferredToolResults | None = None,
726747
model: models.Model | models.KnownModelName | str | None = None,
748+
instructions: Instructions[AgentDepsT] = None,
727749
deps: AgentDepsT = None,
728750
model_settings: ModelSettings | None = None,
729751
usage_limits: _usage.UsageLimits | None = None,
@@ -798,6 +820,7 @@ async def main():
798820
message_history: History of the conversation so far.
799821
deferred_tool_results: Optional results for deferred tool calls in the message history.
800822
model: Optional model to use for this run, required if `model` was not set when creating the agent.
823+
instructions: Optional additional instructions to use for this run.
801824
deps: Optional dependencies to use for this run.
802825
model_settings: Optional settings to use for this model's request.
803826
usage_limits: Optional limits on model request count or token usage.
@@ -821,6 +844,7 @@ async def main():
821844
message_history=message_history,
822845
deferred_tool_results=deferred_tool_results,
823846
model=model,
847+
instructions=instructions,
824848
deps=deps,
825849
model_settings=model_settings,
826850
usage_limits=usage_limits,

0 commit comments

Comments
 (0)