@@ -33,13 +33,28 @@ def list_agents(org_id: int | None = typer.Option(None, help="Organization ID (d
3333 raise typer .Exit (1 )
3434
3535 # Make API request to list agent runs with spinner
36- spinner = create_spinner ("Fetching agent runs..." )
36+ spinner = create_spinner ("Fetching your recent API agent runs..." )
3737 spinner .start ()
3838
3939 try :
4040 headers = {"Authorization" : f"Bearer { token } " }
41+ # Filter to only API source type and current user's agent runs
42+ params = {
43+ "source_type" : "API" ,
44+ # We'll get the user_id from the /users/me endpoint
45+ }
46+
47+ # First get the current user ID
48+ user_response = requests .get (f"{ API_ENDPOINT .rstrip ('/' )} /v1/users/me" , headers = headers )
49+ user_response .raise_for_status ()
50+ user_data = user_response .json ()
51+ user_id = user_data .get ("id" )
52+
53+ if user_id :
54+ params ["user_id" ] = user_id
55+
4156 url = f"{ API_ENDPOINT .rstrip ('/' )} /v1/organizations/{ resolved_org_id } /agent/runs"
42- response = requests .get (url , headers = headers )
57+ response = requests .get (url , headers = headers , params = params )
4358 response .raise_for_status ()
4459 response_data = response .json ()
4560 finally :
@@ -52,42 +67,58 @@ def list_agents(org_id: int | None = typer.Option(None, help="Organization ID (d
5267 page_size = response_data .get ("page_size" , 10 )
5368
5469 if not agent_runs :
55- console .print ("[yellow]No agent runs found.[/yellow]" )
70+ console .print ("[yellow]No API agent runs found for your user .[/yellow]" )
5671 return
5772
5873 # Create a table to display agent runs
5974 table = Table (
60- title = f"Agent Runs (Page { page } , Total: { total } )" ,
75+ title = f"Your Recent API Agent Runs (Page { page } , Total: { total } )" ,
6176 border_style = "blue" ,
6277 show_header = True ,
6378 title_justify = "center" ,
6479 )
65- table .add_column ("ID" , style = "cyan" , no_wrap = True )
66- table .add_column ("Status" , style = "white" , justify = "center" )
67- table .add_column ("Source" , style = "magenta" )
6880 table .add_column ("Created" , style = "dim" )
69- table .add_column ("Result" , style = "green" )
81+ table .add_column ("Status" , style = "white" , justify = "center" )
82+ table .add_column ("Summary" , style = "green" )
83+ table .add_column ("Link" , style = "blue" )
7084
7185 # Add agent runs to table
7286 for agent_run in agent_runs :
7387 run_id = str (agent_run .get ("id" , "Unknown" ))
7488 status = agent_run .get ("status" , "Unknown" )
7589 source_type = agent_run .get ("source_type" , "Unknown" )
7690 created_at = agent_run .get ("created_at" , "Unknown" )
77- result = agent_run .get ("result" , "" )
7891
79- # Status with emoji
80- status_display = status
92+ # Extract summary from task_timeline_json, similar to frontend
93+ timeline = agent_run .get ("task_timeline_json" )
94+ summary = None
95+ if timeline and isinstance (timeline , dict ) and "summary" in timeline :
96+ if isinstance (timeline ["summary" ], str ):
97+ summary = timeline ["summary" ]
98+
99+ # Fall back to goal_prompt if no summary
100+ if not summary :
101+ summary = agent_run .get ("goal_prompt" , "" )
102+
103+ # Status with colored circles
81104 if status == "COMPLETE" :
82- status_display = "✅ Complete"
105+ status_display = "[green]●[/green] Complete"
106+ elif status == "ACTIVE" :
107+ status_display = "[dim]●[/dim] Active"
83108 elif status == "RUNNING" :
84- status_display = "🏃 Running"
109+ status_display = "[dim]●[/dim] Running"
110+ elif status == "CANCELLED" :
111+ status_display = "[yellow]●[/yellow] Cancelled"
112+ elif status == "ERROR" :
113+ status_display = "[red]●[/red] Error"
85114 elif status == "FAILED" :
86- status_display = "❌ Failed"
115+ status_display = "[red]●[/red] Failed"
87116 elif status == "STOPPED" :
88- status_display = "⏹️ Stopped"
117+ status_display = "[yellow]●[/yellow] Stopped"
89118 elif status == "PENDING" :
90- status_display = "⏳ Pending"
119+ status_display = "[dim]●[/dim] Pending"
120+ else :
121+ status_display = "[dim]●[/dim] " + status
91122
92123 # Format created date (just show date and time, not full timestamp)
93124 if created_at and created_at != "Unknown" :
@@ -102,13 +133,20 @@ def list_agents(org_id: int | None = typer.Option(None, help="Organization ID (d
102133 else :
103134 created_display = created_at
104135
105- # Truncate result if too long
106- result_display = result [:50 ] + "..." if result and len (result ) > 50 else result or "No result"
136+ # Truncate summary if too long
137+ summary_display = summary [:50 ] + "..." if summary and len (summary ) > 50 else summary or "No summary"
138+
139+ # Create web link for the agent run
140+ web_url = agent_run .get ("web_url" )
141+ if not web_url :
142+ # Construct URL if not provided
143+ web_url = f"https://codegen.com/traces/{ run_id } "
144+ link_display = web_url
107145
108- table .add_row (run_id , status_display , source_type , created_display , result_display )
146+ table .add_row (created_display , status_display , summary_display , link_display )
109147
110148 console .print (table )
111- console .print (f"\n [green]Showing { len (agent_runs )} of { total } agent runs[/green]" )
149+ console .print (f"\n [green]Showing { len (agent_runs )} of { total } API agent runs[/green]" )
112150
113151 except requests .RequestException as e :
114152 console .print (f"[red]Error fetching agent runs:[/red] { e } " , style = "bold red" )
0 commit comments