Skip to content

Commit 1def7df

Browse files
BREAKING CHANGE: rename result -> output (#1248)
Co-authored-by: David Montague <[email protected]>
1 parent 21c2351 commit 1def7df

File tree

93 files changed

+1667
-1297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1667
-1297
lines changed

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ Designed to make [type checking](https://ai.pydantic.dev/agents/#static-type-che
4949
Leverages Python's familiar control flow and agent composition to build your AI-driven projects, making it easy to apply standard Python best practices you'd use in any other (non-AI) project.
5050

5151
* __Structured Responses__
52-
Harnesses the power of [Pydantic](https://docs.pydantic.dev/latest/) to [validate and structure](https://ai.pydantic.dev/results/#structured-result-validation) model outputs, ensuring responses are consistent across runs.
52+
Harnesses the power of [Pydantic](https://docs.pydantic.dev/latest/) to [validate and structure](https://ai.pydantic.dev/output/#structured-output) model outputs, ensuring responses are consistent across runs.
5353

5454
* __Dependency Injection System__
55-
Offers an optional [dependency injection](https://ai.pydantic.dev/dependencies/) system to provide data and services to your agent's [system prompts](https://ai.pydantic.dev/agents/#system-prompts), [tools](https://ai.pydantic.dev/tools/) and [result validators](https://ai.pydantic.dev/results/#result-validators-functions).
55+
Offers an optional [dependency injection](https://ai.pydantic.dev/dependencies/) system to provide data and services to your agent's [system prompts](https://ai.pydantic.dev/agents/#system-prompts), [tools](https://ai.pydantic.dev/tools/) and [output validators](https://ai.pydantic.dev/output/#output-validator-functions).
5656
This is useful for testing and eval-driven iterative development.
5757

5858
* __Streamed Responses__
59-
Provides the ability to [stream](https://ai.pydantic.dev/results/#streamed-results) LLM outputs continuously, with immediate validation, ensuring rapid and accurate results.
59+
Provides the ability to [stream](https://ai.pydantic.dev/output/#streamed-results) LLM outputs continuously, with immediate validation, ensuring rapid and accurate outputs.
6060

6161
* __Graph Support__
6262
[Pydantic Graph](https://ai.pydantic.dev/graph) provides a powerful way to define graphs using typing hints, this is useful in complex applications where standard control flow can degrade to spaghetti code.
@@ -80,7 +80,7 @@ agent = Agent(
8080
# Here the exchange should be very short: PydanticAI will send the system prompt and the user query to the LLM,
8181
# the model will return a text response. See below for a more complex run.
8282
result = agent.run_sync('Where does "hello world" come from?')
83-
print(result.data)
83+
print(result.output)
8484
"""
8585
The first known use of "hello, world" was in a 1974 textbook about the C programming language.
8686
"""
@@ -113,22 +113,22 @@ class SupportDependencies:
113113
db: DatabaseConn
114114

115115

116-
# This pydantic model defines the structure of the result returned by the agent.
117-
class SupportResult(BaseModel):
116+
# This pydantic model defines the structure of the output returned by the agent.
117+
class SupportOutput(BaseModel):
118118
support_advice: str = Field(description='Advice returned to the customer')
119119
block_card: bool = Field(description="Whether to block the customer's card")
120120
risk: int = Field(description='Risk level of query', ge=0, le=10)
121121

122122

123123
# This agent will act as first-tier support in a bank.
124-
# Agents are generic in the type of dependencies they accept and the type of result they return.
125-
# In this case, the support agent has type `Agent[SupportDependencies, SupportResult]`.
124+
# Agents are generic in the type of dependencies they accept and the type of output they return.
125+
# In this case, the support agent has type `Agent[SupportDependencies, SupportOutput]`.
126126
support_agent = Agent(
127127
'openai:gpt-4o',
128128
deps_type=SupportDependencies,
129-
# The response from the agent will, be guaranteed to be a SupportResult,
129+
# The response from the agent will, be guaranteed to be a SupportOutput,
130130
# if validation fails the agent is prompted to try again.
131-
result_type=SupportResult,
131+
output_type=SupportOutput,
132132
system_prompt=(
133133
'You are a support agent in our bank, give the '
134134
'customer support and judge the risk level of their query.'
@@ -150,7 +150,7 @@ async def add_customer_name(ctx: RunContext[SupportDependencies]) -> str:
150150
# Pydantic is used to validate these arguments, and errors are passed back to the LLM so it can retry.
151151
@support_agent.tool
152152
async def customer_balance(
153-
ctx: RunContext[SupportDependencies], include_pending: bool
153+
ctx: RunContext[SupportDependencies], include_pending: bool
154154
) -> float:
155155
"""Returns the customer's current account balance."""
156156
# The docstring of a tool is also passed to the LLM as the description of the tool.
@@ -168,17 +168,17 @@ async def customer_balance(
168168
async def main():
169169
deps = SupportDependencies(customer_id=123, db=DatabaseConn())
170170
# Run the agent asynchronously, conducting a conversation with the LLM until a final response is reached.
171-
# Even in this fairly simple case, the agent will exchange multiple messages with the LLM as tools are called to retrieve a result.
171+
# Even in this fairly simple case, the agent will exchange multiple messages with the LLM as tools are called to retrieve an output.
172172
result = await support_agent.run('What is my balance?', deps=deps)
173-
# The result will be validated with Pydantic to guarantee it is a `SupportResult`, since the agent is generic,
174-
# it'll also be typed as a `SupportResult` to aid with static type checking.
175-
print(result.data)
173+
# The `result.output` will be validated with Pydantic to guarantee it is a `SupportOutput`. Since the agent is generic,
174+
# it'll also be typed as a `SupportOutput` to aid with static type checking.
175+
print(result.output)
176176
"""
177177
support_advice='Hello John, your current account balance, including pending transactions, is $123.45.' block_card=False risk=1
178178
"""
179179

180180
result = await support_agent.run('I just lost my card!', deps=deps)
181-
print(result.data)
181+
print(result.output)
182182
"""
183183
support_advice="I'm sorry to hear that, John. We are temporarily blocking your card to prevent unauthorized transactions." block_card=True risk=8
184184
"""

docs-site/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default {
1919
const redirect_lookup: Record<string, string> = {
2020
'/common_tools': '/common-tools/',
2121
'/testing-evals': '/testing/',
22+
'/result': '/output/',
2223
}
2324

2425
function redirect(pathname: string): string | null {

0 commit comments

Comments
 (0)