Skip to content

Commit 432c954

Browse files
committed
add tool_args_partial to RunContext
1 parent 2036411 commit 432c954

File tree

5 files changed

+7
-3
lines changed

5 files changed

+7
-3
lines changed

docs/durable_execution/temporal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ As workflows and activities run in separate processes, any values passed between
172172

173173
To account for these limitations, tool functions and the [event stream handler](#streaming) running inside activities receive a limited version of the agent's [`RunContext`][pydantic_ai.tools.RunContext], and it's your responsibility to make sure that the [dependencies](../dependencies.md) object provided to [`TemporalAgent.run()`][pydantic_ai.durable_exec.temporal.TemporalAgent.run] can be serialized using Pydantic.
174174

175-
Specifically, only the `deps`, `retries`, `tool_call_id`, `tool_name`, `tool_call_approved`, `retry`, `max_retries` and `run_step` fields are available by default, and trying to access `model`, `usage`, `prompt`, `messages`, or `tracer` will raise an error.
175+
Specifically, only the `deps`, `retries`, `tool_call_id`, `tool_name`, `tool_call_approved`, `retry`, `max_retries`, `run_step` and `tool_args_partial` fields are available by default, and trying to access `model`, `usage`, `prompt`, `messages`, or `tracer` will raise an error.
176176
If you need one or more of these attributes to be available inside activities, you can create a [`TemporalRunContext`][pydantic_ai.durable_exec.temporal.TemporalRunContext] subclass with custom `serialize_run_context` and `deserialize_run_context` class methods and pass it to [`TemporalAgent`][pydantic_ai.durable_exec.temporal.TemporalAgent] as `run_context_type`.
177177

178178
### Streaming

pydantic_ai_slim/pydantic_ai/_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ async def call_tool(
10831083
) -> Any:
10841084
output = await self.processors[name].call(tool_args, ctx, wrap_validation_errors=False)
10851085
for validator in self.output_validators:
1086-
output = await validator.validate(output, ctx, wrap_validation_errors=False)
1086+
output = await validator.validate(output, ctx, wrap_validation_errors=False, partial=ctx.tool_args_partial)
10871087
return output
10881088

10891089

pydantic_ai_slim/pydantic_ai/_run_context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class RunContext(Generic[AgentDepsT]):
5454
"""The current step in the run."""
5555
tool_call_approved: bool = False
5656
"""Whether a tool call that required approval has now been approved."""
57+
tool_args_partial: bool = False
58+
"""Whether args are partial in the tool call."""
5759

5860
@property
5961
def last_attempt(self) -> bool:

pydantic_ai_slim/pydantic_ai/_tool_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ async def _call_tool(
145145
self.ctx,
146146
tool_name=name,
147147
tool_call_id=call.tool_call_id,
148+
tool_args_partial=allow_partial,
148149
retry=self.ctx.retries.get(name, 0),
149150
max_retries=tool.max_retries,
150151
)

pydantic_ai_slim/pydantic_ai/durable_exec/temporal/_run_context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class TemporalRunContext(RunContext[AgentDepsT]):
1010
"""The [`RunContext`][pydantic_ai.tools.RunContext] subclass to use to serialize and deserialize the run context for use inside a Temporal activity.
1111
12-
By default, only the `deps`, `retries`, `tool_call_id`, `tool_name`, `tool_call_approved`, `retry`, `max_retries` and `run_step` attributes will be available.
12+
By default, only the `deps`, `retries`, `tool_call_id`, `tool_name`, `tool_call_approved`, `tool_args_partial`, `retry`, `max_retries` and `run_step` attributes will be available.
1313
To make another attribute available, create a `TemporalRunContext` subclass with a custom `serialize_run_context` class method that returns a dictionary that includes the attribute and pass it to [`TemporalAgent`][pydantic_ai.durable_exec.temporal.TemporalAgent].
1414
"""
1515

@@ -41,6 +41,7 @@ def serialize_run_context(cls, ctx: RunContext[Any]) -> dict[str, Any]:
4141
'tool_call_id': ctx.tool_call_id,
4242
'tool_name': ctx.tool_name,
4343
'tool_call_approved': ctx.tool_call_approved,
44+
'tool_args_partial': ctx.tool_args_partial,
4445
'retry': ctx.retry,
4546
'max_retries': ctx.max_retries,
4647
'run_step': ctx.run_step,

0 commit comments

Comments
 (0)