Open-source AI penetration testing tool to find and fix your app’s vulnerabilities.
Python agentsai-hackingai-penetration-testingai-pentestingai-securityartificial-intelligencebug-bountycode-qualityctf-toolscybersecuritycybersecurity-toolsethical-hackinghackingllm-securityoffensive-securitypenetration-testingpentesting-toolsred-teamingsecuritysecurity-automation
perf(agent): wake on state change instead of 500ms polling (#305)
Balae1f38f8339c5
diff --git a/strix/agents/base_agent.py b/strix/agents/base_agent.pyindex c759f9a9..9ff16dfe 100644--- a/strix/agents/base_agent.py+++ b/strix/agents/base_agent.py@@ -282,7 +282,7 @@ class BaseAgent(metaclass=AgentMeta):return- await asyncio.sleep(0.5)+ await self.state.wait_for_wake(timeout=0.5)async def _enter_waiting_state(self,diff --git a/strix/agents/state.py b/strix/agents/state.pyindex da04ee7f..09b1c910 100644--- a/strix/agents/state.py+++ b/strix/agents/state.py@@ -1,8 +1,9 @@+import asyncioimport uuidfrom datetime import UTC, datetimefrom typing import Any-from pydantic import BaseModel, Field+from pydantic import BaseModel, Field, PrivateAttrdef _generate_agent_id() -> str:@@ -40,6 +41,8 @@ class AgentState(BaseModel):errors: list[str] = Field(default_factory=list)+ _wake_event: asyncio.Event = PrivateAttr(default_factory=asyncio.Event)+def increment_iteration(self) -> None:self.iteration += 1self.last_updated = datetime.now(UTC).isoformat()@@ -52,6 +55,8 @@ class AgentState(BaseModel):message["thinking_blocks"] = thinking_blocksself.messages.append(message)self.last_updated = datetime.now(UTC).isoformat()+ if self.waiting_for_input:+ self._wake_event.set()def add_action(self, action: dict[str, Any]) -> None:self.actions_taken.append(@@ -109,6 +114,14 @@ class AgentState(BaseModel):if new_task:self.task = new_taskself.last_updated = datetime.now(UTC).isoformat()+ self._wake_event.set()++ async def wait_for_wake(self, timeout: float = 0.5) -> None:+ try:+ await asyncio.wait_for(self._wake_event.wait(), timeout=timeout)+ self._wake_event.clear()+ except TimeoutError:+ passdef has_reached_max_iterations(self) -> bool:return self.iteration >= self.max_iterations