@@ -440,9 +440,9 @@ Monitor your agent's real-time activities using the unified event subscription:
440440
441441``` graphql 
442442subscription  {
443-   agentEvents (agentId : " agent_neo_001" 
444-     type 
445-     payload 
443+   agentEvent (agentId : " agent_neo_001" 
444+     name 
445+     data 
446446    timestamp 
447447  }
448448}
@@ -453,9 +453,9 @@ Your agent streams various types of operational events:
453453``` json 
454454{
455455  "data" : {
456-     "agentEvents " : {
457-       "type " : " mission_started" 
458-       "payload " : {
456+     "agentEvent " : {
457+       "name " : " mission_started" 
458+       "data " : {
459459        "missionName" : " Deep Matrix Surveillance" 
460460        "priority" : " HIGH" 
461461        "estimatedDuration" : " 180s" 
@@ -469,9 +469,9 @@ Your agent streams various types of operational events:
469469``` json 
470470{
471471  "data" : {
472-     "agentEvents " : {
473-       "type " : " agent_threat_detected" 
474-       "payload " : {
472+     "agentEvent " : {
473+       "name " : " agent_threat_detected" 
474+       "data " : {
475475        "threatLevel" : " CRITICAL" 
476476        "confidence" : 0.92 ,
477477        "indicators" : [" agent_smith_replication" " unusual_code_patterns" 
@@ -486,9 +486,9 @@ Your agent streams various types of operational events:
486486``` json 
487487{
488488  "data" : {
489-     "agentEvents " : {
490-       "type " : " surveillance_progress" 
491-       "payload " : {
489+     "agentEvent " : {
490+       "name " : " surveillance_progress" 
491+       "data " : {
492492        "phase" : " Processing Matrix surveillance data" 
493493        "progress" : 0.65 ,
494494        "reportsProcessed" : 5 ,
@@ -500,31 +500,47 @@ Your agent streams various types of operational events:
500500}
501501``` 
502502
503- ### Emitting  events from your agent 
503+ ### Publishing  events from your agent 
504504
505- Agents can broadcast real-time operational intelligence by emitting  events
506- during their operations. Let's enhance our Matrix surveillance example :
505+ Agents can broadcast real-time operational intelligence by publishing  events
506+ during their operations. Use the  ` PublishEvent `  method to emit custom events :
507507
508508``` go 
509+ //  Custom event types implement the AgentEvent interface
510+ type  ThreatDetected  struct  {
511+     ThreatLevel  string  ` json:"threatLevel"` 
512+     Confidence   float64  ` json:"confidence"` 
513+     Analysis     string  ` json:"analysis"` 
514+ }
515+ 
516+ func  (e  ThreatDetected ) EventName  () string  {
517+     return  " threat_detected" 
518+ }
519+ 
520+ //  Other event types can be defined similarly...
521+ 
509522func  (a  *IntelligenceAgent ) analyzeMatrixActivity (
510523    data string,
511524) (*string, error) {
512525    //  Emit mission start event
513-     a. EmitEvent ( " mission_started " , any {
514-         " missionName " " Matrix Surveillance Analysis" 
515-         " priority " " HIGH" 
516-         " activityData " len (*data),
526+     err   :=  a. PublishEvent (MissionStarted {
527+         MissionName : " Matrix Surveillance Analysis" 
528+         Priority : " HIGH" 
529+         ActivityData : len (*data),
517530    })
531+     if  err != nil  {
532+         return  nil , err
533+     }
518534
519535    //  Store new intelligence in persistent memory
520536    a.intelligenceReports  = append (a.intelligenceReports , *data)
521537    a.lastContact  = time.Now ()
522538
523539    //  Emit progress update
524-     a.EmitEvent ( " surveillance_progress " , any {
525-         " reportsProcessed " len (a.intelligenceReports ),
526-         " phase " " Processing Matrix surveillance data" 
527-         " progress " 0.3 ,
540+     a.PublishEvent (SurveillanceProgress {
541+         ReportsProcessed : len (a.intelligenceReports ),
542+         Phase : " Processing Matrix surveillance data" 
543+         Progress : 0.3 ,
528544    })
529545
530546    //  Build context from all accumulated intelligence
@@ -555,10 +571,10 @@ func (a *IntelligenceAgent) analyzeMatrixActivity(
555571    }
556572
557573    //  Emit AI processing event
558-     a.EmitEvent ( " ai_analysis_started " , any {
559-         " modelName " " analyst-model" 
560-         " contextSize " len (accumulatedReports),
561-         " reportCount " len (a.intelligenceReports ),
574+     a.PublishEvent (AIAnalysisStarted {
575+         ModelName : " analyst-model" 
576+         ContextSize : len (accumulatedReports),
577+         ReportCount : len (a.intelligenceReports ),
562578    })
563579
564580    output , err  :=  model.Invoke (input)
@@ -577,20 +593,19 @@ func (a *IntelligenceAgent) analyzeMatrixActivity(
577593    if  strings.Contains (strings.ToLower (analysis), " critical" 
578594       strings.Contains (strings.ToLower (analysis), " agent smith" 
579595        a.threatLevel  = math.Min (a.threatLevel  + 0.2 , 1.0 )
580-         a.EmitEvent (" agent_threat_detected" 
581-             " threatLevel" " HIGH" 
582-             " confidence" threatLevel ,
583-             " analysis" 
584-             " recommendation" " immediate_extraction" 
596+         a.PublishEvent (ThreatDetected{
597+             ThreatLevel: " HIGH" 
598+             Confidence: a.threatLevel ,
599+             Analysis: analysis,
585600        })
586601    }
587602
588603    //  Emit mission completion
589-     a.EmitEvent ( " mission_completed " , any {
590-         " missionName " " Matrix Surveillance Analysis" 
591-         " confidence " threatLevel ,
592-         " reportsAnalyzed " len (a.intelligenceReports ),
593-         " status " " SUCCESS" 
604+     a.PublishEvent (MissionCompleted {
605+         MissionName : " Matrix Surveillance Analysis" 
606+         Confidence : a.threatLevel ,
607+         ReportsAnalyzed : len (a.intelligenceReports ),
608+         Status : " SUCCESS" 
594609    })
595610
596611    result  :=  fmt.Sprintf (` Matrix surveillance complete:
@@ -622,6 +637,27 @@ analysis.
622637** Progressive Enhancement** : update user interfaces progressively as agents work
623638through complex, multi-phase operations without polling or manual refresh.
624639
640+ ### Subscription protocol  
641+ 
642+ Modus uses GraphQL subscriptions over Server-Sent Events (SSE) following the
643+ [ GraphQL-SSE specification] ( https://the-guild.dev/graphql/sse ) . To consume these
644+ subscriptions:
645+ 
646+ 1 .  ** From a web browser** : Use the EventSource API or a GraphQL client that
647+    supports SSE subscriptions
648+ 2 .  ** From Postman** : Set Accept header to ` text/event-stream `  and make a POST
649+    request
650+ 3 .  ** From curl** : Use ` -N `  flag and appropriate headers for streaming
651+ 
652+ Example with curl:
653+ 
654+ ``` bash 
655+ curl -N -H " accept: text/event-stream" 
656+      -H " content-type: application/json" 
657+      -X POST http://localhost:8080/graphql \
658+      -d ' {"query":"subscription { agentEvent(agentId: \"agent_neo_001\") { name data timestamp } }"}' 
659+ ``` 
660+ 
625661## Monitoring ongoing operations  
626662
627663You can also poll agent status directly through dedicated functions:
@@ -706,9 +742,9 @@ query MonitorMission($agentId: String!) {
706742
707743# Real-time streaming approach (recommended) 
708744subscription  LiveAgentMonitoring ($agentId : String ! ) {
709-   agentEvents (agentId : $agentId ) {
710-     type 
711-     payload 
745+   agentEvent (agentId : $agentId ) {
746+     name 
747+     data 
712748    timestamp 
713749  }
714750}
0 commit comments