-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add flow_id, self.name for instance names of Flows and Nodes and easy isolated storage for nested flows #5
base: main
Are you sure you want to change the base?
Conversation
For performance and tracing flow history, I think a decorator could do.
Also I didn't get to the point where I would need to manage concurrent connections, requests per minutes/flow/batch, and token per node/flow... But it would be nice to have it planned at this stage. Like infinite loop prevention other than logging to But am I getting to far from a minimal implementation of PocketFlow ? Some example decorator from AI: def trace_node(debug=False):
def decorator(func):
if not debug:
# Return original function if debug is disabled
return func
def wrapper(node, *args, **kwargs):
# Initialize trace if not exists
if not hasattr(node, '_trace'):
node._trace = []
# Create trace entry
trace_entry = {
'timestamp': time.time(),
'node': node.name,
'action': func.__name__,
'args': args,
'kwargs': kwargs,
'status': 'started'
}
# Add initial entry
node._trace.append(trace_entry)
try:
# Execute the original method
result = func(node, *args, **kwargs)
# Update entry with success status
trace_entry.update({
'status': 'success',
'duration': time.time() - trace_entry['timestamp'],
'result': result
})
return result
except Exception as e:
# Update entry with error status
trace_entry.update({
'status': 'error',
'duration': time.time() - trace_entry['timestamp'],
'exception': str(e),
'traceback': traceback.format_exc()
})
raise
finally:
# Finalize entry
trace_entry['end_time'] = time.time()
return wrapper
return decorator
...
DEBUG = True # Set this globally or via configuration
class Node(BaseNode):
@trace_node(debug=DEBUG)
def prep(self, shared):
... # Access tracing information
for node in flow.get_all_nodes():
print(f"Node: {node.name}")
for entry in node._trace:
print(f" {entry['action']}: {entry['status']} in {entry['duration']:.2f}s") |
WIP to get instance names and flow names.
For discussion as in Issue #4
THIS IS JUST A DRAFT, NOT TESTED EXTENSIVELY.
Now when inside a
prep()
,exec()
orpost()
, it's possible to print the instance name withWill now print :
Todo : get feedback and more ideas + review ?
Questions: This does add complexity and more lines of code... Is it all useful ?
So I think that :
pocketflow
andpocketflowextra
to separate basic and advanced framework that are still somewhat compatible but with missing features ? Users could just cherry pick some parts fromextra
to add features quickly.pocketflowdev
for development and experimental features that may break compatibility ?Try this code
I added
rework.py
as example, look atclass GetOpinion(Node):
for actual use.EDIT: Now with updated
build_mermaid
code !PR comment generated with AI assistance :
This change introduces several improvements to BaseNode and Flow classes:
These changes enable:
The improvements include:
This is particularly useful for: