Skip to content

Commit 0c7f813

Browse files
committed
fixing code style
1 parent e459286 commit 0c7f813

1 file changed

Lines changed: 34 additions & 55 deletions

File tree

src/flowcept/flowceptor/adapters/code_assistants/codex/codex_interceptor.py

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -326,29 +326,17 @@ def _normalize_declared_event(event: JsonObject) -> JsonObject | None:
326326
event_class = DPL_CLASS_ALIASES.get(class_key, raw_class)
327327
event_name = event.get("event")
328328
if event_class in DPL_MESSAGE_CLASSES:
329-
normalized = {
330-
key: value
331-
for key, value in event.items()
332-
if key not in {"layer", "class", "event"}
333-
}
329+
normalized = {key: value for key, value in event.items() if key not in {"layer", "class", "event"}}
334330
normalized["type"] = DPL_CLASS_TO_MESSAGE_TYPE[event_class]
335331
normalized["classification_source"] = "declared"
336332
return normalized
337333
if event_class in DPL_ENTITY_CLASSES:
338-
normalized = {
339-
key: value
340-
for key, value in event.items()
341-
if key not in {"layer", "class", "event"}
342-
}
334+
normalized = {key: value for key, value in event.items() if key not in {"layer", "class", "event"}}
343335
normalized["type"] = DPL_CLASS_TO_ENTITY_TYPE[event_class]
344336
normalized["classification_source"] = "declared"
345337
return normalized
346338
if event_class in DPL_TASK_CLASSES and event_name in {"started", "finished"}:
347-
normalized = {
348-
key: value
349-
for key, value in event.items()
350-
if key not in {"layer", "class", "event"}
351-
}
339+
normalized = {key: value for key, value in event.items() if key not in {"layer", "class", "event"}}
352340
normalized["type"] = f"{DPL_CLASS_TO_TASK_PREFIX[event_class]}_{event_name}"
353341
normalized["classification_source"] = "declared"
354342
return normalized
@@ -1012,11 +1000,7 @@ def _start_tagged_task(
10121000
if started_at is not None and subtype == PROV_AGENT_LOOP.PLAN_STEP_EXECUTION.value:
10131001
started_at -= 0.002
10141002
parent_task_id = self._parent_for_tagged_task(subtype)
1015-
if (
1016-
started_at is not None
1017-
and subtype == PROV_AGENT_LOOP.EVALUATION.value
1018-
and parent_task_id is not None
1019-
):
1003+
if started_at is not None and subtype == PROV_AGENT_LOOP.EVALUATION.value and parent_task_id is not None:
10201004
parent = self._active_tagged_task(PROV_AGENT_LOOP.LOOP_ITERATION.value)
10211005
if parent and parent.task_id == parent_task_id and parent.started_at is not None:
10221006
started_at = max(started_at, parent.started_at + 0.001)
@@ -1326,9 +1310,7 @@ def _apply_model_metadata(self, invocation: ModelInvocationState, turn: TurnStat
13261310
)
13271311
)
13281312

1329-
def _normalize_llm_usage(
1330-
self, usage: JsonObject, invocation: ModelInvocationState, info: JsonObject
1331-
) -> JsonObject:
1313+
def _normalize_llm_usage(self, usage: JsonObject, invocation: ModelInvocationState, info: JsonObject) -> JsonObject:
13321314
return _compact_dict(
13331315
{
13341316
"model": invocation.ai_model.get("model"),
@@ -1374,10 +1356,7 @@ def _emit_turn(self, turn: TurnState):
13741356
task.submitted_at = turn.submitted_at
13751357
task.started_at = turn.metadata.get("declared_loop_started_at") or turn.started_at
13761358
child_ended_at = [
1377-
ended_at
1378-
for invocation in turn.invocations
1379-
for ended_at in [invocation.ended_at]
1380-
if ended_at is not None
1359+
ended_at for invocation in turn.invocations for ended_at in [invocation.ended_at] if ended_at is not None
13811360
]
13821361
task.ended_at = turn.metadata.get("declared_loop_finished_at") or max(
13831362
[ended_at for ended_at in [turn.ended_at, *child_ended_at] if ended_at is not None],
@@ -1793,11 +1772,7 @@ def _parent_for_observed_task(
17931772
if loop and loop.workflow_id == workflow_id:
17941773
return loop.task_id
17951774
turn = self._current_turn()
1796-
if (
1797-
turn
1798-
and workflow_id
1799-
and turn.metadata.get("last_loop_iteration_workflow_id") == workflow_id
1800-
):
1775+
if turn and workflow_id and turn.metadata.get("last_loop_iteration_workflow_id") == workflow_id:
18011776
last_loop_id = turn.metadata.get("last_loop_iteration_id")
18021777
if last_loop_id:
18031778
return last_loop_id
@@ -2180,14 +2155,18 @@ def _tagged_task_generated_messages(
21802155
return []
21812156
content = event.get("summary") or event.get("result") or event.get("content")
21822157
message_type = "message"
2183-
return [
2184-
_entity(
2185-
message_type,
2186-
content=content,
2187-
attributed_to=invocation.agent_id,
2188-
status=event.get("status"),
2189-
)
2190-
] if content else []
2158+
return (
2159+
[
2160+
_entity(
2161+
message_type,
2162+
content=content,
2163+
attributed_to=invocation.agent_id,
2164+
status=event.get("status"),
2165+
)
2166+
]
2167+
if content
2168+
else []
2169+
)
21912170

21922171
def _tagged_task_generated_entities(
21932172
self,
@@ -2197,16 +2176,20 @@ def _tagged_task_generated_entities(
21972176
) -> list[JsonObject]:
21982177
content = event.get("result") or event.get("summary") or event.get("content")
21992178
if subtype == PROV_AGENT_LOOP.EVALUATION.value:
2200-
return [
2201-
_entity(
2202-
"evaluation_result",
2203-
content=content,
2204-
status=event.get("status"),
2205-
decision=event.get("decision"),
2206-
reason=event.get("reason"),
2207-
attributed_to=invocation.agent_id,
2208-
)
2209-
] if content or event.get("status") else []
2179+
return (
2180+
[
2181+
_entity(
2182+
"evaluation_result",
2183+
content=content,
2184+
status=event.get("status"),
2185+
decision=event.get("decision"),
2186+
reason=event.get("reason"),
2187+
attributed_to=invocation.agent_id,
2188+
)
2189+
]
2190+
if content or event.get("status")
2191+
else []
2192+
)
22102193
return []
22112194

22122195
def _criteria_entities_from_event(
@@ -2366,11 +2349,7 @@ def _normalize_against_active_parent(self, task: TaskObject):
23662349
if not task.parent_task_id:
23672350
return
23682351
parent = next(
2369-
(
2370-
state
2371-
for state in self._active_tagged_tasks.values()
2372-
if state.task_id == task.parent_task_id
2373-
),
2352+
(state for state in self._active_tagged_tasks.values() if state.task_id == task.parent_task_id),
23742353
None,
23752354
)
23762355
if parent is None or parent.started_at is None:

0 commit comments

Comments
 (0)