Skip to content

Commit 53807f2

Browse files
gabrycinaclaude
andcommitted
feat: add get_current_state workflow query to BaseWorkflow
Adds a default @workflow.query handler named "get_current_state" to BaseWorkflow. Automatically returns the state machine's current state if self.state_machine exists (covers all StateMachine-based agents without any override needed). Falls back to _workflow_state string for non-state-machine agents. Enables external callers to detect turn completion: "waiting_for_input" = agent is done, ready for next message "researching" = agent is still working Companion to scaleapi/scale-agentex#173 which adds GET /tasks/{task_id}/query/{query_name} endpoint. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent aa3aaa1 commit 53807f2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/agentex/lib/core/temporal/workflows/workflow.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ def __init__(
1515
display_name: str,
1616
):
1717
self.display_name = display_name
18+
self._workflow_state: str = "initialized"
19+
20+
@workflow.query(name="get_current_state")
21+
def get_current_state(self) -> str:
22+
"""Query handler for the current workflow state.
23+
24+
If the workflow uses a StateMachine (self.state_machine),
25+
returns the state machine's current state automatically.
26+
Otherwise returns the fallback _workflow_state string.
27+
28+
This enables external callers to detect when the agent has
29+
finished processing a turn (state == "waiting_for_input").
30+
"""
31+
if hasattr(self, "state_machine") and self.state_machine is not None:
32+
return self.state_machine.get_current_state()
33+
return self._workflow_state
1834

1935
@abstractmethod
2036
@workflow.signal(name=SignalName.RECEIVE_EVENT)

0 commit comments

Comments
 (0)