Skip to content

Commit 375a091

Browse files
committed
Test that the validation context is updated as the deps are mutated
1 parent 61ab2f5 commit 375a091

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test_validation_context.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,28 @@ def identity(ctx: RunContext[Deps], v: Value) -> Value:
120120

121121
result = agent.run_sync('', deps=Deps(increment=10))
122122
assert result.output.x == snapshot(10)
123+
124+
125+
def test_agent_output_validator_with_intermediary_deps_change_and_validation_context():
126+
"""Test that the validation context is updated as run dependencies are mutated."""
127+
128+
agent = Agent(
129+
'test',
130+
output_type=Value,
131+
deps_type=Deps,
132+
validation_context=lambda ctx: ctx.deps.increment,
133+
)
134+
135+
@agent.tool
136+
def bump_increment(ctx: RunContext[Deps]):
137+
assert ctx.validation_context == snapshot(10) # validation ctx was first computed using the original deps
138+
ctx.deps.increment += 5 # update the deps
139+
140+
@agent.output_validator
141+
def identity(ctx: RunContext[Deps], v: Value) -> Value:
142+
assert ctx.validation_context == snapshot(15) # validation ctx was re-computed after deps update from tool call
143+
144+
return v
145+
146+
result = agent.run_sync('', deps=Deps(increment=10))
147+
assert result.output.x == snapshot(15)

0 commit comments

Comments
 (0)