You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -203,7 +203,7 @@ You can add both to a single agent; they're appended in the order they're define
203
203
204
204
Here's an example using both types of system prompts:
205
205
206
-
```pytitle="system_prompts.py"
206
+
```python {title="system_prompts.py"}
207
207
from datetime import date
208
208
209
209
from pydantic_ai import Agent, RunContext
@@ -258,7 +258,7 @@ There are a number of ways to register tools with an agent:
258
258
259
259
Here's an example using both:
260
260
261
-
```pytitle="dice_game.py"
261
+
```python {title="dice_game.py"}
262
262
import random
263
263
264
264
from pydantic_ai import Agent, RunContext
@@ -301,7 +301,7 @@ _(This example is complete, it can be run "as is")_
301
301
302
302
Let's print the messages from that game to see what happened:
303
303
304
-
```pytitle="dice_game_messages.py"
304
+
```python {title="dice_game_messages.py"}
305
305
from dice_game import dice_result
306
306
307
307
print(dice_result.all_messages())
@@ -399,7 +399,7 @@ sequenceDiagram
399
399
400
400
As well as using the decorators, we can register tools via the `tools` argument to the [`Agent` constructor][pydantic_ai.Agent.__init__]. This is useful when you want to re-use tools, and can also give more fine-grained control over the tools.
401
401
402
-
```pytitle="dice_game_tool_kwarg.py"
402
+
```python {title="dice_game_tool_kwarg.py"}
403
403
import random
404
404
405
405
from pydantic_ai import Agent, RunContext, Tool
@@ -452,7 +452,7 @@ Even better, PydanticAI extracts the docstring from functions and (thanks to [gr
452
452
453
453
To demonstrate a tool's schema, here we use [`FunctionModel`][pydantic_ai.models.function.FunctionModel] to print the schema a model would receive:
454
454
455
-
```pytitle="tool_schema.py"
455
+
```python {title="tool_schema.py"}
456
456
from pydantic_ai import Agent
457
457
from pydantic_ai.messages import Message, ModelAnyResponse, ModelTextResponse
458
458
from pydantic_ai.models.function import AgentInfo, FunctionModel
@@ -509,7 +509,7 @@ If a tool has a single parameter that can be represented as an object in JSON sc
509
509
510
510
Here's an example, we use [`TestModel.agent_model_function_tools`][pydantic_ai.models.test.TestModel.agent_model_function_tools] to inspect the tool schema that would be passed to the model.
511
511
512
-
```pytitle="single_parameter_tool.py"
512
+
```python {title="single_parameter_tool.py"}
513
513
from pydantic import BaseModel
514
514
515
515
from pydantic_ai import Agent
@@ -577,7 +577,7 @@ Here's a simple `prepare` method that only includes the tool if the value of the
577
577
578
578
As with the previous example, we use [`TestModel`][pydantic_ai.models.test.TestModel] to demonstrate the behavior without calling a real model.
579
579
580
-
```pytitle="tool_only_if_42.py"
580
+
```python {title="tool_only_if_42.py"}
581
581
from typing import Union
582
582
583
583
from pydantic_ai import Agent, RunContext
@@ -612,7 +612,7 @@ Here's a more complex example where we change the description of the `name` para
612
612
613
613
For the sake of variation, we create this tool using the [`Tool`][pydantic_ai.tools.Tool] dataclass.
614
614
615
-
```pytitle="customize_name.py"
615
+
```python {title="customize_name.py"}
616
616
from__future__import annotations
617
617
618
618
from typing import Literal
@@ -678,7 +678,7 @@ You can also raise [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] from within
678
678
679
679
Here's an example:
680
680
681
-
```pytitle="tool_retry.py"
681
+
```python {title="tool_retry.py"}
682
682
from fake_database import DatabaseConn
683
683
from pydantic import BaseModel
684
684
@@ -726,7 +726,7 @@ If models behave unexpectedly (e.g., the retry limit is exceeded, or their API r
726
726
727
727
In these cases, [`agent.last_run_messages`][pydantic_ai.Agent.last_run_messages] can be used to access the messages exchanged during the run to help diagnose the issue.
728
728
729
-
```py
729
+
```python
730
730
from pydantic_ai import Agent, ModelRetry, UnexpectedModelBehavior
Copy file name to clipboardExpand all lines: docs/dependencies.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Here's an example of defining an agent that requires dependencies.
12
12
13
13
(**Note:** dependencies aren't actually used in this example, see [Accessing Dependencies](#accessing-dependencies) below)
14
14
15
-
```pytitle="unused_dependencies.py"
15
+
```python {title="unused_dependencies.py"}
16
16
from dataclasses import dataclass
17
17
18
18
import httpx
@@ -54,7 +54,7 @@ _(This example is complete, it can be run "as is")_
54
54
Dependencies are accessed through the [`RunContext`][pydantic_ai.tools.RunContext] type, this should be the first parameter of system prompt functions etc.
@@ -112,7 +112,7 @@ to use `async` methods where dependencies perform IO, although synchronous depen
112
112
113
113
Here's the same example as above, but with a synchronous dependency:
114
114
115
-
```pytitle="sync_dependencies.py"
115
+
```python {title="sync_dependencies.py"}
116
116
from dataclasses import dataclass
117
117
118
118
import httpx
@@ -160,7 +160,7 @@ _(This example is complete, it can be run "as is")_
160
160
161
161
As well as system prompts, dependencies can be used in [tools](agents.md#function-tools) and [result validators](results.md#result-validators-functions).
3. Application code that calls the agent, in a real application this might be an API endpoint.
276
276
4. Call the agent from within the application code, in a real application this call might be deep within a call stack. Note `app_deps` here will NOT be used when deps are overridden.
Copy file name to clipboardExpand all lines: docs/examples/chat-app.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,18 +29,18 @@ TODO screenshot.
29
29
30
30
Python code that runs the chat app:
31
31
32
-
```pytitle="chat_app.py"
32
+
```python {title="chat_app.py"}
33
33
#! pydantic_ai_examples/chat_app.py
34
34
```
35
35
36
36
Simple HTML page to render the app:
37
37
38
-
```html title="chat_app.html"
38
+
```html{title="chat_app.html"}
39
39
#! pydantic_ai_examples/chat_app.html
40
40
```
41
41
42
42
TypeScript to handle rendering the messages, to keep this simple (and at the risk of offending frontend developers) the typescript code is passed to the browser as plain text and transpiled in the browser.
0 commit comments