Skip to content

Allow to pass both session and input list #1298

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

DanieleMorotti
Copy link
Contributor

@DanieleMorotti DanieleMorotti commented Jul 29, 2025

Summary

This PR has been implemented to resolve #1140 . I added a parameter to the RunConfig object such that it can be specified if the given input list will replace the session history or it will be appended to it.

The current implementation is a possible approach but I would be happy to change the code if there are better solutions.

@seratch @rm-openai whenever you have a moment, please let me know your thoughts.

Test plan

I added 2 unit tests in tests/test_session.py.

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

@@ -1212,8 +1223,17 @@ async def _prepare_input_with_session(
# Convert input to list format
new_input_list = ItemHelpers.input_to_new_input_list(input)

# Combine history with new input
combined_input = history + new_input_list
if session_input_handling == "append" or session_input_handling is None:
Copy link
Member

@seratch seratch Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, allowing to pass callback function here to combine the item list to save sounds more flexible. @rm-openai what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this would offer much more flexibility.
However, would you still preserve the option for the users to specify "replace" or "append" in order to apply some predefined processing?

In that scenario, the RunConfig attribute could accept a Callable, a str or None.

Or would you prefer to have a more complex implementation like the one done for MCP filters (ToolFilterCallable, etc)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sessions are supposed to be used for maintaining conversation history across multiple agent runs. So, I don't think "replace" is a common use case. If "replace" works well, do you really need a session for the case?

If a developer would like to make some adjustments to stored history based on some conditions, that could be a valid use case (I still think it's an edge case though). That's why I thought enabling callback functions here would make more sense.

Let me know if I am missing anything!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. And what should happen if the callback function is left unspecified (None) and the input is a list? We may raise an error, as in the current implementation.

Moreover, does the callback function only take the history and the list of new items as input, or should I allow additional parameters?

@seratch seratch added bug Something isn't working feature:sessions enhancement New feature or request labels Jul 29, 2025
@seratch seratch requested a review from rm-openai July 29, 2025 23:28
@DanieleMorotti
Copy link
Contributor Author

I implemented a new version, where the RunConfig attribute accepts a callback function that takes as input the history from the session and the new inputs.

Let me know what else should be improved.

@rm-openai
Copy link
Collaborator

I'm missing some context, what's the use case for this? I read the issue but couldn't quite figure it out

@gonzamordecki
Copy link

gonzamordecki commented Aug 1, 2025

@rm-openai Adding some context, as I just faced this limitation:

An agent currently cannot be run using built-in sessions from the SDK while receiving two new inputs from the user. This is requested, for example, when passing an image and text (i.e., Product Image + “Do you have this product in black?”).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request feature:sessions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

multiple inputs with session support
4 participants