feat: add property-based access control to GraphRuntimeState

- Replace direct field access with private attributes and property decorators
- Implement deep copy protection for mutable objects (dict, LLMUsage)
- Add helper methods: set_output(), get_output(), update_outputs()
- Add increment_node_run_steps() and add_tokens() convenience methods
- Update loop_node and event_handlers to use new accessor methods
- Add comprehensive unit tests for immutability and validation
- Ensure backward compatibility with existing property access patterns
This commit is contained in:
-LAN-
2025-09-04 02:08:58 +08:00
parent 9c96b23d55
commit fe3f03e50a
4 changed files with 250 additions and 24 deletions

View File

@ -267,10 +267,10 @@ class EventHandler:
# in runtime state, rather than allowing nodes to directly access runtime state.
for key, value in event.node_run_result.outputs.items():
if key == "answer":
existing = self._graph_runtime_state.outputs.get("answer", "")
existing = self._graph_runtime_state.get_output("answer", "")
if existing:
self._graph_runtime_state.outputs["answer"] = f"{existing}{value}"
self._graph_runtime_state.set_output("answer", f"{existing}{value}")
else:
self._graph_runtime_state.outputs["answer"] = value
self._graph_runtime_state.set_output("answer", value)
else:
self._graph_runtime_state.outputs[key] = value
self._graph_runtime_state.set_output(key, value)