Skip to content

Commit 4203be7

Browse files
authored
Merge pull request #17 from mmontan/performance-optimize-sessions-iterator-4640066907036728142
⚡ Optimize session listing by using iterators
2 parents 05a3f78 + c4058ca commit 4203be7

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/agent_engine_cli/main.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,7 @@ def list_sessions(
336336
"""List all sessions for an agent."""
337337
client = get_ready_client()
338338
try:
339-
sessions = list(client.list_sessions(agent_id))
340-
341-
if not sessions:
342-
console.print("No sessions found.")
343-
return
339+
sessions = client.list_sessions(agent_id)
344340

345341
table = Table(title="Sessions")
346342
table.add_column("Session ID", style="cyan")
@@ -349,7 +345,9 @@ def list_sessions(
349345
table.add_column("Created")
350346
table.add_column("Expires")
351347

348+
has_sessions = False
352349
for session in sessions:
350+
has_sessions = True
353351
session_id = get_id(session)
354352
display_name = getattr(session, "display_name", "") or ""
355353
user_id = getattr(session, "user_id", "") or ""
@@ -375,6 +373,10 @@ def list_sessions(
375373
expire_time,
376374
)
377375

376+
if not has_sessions:
377+
console.print("No sessions found.")
378+
return
379+
378380
console.print(table)
379381
except Exception as e:
380382
console.print(f"[red]Error listing sessions: {escape(str(e))}[/red]")

0 commit comments

Comments
 (0)