Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite6396cc

Browse files
⚡️ Speed up methodAgentRunResult._set_output_tool_return by 18798% (#2196)
Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
1 parent883e1ea commite6396cc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

‎pydantic_ai_slim/pydantic_ai/agent.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,12 +2218,18 @@ def _set_output_tool_return(self, return_content: str) -> list[_messages.ModelMe
22182218
"""
22192219
ifnotself._output_tool_name:
22202220
raiseValueError('Cannot set output tool return content when the return type is `str`.')
2221-
messages=deepcopy(self._state.message_history)
2221+
2222+
messages=self._state.message_history
22222223
last_message=messages[-1]
2223-
forpartinlast_message.parts:
2224+
foridx,partinenumerate(last_message.parts):
22242225
ifisinstance(part,_messages.ToolReturnPart)andpart.tool_name==self._output_tool_name:
2225-
part.content=return_content
2226-
returnmessages
2226+
# Only do deepcopy when we have to modify
2227+
copied_messages=list(messages)
2228+
copied_last=deepcopy(last_message)
2229+
copied_last.parts[idx].content=return_content# type: ignore[misc]
2230+
copied_messages[-1]=copied_last
2231+
returncopied_messages
2232+
22272233
raiseLookupError(f'No tool call found with tool name{self._output_tool_name!r}.')
22282234

22292235
@overload

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp