@@ -422,13 +422,24 @@ async fn plugin_send_message(
422422 ) ?;
423423 message. correlation_id = correlation_id. clone ( ) ;
424424 context. send_channel_message ( message) . await ?;
425+ let result = pending_remote_task_result ( & args. agent_id , & correlation_id, & remote. peer_id ) ;
426+ let mut cache = RemoteTaskCache :: load ( & state. data_dir ) ?;
427+ cache. upsert_pending (
428+ args. agent_id . clone ( ) ,
429+ remote. peer_id . clone ( ) ,
430+ correlation_id. clone ( ) ,
431+ result. clone ( ) ,
432+ ) ;
433+ cache. save ( & state. data_dir ) ?;
425434 Ok ( json ! ( {
426435 "agent_id" : args. agent_id,
427436 "location" : "remote" ,
428437 "peer_id" : remote. peer_id,
438+ "task_id" : correlation_id. clone( ) ,
429439 "correlation_id" : correlation_id,
430440 "status" : "submitted" ,
431- "note" : "remote task result will be available through agents.get_task after the owner node replies" ,
441+ "result" : result,
442+ "note" : "task_id is a followable pending task reference; agents.get_task will resolve it to the final A2A task after the owner node replies" ,
432443 } ) )
433444}
434445
@@ -449,6 +460,8 @@ async fn plugin_get_task(state: &PluginState, agent_id: &str, task_id: &str) ->
449460 "agent_id" : agent_id,
450461 "location" : "remote" ,
451462 "peer_id" : remote. peer_id,
463+ "task_id" : remote. task_id,
464+ "correlation_id" : remote. correlation_id,
452465 "task" : remote. result,
453466 } ) )
454467}
@@ -530,13 +543,32 @@ fn decode_task_value(value: Value) -> Result<Task> {
530543 serde_json:: from_value ( value) . context ( "failed to decode task" )
531544}
532545
546+ fn pending_remote_task_result ( agent_id : & str , correlation_id : & str , peer_id : & str ) -> Value {
547+ json ! ( {
548+ "task" : {
549+ "id" : correlation_id,
550+ "contextId" : correlation_id,
551+ "status" : {
552+ "state" : "TASK_STATE_SUBMITTED" ,
553+ } ,
554+ "metadata" : {
555+ "mesh_llm_pending_remote" : true ,
556+ "agent_id" : agent_id,
557+ "peer_id" : peer_id,
558+ "correlation_id" : correlation_id,
559+ } ,
560+ } ,
561+ } )
562+ }
563+
533564async fn send_remote_message_stream (
534565 state : & PluginState ,
535566 remote : & crate :: mesh:: RemoteAgentAd ,
536567 args : & SendMessageArgs ,
537568 context : & mut PluginContext < ' _ > ,
538569) -> Result < Value > {
539570 let stream_id = format ! ( "a2a-{}-{}" , args. agent_id, now_ms( ) ) ;
571+ let correlation_id = format ! ( "remote-{}" , now_ms( ) ) ;
540572 let metadata = MeshStreamRequest :: SendMessage {
541573 agent_id : args. agent_id . clone ( ) ,
542574 message : args. message . clone ( ) ,
@@ -552,7 +584,7 @@ async fn send_remote_message_stream(
552584 mode : mesh_llm_plugin:: proto:: StreamMode :: EventStream as i32 ,
553585 bidirectional : false ,
554586 content_type : Some ( "text/event-stream" . to_string ( ) ) ,
555- correlation_id : Some ( format ! ( "remote-{}" , now_ms ( ) ) ) ,
587+ correlation_id : Some ( correlation_id . clone ( ) ) ,
556588 metadata_json : Some ( serde_json:: to_string ( & metadata) ?) ,
557589 expected_bytes : None ,
558590 idle_timeout_ms : Some ( 300_000 ) ,
@@ -579,7 +611,7 @@ async fn send_remote_message_stream(
579611 agent_id : args. agent_id . clone ( ) ,
580612 task_id : task_id. clone ( ) ,
581613 peer_id : remote. peer_id . clone ( ) ,
582- correlation_id : String :: new ( ) ,
614+ correlation_id : correlation_id . clone ( ) ,
583615 result : final_result. clone ( ) ,
584616 updated_at_ms : now_ms ( ) ,
585617 } ) ;
@@ -592,6 +624,7 @@ async fn send_remote_message_stream(
592624 "peer_id" : remote. peer_id,
593625 "transport" : "mesh_stream" ,
594626 "task_id" : task_id,
627+ "correlation_id" : correlation_id,
595628 "result" : final_result,
596629 "events" : events,
597630 } ) )
0 commit comments