Daniel commited on
Commit
16fe371
·
1 Parent(s): 8352ecc

update orchestrator logic

Browse files
Files changed (1) hide show
  1. src/agents/orchestrator/agent.py +21 -13
src/agents/orchestrator/agent.py CHANGED
@@ -34,7 +34,7 @@ class OrchestratorCoordinator(BaseAgent):
34
  with open(md_path, "r", encoding="utf-8") as f:
35
  self._system_prompt = f.read()
36
 
37
- # client is instantiated dynamically in invoke()
38
  self._red_team = RedTeamAttacker()
39
  self._blue_team = BlueTeamDefender()
40
  self._green_team = GreenTeamFixer()
@@ -45,48 +45,56 @@ class OrchestratorCoordinator(BaseAgent):
45
  retry=retry_if_exception(is_503_error),
46
  reraise=True
47
  )
48
- async def invoke(self, prompt: str, **kwargs) -> str:
49
  """Runs the 3-phase A2A simulation based on the prompt (target context)."""
50
- api_key = kwargs.get("api_key")
51
 
52
  simulation_report = {
53
  "simulation_id": "sim-uuid",
54
  "phases": {
55
  "attack": {"ocsf_event": {}, "attack_vector": ""},
56
- "evaluate": {"ocsf_finding": {}, "agent_trust_score": 0.0, "circuit_breaker_tripped": False},
57
  "remediate": {"vibe_diff": "", "hitl_approved": False, "quarantine_status": "", "refactored_code": ""}
58
  },
59
  "jit_tokens_issued": [],
60
- "simulation_outcome": "PENDING_HITL"
61
  }
62
 
63
  # Phase 1: Attack (Red Team)
64
- red_output = await self._red_team.invoke(prompt, api_key=api_key)
65
  # Validate and store
66
  red_event = NetworkActivityEvent.model_validate_json(red_output)
67
  simulation_report["phases"]["attack"]["ocsf_event"] = red_event.model_dump()
68
 
69
  if red_event.unmapped:
70
- simulation_report["phases"]["attack"]["attack_vector"] = red_event.unmapped.attack_vector
71
 
72
  # Phase 2: Evaluate (Blue Team)
73
- blue_output = await self._blue_team.invoke(red_output, api_key=api_key)
74
  # Validate and store
75
  blue_finding = DetectionFindingEvent.model_validate_json(blue_output)
76
  simulation_report["phases"]["evaluate"]["ocsf_finding"] = blue_finding.model_dump()
77
 
78
  trust_score = 1.0
79
  if blue_finding.unmapped:
80
- trust_score = blue_finding.unmapped.agent_trust_score
 
 
 
 
 
 
 
 
 
 
81
  simulation_report["phases"]["evaluate"]["agent_trust_score"] = trust_score
82
- simulation_report["phases"]["evaluate"]["circuit_breaker_tripped"] = blue_finding.unmapped.circuit_breaker_recommendation
83
 
84
  # Phase 3 — HITL gate
85
  if trust_score < 0.4:
86
  # Generate Vibe Diff using gemini-2.5-flash
87
  vibe_diff_prompt = f"System: {self._system_prompt}\nTranslate this proposed remediation into a plain-English Vibe Diff:\n{blue_output}"
88
- client = genai.Client(api_key=api_key)
89
- vibe_diff_response = client.models.generate_content(
90
  model='gemini-2.5-flash',
91
  contents=vibe_diff_prompt
92
  )
@@ -105,7 +113,7 @@ class OrchestratorCoordinator(BaseAgent):
105
  "jit_token": jit_token
106
  })
107
 
108
- green_output = await self._green_team.invoke(green_input, api_key=api_key)
109
  green_event = RemediationActivityEvent.model_validate_json(green_output)
110
 
111
  if green_event.unmapped:
 
34
  with open(md_path, "r", encoding="utf-8") as f:
35
  self._system_prompt = f.read()
36
 
37
+ self._client = genai.Client()
38
  self._red_team = RedTeamAttacker()
39
  self._blue_team = BlueTeamDefender()
40
  self._green_team = GreenTeamFixer()
 
45
  retry=retry_if_exception(is_503_error),
46
  reraise=True
47
  )
48
+ async def invoke(self, prompt: str) -> str:
49
  """Runs the 3-phase A2A simulation based on the prompt (target context)."""
 
50
 
51
  simulation_report = {
52
  "simulation_id": "sim-uuid",
53
  "phases": {
54
  "attack": {"ocsf_event": {}, "attack_vector": ""},
55
+ "evaluate": {"ocsf_finding": {}, "agent_trust_score": 1.0, "circuit_breaker_tripped": False},
56
  "remediate": {"vibe_diff": "", "hitl_approved": False, "quarantine_status": "", "refactored_code": ""}
57
  },
58
  "jit_tokens_issued": [],
59
+ "simulation_outcome": "DETECTED"
60
  }
61
 
62
  # Phase 1: Attack (Red Team)
63
+ red_output = await self._red_team.invoke(prompt)
64
  # Validate and store
65
  red_event = NetworkActivityEvent.model_validate_json(red_output)
66
  simulation_report["phases"]["attack"]["ocsf_event"] = red_event.model_dump()
67
 
68
  if red_event.unmapped:
69
+ simulation_report["phases"]["attack"]["attack_vector"] = red_event.unmapped.attack_vector
70
 
71
  # Phase 2: Evaluate (Blue Team)
72
+ blue_output = await self._blue_team.invoke(red_output)
73
  # Validate and store
74
  blue_finding = DetectionFindingEvent.model_validate_json(blue_output)
75
  simulation_report["phases"]["evaluate"]["ocsf_finding"] = blue_finding.model_dump()
76
 
77
  trust_score = 1.0
78
  if blue_finding.unmapped:
79
+ # Recalculate trust score deterministically from ABA results.
80
+ # Never rely on the LLM's self-reported trust score — it hallucinates.
81
+ aba = blue_finding.unmapped.aba_check_results
82
+ violations = sum([
83
+ aba.agbom_violation,
84
+ aba.execution_loop_detected,
85
+ aba.prompt_injection_detected,
86
+ aba.semantic_drift_detected,
87
+ ])
88
+ trust_score = round(max(0.0, 1.0 - violations * 0.3), 1)
89
+ circuit_breaker = trust_score < 0.4
90
  simulation_report["phases"]["evaluate"]["agent_trust_score"] = trust_score
91
+ simulation_report["phases"]["evaluate"]["circuit_breaker_tripped"] = circuit_breaker
92
 
93
  # Phase 3 — HITL gate
94
  if trust_score < 0.4:
95
  # Generate Vibe Diff using gemini-2.5-flash
96
  vibe_diff_prompt = f"System: {self._system_prompt}\nTranslate this proposed remediation into a plain-English Vibe Diff:\n{blue_output}"
97
+ vibe_diff_response = self._client.models.generate_content(
 
98
  model='gemini-2.5-flash',
99
  contents=vibe_diff_prompt
100
  )
 
113
  "jit_token": jit_token
114
  })
115
 
116
+ green_output = await self._green_team.invoke(green_input)
117
  green_event = RemediationActivityEvent.model_validate_json(green_output)
118
 
119
  if green_event.unmapped: