|
13 | 13 |
|
14 | 14 | class DurableAIAgentContext: |
15 | 15 | def __init__(self, context: DurableOrchestrationContext): |
16 | | - self.context = context |
17 | | - self.activities_called = 0 |
18 | | - self.tasks_to_yield = [] |
| 16 | + self._context = context |
| 17 | + self._activities_called = 0 |
| 18 | + self._tasks_to_yield = [] |
19 | 19 |
|
20 | 20 | def get_activity_call_result(self, activity_name, input: str): |
21 | | - task = self.context.call_activity(activity_name, input) |
| 21 | + task = self._context.call_activity(activity_name, input) |
22 | 22 |
|
23 | | - self.activities_called += 1 |
| 23 | + self._activities_called += 1 |
24 | 24 |
|
25 | | - histories = self.context.histories |
| 25 | + histories = self._context.histories |
26 | 26 | completed_tasks = [entry for entry in histories if entry.event_type == 5] |
27 | | - if len(completed_tasks) < self.activities_called: |
| 27 | + if len(completed_tasks) < self._activities_called: |
28 | 28 | # yield immediately |
29 | 29 | raise YieldException(task) |
30 | 30 | else: |
31 | 31 | # yield later |
32 | | - self.tasks_to_yield.append(task) |
| 32 | + self._tasks_to_yield.append(task) |
33 | 33 |
|
34 | | - result_json = completed_tasks[self.activities_called - 1].Result |
| 34 | + result_json = completed_tasks[self._activities_called - 1].Result |
35 | 35 | result = json.loads(result_json) |
36 | 36 | return result |
37 | 37 |
|
38 | 38 | def call_activity(self, activity_name, input: str): |
39 | | - task = self.context.call_activity(activity_name, input) |
40 | | - self.activities_called += 1 |
| 39 | + task = self._context.call_activity(activity_name, input) |
| 40 | + self._activities_called += 1 |
41 | 41 | return task |
42 | 42 |
|
43 | 43 | def set_custom_status(self, status: str): |
44 | | - self.context.set_custom_status(status) |
| 44 | + self._context.set_custom_status(status) |
45 | 45 |
|
46 | 46 | def wait_for_external_event(self, event_name: str): |
47 | | - return self.context.wait_for_external_event(event_name) |
| 47 | + return self._context.wait_for_external_event(event_name) |
48 | 48 |
|
49 | 49 | def yield_and_clear_tasks(self): |
50 | 50 | """Yield all accumulated tasks and clear the tasks list.""" |
51 | | - for task in self.tasks_to_yield: |
| 51 | + for task in self._tasks_to_yield: |
52 | 52 | yield task |
53 | | - self.tasks_to_yield.clear() |
| 53 | + self._tasks_to_yield.clear() |
54 | 54 |
|
55 | 55 | def activity_as_tool( |
56 | 56 | self, |
|
0 commit comments