Agent.run()
, it creates a stateless, singular Agent run.
But what if we want to continue this run i.e. have a multi-turn conversation? That’s where sessions
come in. A session is collection of consecutive runs.
In practice, a session is a multi-turn conversation between a user and an Agent. Using a session_id
, we can connect the conversation history and state across multiple runs.
Let’s outline some key concepts:
session_id
and each turn is a run.run_id
and Agent.run()
creates a new run_id
when called.run_id
is automatically generated, as well as a session_id
(because we didn’t provide one to continue the conversation). This run is not yet associated with a user.
user_id
to connect a user to their sessions with the Agent.
In the example below, we set a session_id
to demo how to have multi-turn conversations with multiple users at the same time. In production, the session_id
is auto generated.
Memory.v2
, which will become the default memory implementation in the next release.search_previous_sessions_history
: Set this to True
to allow searching through previous sessions.num_history_sessions
: Specify the number of past sessions to include in the search. In this example, it is set to 2
to include only the last 2 sessions.
It’s advisable to keep this number to 2 or 3 for now, as a larger number might fill up the context length of the model, potentially leading to performance issues.