2020import typer
2121from rich .console import Console
2222import random
23+ import uuid
2324from agentkit .toolkit .config import get_config
2425import logging
2526
@@ -64,6 +65,7 @@ def build_a2a_payload(message: Optional[str], payload: Optional[str], headers: d
6465 "params" : {
6566 "message" : {
6667 "role" : "user" ,
68+ "messageId" : str (uuid .uuid4 ()),
6769 "parts" : [
6870 {"kind" : "text" , "text" : text }
6971 ]
@@ -117,15 +119,6 @@ def invoke_command(
117119 config = get_config (config_path = config_file )
118120 common_config = config .get_common_config ()
119121
120- final_payload = build_standard_payload (message , payload )
121- agent_type = getattr (common_config , "agent_type" , "" ) or getattr (common_config , "template_type" , "" )
122- is_a2a = isinstance (agent_type , str ) and "a2a" in agent_type .lower ()
123-
124- # If it's an A2A Agent, reconstruct payload using A2A constructor
125- if is_a2a :
126- console .print ("[cyan]Detected A2A agent type - constructing A2A JSON-RPC envelope[/cyan]" )
127- final_payload = build_a2a_payload (message , payload , final_headers )
128-
129122 # Process headers
130123 final_headers = {"user_id" : "agentkit_user" , "session_id" : "agentkit_sample_session" }
131124 if headers :
@@ -137,6 +130,16 @@ def invoke_command(
137130 raise typer .Exit (1 )
138131 else :
139132 console .print (f"[blue]Using default headers: { final_headers } [/blue]" )
133+
134+ final_payload = build_standard_payload (message , payload )
135+ agent_type = getattr (common_config , "agent_type" , "" ) or getattr (common_config , "template_type" , "" )
136+ is_a2a = isinstance (agent_type , str ) and "a2a" in agent_type .lower ()
137+
138+ # If it's an A2A Agent, reconstruct payload using A2A constructor
139+ if is_a2a :
140+ console .print ("[cyan]Detected A2A agent type - constructing A2A JSON-RPC envelope[/cyan]" )
141+ final_payload = build_a2a_payload (message , payload , final_headers )
142+
140143
141144 # Set execution context - CLI uses ConsoleReporter (with colored output and progress)
142145 from agentkit .toolkit .context import ExecutionContext
@@ -194,6 +197,10 @@ def invoke_command(
194197 parts = event ["message" ].get ("parts" , [])
195198 elif isinstance (event .get ("content" ), dict ):
196199 parts = event ["content" ].get ("parts" , [])
200+ elif isinstance (event .get ("status" ), dict ):
201+ role = event ["status" ].get ("message" , {}).get ("role" )
202+ if role == "agent" :
203+ parts = event ["status" ].get ("message" , {}).get ("parts" , [])
197204 if not event .get ("partial" , True ):
198205 logger .info ("Partial event: %s" , event ) # Log partial events
199206 continue
@@ -216,7 +223,6 @@ def invoke_command(
216223
217224 # Handle status updates (e.g., final flag or completed status)
218225 if event .get ("final" ) is True :
219- console .print ("\n [cyan]Stream marked final[/cyan]" )
220226 break
221227
222228 status = event .get ("status" )
0 commit comments