Skip to content

Commit d0325e9

Browse files
committed
Add AgentRun.{all,new}_messages
This allows convenient access to these even if the run didn't end, at which point they would not be available via `AgentRun.result`.
1 parent 4cc4f35 commit d0325e9

File tree

1 file changed

+16
-0
lines changed
  • pydantic_ai_slim/pydantic_ai

1 file changed

+16
-0
lines changed

pydantic_ai_slim/pydantic_ai/run.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ def result(self) -> AgentRunResult[OutputDataT] | None:
135135
self._traceparent(required=False),
136136
)
137137

138+
@property
139+
def all_messages(self) -> list[_messages.ModelMessage]:
140+
"""Return all messages.
141+
142+
Messages from older runs are included.
143+
"""
144+
return self.ctx.state.message_history
145+
146+
@property
147+
def new_messages(self) -> list[_messages.ModelMessage]:
148+
"""Return new messages associated with this run.
149+
150+
Messages from older runs are excluded.
151+
"""
152+
return self.ctx.state.message_history[self.ctx.deps.new_message_index :]
153+
138154
def __aiter__(
139155
self,
140156
) -> AsyncIterator[_agent_graph.AgentNode[AgentDepsT, OutputDataT] | End[FinalResult[OutputDataT]]]:

0 commit comments

Comments
 (0)