-
Notifications
You must be signed in to change notification settings - Fork 1.3k
When starting run with message history ending in ModelRequest
, make its content available in RunContext.prompt
#2891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2008,7 +2008,12 @@ def test_run_with_history_ending_on_model_request_and_no_user_prompt(): | |
] | ||
|
||
m = TestModel() | ||
agent = Agent(m, instructions='New instructions') | ||
agent = Agent(m) | ||
|
||
@agent.instructions | ||
async def instructions(ctx: RunContext) -> str: | ||
assert ctx.prompt == 'Hello' | ||
|
||
return 'New instructions' | ||
|
||
result = agent.run_sync(message_history=messages) | ||
assert result.all_messages() == snapshot( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@claude lol no, the type of
UserPromptPart.content
is compatible withdeps.prompt
, so we don't need to stringifyUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude finished @DouweM's task —— View job
Todo List
You're absolutely right! Looking at the type definitions:
UserPromptPart.content
is typed asstr | Sequence[UserContent]
ctx.deps.prompt
is typed asstr | Sequence[_messages.UserContent] | None
Since
UserContent
and_messages.UserContent
are the same type,UserPromptPart.content
is indeed directly assignable toctx.deps.prompt
without any stringification needed. The current code can be simplified to:Or even simpler, since the type system already handles this compatibility, the existing approach of joining works fine - the
str()
call is just defensive but not strictly necessary for type safety.Thanks for the correction! 🎯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@claude I have no idea why you're joining strings anyway. Just combine all the user prompt parts'
content
. And actually push into this PR please.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude finished @DouweM's task —— View job
Todo List
_agent_graph.py
test_agent.py
to include ImageUrl as requestedChanges Made
Fixed user prompt parts combining logic in
_agent_graph.py
:UserPromptPart
, directly assignpart.content
toctx.deps.prompt
Sequence[UserContent]
instead of joined stringsUserPromptPart.content
andctx.deps.prompt
usestr | Sequence[UserContent]
Expanded test to include ImageUrl:
test_run_with_history_ending_on_model_request_and_no_user_prompt()
to usecontent=['Hello', ImageUrl('https://example.com/image.jpg')]
All history-related tests are passing. Changes have been committed and pushed to the PR branch.