10000 feat: Add --session_id option to `adk run`: · aphraz/adk-python@a61d20e · GitHub
[go: up one dir, main page]

Skip to content

Commit a61d20e

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Add --session_id option to adk run:
--session_id : The session ID to save the session to on exit when --save_session is set to true. User will be prompted to enter a session ID if not set. PiperOrigin-RevId: 756335619
1 parent 41564de commit a61d20e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/google/adk/cli/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ async def run_cli(
105105
input_file: Optional[str] = None,
106106
saved_session_file: Optional[str] = None,
107107
save_session: bool,
108+
session_id: Optional[str] = None,
108109
) -> None:
109110
"""Runs an interactive CLI for a certain agent.
110111
@@ -118,6 +119,7 @@ async def run_cli(
118119
saved_session_file: Optional[str], the absolute path to the json file that
119120
contains a previously saved session, exclusive with input_file.
120121
save_session: bool, whether to save the session on exit.
122+
session_id: Optional[str], the session ID to save the session to on exit.
121123
"""
122124
if agent_parent_dir not in sys.path:
123125
sys.path.append(agent_parent_dir)
@@ -175,7 +177,7 @@ async def run_cli(
175177
)
176178

177179
if save_session:
178-
session_id = input('Session ID to save: ')
180+
session_id = session_id or input('Session ID to save: ')
179181
session_path = f'{agent_module_path}/{session_id}.session.json'
180182

181183
# Fetch the session again to get all the details.

src/google/adk/cli/cli_tools_click.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ def validate_exclusive(ctx, param, value):
122122
default=False,
123123
help="Optional. Whether to save the session to a json file on exit.",
124124
)
125+
@click.option(
126+
"--session_id",
127+
type=str,
128+
help=(
129+
"Optional. The session ID to save the session to on exit when"
130+
" --save_session is set to true. User will be prompted to enter a"
131+
" session ID if not set."
132+
),
133+
)
125134
@click.option(
126135
"--replay",
127136
type=click.Path(
@@ -156,6 +165,7 @@ def validate_exclusive(ctx, param, value):
156165
def cli_run(
157166
agent: str,
158167
save_session: bool,
168+
session_id: Optional[str],
159169
replay: Optional[str],
160170
resume: Optional[str],
161171
):
@@ -179,6 +189,7 @@ def cli_run(
179189
input_file=replay,
180190
saved_session_file=resume,
181191
save_session=save_session,
192+
session_id=session_id,
182193
)
183194
)
184195

0 commit comments

Comments
 (0)
0