Skip to content

Commit 01391e0

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. Returns "unknown" by default — agents override to report their actual state. Example for StateMachine-based agents: @workflow.query(name="get_current_state") def get_current_state(self) -> str: return self.state_machine.get_current_state() 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 01391e0

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
@@ -16,6 +16,22 @@ def __init__(
1616
):
1717
self.display_name = display_name
1818

19+
@workflow.query(name="get_current_state")
20+
def get_current_state(self) -> str:
21+
"""Query handler for the current workflow state.
22+
23+
Returns "unknown" by default. Subclasses should override this
24+
to return their actual state, enabling external callers to
25+
detect turn completion.
26+
27+
Example override for StateMachine-based agents:
28+
29+
@workflow.query(name="get_current_state")
30+
def get_current_state(self) -> str:
31+
return self.state_machine.get_current_state()
32+
"""
33+
return "unknown"
34+
1935
@abstractmethod
2036
@workflow.signal(name=SignalName.RECEIVE_EVENT)
2137
async def on_task_event_send(self, params: SendEventParams) -> None:

0 commit comments

Comments
 (0)