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
@@ -179,7 +179,9 @@ They're useful when it is impractical or impossible to put all the context an ag
179
179
There are two different decorator functions to register retrievers:
180
180
181
181
1.[`@agent.retriever_plain`][pydantic_ai.Agent.retriever_plain] — for retrievers that don't need access to the agent [context][pydantic_ai.dependencies.CallContext]
182
-
2.[`@agent.retriever_context`][pydantic_ai.Agent.retriever_context] — for retrievers that do need access to the agent [context][pydantic_ai.dependencies.CallContext]
182
+
2.[`@agent.retriever`][pydantic_ai.Agent.retriever] — for retrievers that do need access to the agent [context][pydantic_ai.dependencies.CallContext]
183
+
184
+
`@agent.retriever` is the default since in the majority of cases retrievers will need access to the agent context.
183
185
184
186
Here's an example using both:
185
187
@@ -205,7 +207,7 @@ def roll_dice() -> str:
205
207
returnstr(random.randint(1, 6))
206
208
207
209
208
-
@agent.retriever_context# (4)!
210
+
@agent.retriever# (4)!
209
211
defget_player_name(ctx: CallContext[str]) -> str:
210
212
"""Get the player's name."""
211
213
return ctx.deps
@@ -219,7 +221,7 @@ print(dice_result.data)
219
221
1. This is a pretty simple task, so we can use the fast and cheap Gemini flash model.
220
222
2. We pass the user's name as the dependency, to keep things simple we use just the name as a string as the dependency.
221
223
3. This retriever doesn't need any context, it just returns a random number. You could probably use a dynamic system prompt in this case.
222
-
4. This retriever needs the player's name, so it uses `CallContext` to access dependencies which are just the player's name.
224
+
4. This retriever needs the player's name, so it uses `CallContext` to access dependencies which are just the player's name in this case.
223
225
5. Run the agent, passing the player's name as the dependency.
224
226
225
227
_(This example is complete, it can be run "as is")_
@@ -362,7 +364,7 @@ Validation errors from both retriever parameter validation and [structured resul
362
364
363
365
You can also raise [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] from within a [retriever](#retrievers) or [result validator functions](results.md#result-validators-functions) to tell the model it should retry.
364
366
365
-
- The default retry count is **1** but can be altered for the [entire agent][pydantic_ai.Agent.__init__], a [specific retriever][pydantic_ai.Agent.retriever_context], or a [result validator][pydantic_ai.Agent.__init__].
367
+
- The default retry count is **1** but can be altered for the [entire agent][pydantic_ai.Agent.__init__], a [specific retriever][pydantic_ai.Agent.retriever], or a [result validator][pydantic_ai.Agent.__init__].
366
368
- You can access the current retry count from within a retriever or result validator via [`ctx.retry`][pydantic_ai.dependencies.CallContext].
0 commit comments