Skip to content

Commit 343b0cc

Browse files
committed
feedback: move validation context 'build + replace' inside build_run_context
1 parent 3d09b51 commit 343b0cc

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

pydantic_ai_slim/pydantic_ai/_agent_graph.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,6 @@ async def _prepare_request(
478478
ctx.state.run_step += 1
479479

480480
run_context = build_run_context(ctx)
481-
validation_context = build_validation_context(ctx.deps.validation_context, run_context)
482-
run_context = replace(run_context, validation_context=validation_context)
483481

484482
# This will raise errors for any tool name conflicts
485483
ctx.deps.tool_manager = await ctx.deps.tool_manager.for_run_step(run_context)
@@ -723,9 +721,6 @@ async def _handle_text_response(
723721
text_processor: _output.BaseOutputProcessor[NodeRunEndT],
724722
) -> ModelRequestNode[DepsT, NodeRunEndT] | End[result.FinalResult[NodeRunEndT]]:
725723
run_context = build_run_context(ctx)
726-
validation_context = build_validation_context(ctx.deps.validation_context, run_context)
727-
728-
run_context = replace(run_context, validation_context=validation_context)
729724

730725
result_data = await text_processor.process(text, run_context=run_context)
731726

@@ -772,7 +767,7 @@ async def run(
772767

773768
def build_run_context(ctx: GraphRunContext[GraphAgentState, GraphAgentDeps[DepsT, Any]]) -> RunContext[DepsT]:
774769
"""Build a `RunContext` object from the current agent graph run context."""
775-
return RunContext[DepsT](
770+
run_context = RunContext[DepsT](
776771
deps=ctx.deps.user_deps,
777772
model=ctx.deps.model,
778773
usage=ctx.state.usage,
@@ -788,6 +783,9 @@ def build_run_context(ctx: GraphRunContext[GraphAgentState, GraphAgentDeps[DepsT
788783
run_step=ctx.state.run_step,
789784
run_id=ctx.state.run_id,
790785
)
786+
validation_context = build_validation_context(ctx.deps.validation_context, run_context)
787+
run_context = replace(run_context, validation_context=validation_context)
788+
return run_context
791789

792790

793791
def build_validation_context(

0 commit comments

Comments
 (0)