Processes each item in the operation chain by executing the specified external function
with its args and kwargs. Logs starting, annotating, and ending the trace based on tuple position.
PARAMETER |
DESCRIPTION |
chain
|
A list where each tuple contains:
- An external function to execute.
- A list of positional arguments for the function.
- A dictionary of keyword arguments for the function.
TYPE:
List[Tuple[Callable[..., Any], List[Any], Dict[str, Any]]]
|
Source code in swarmauri_standard/tracing/ChainTracer.py
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 | def process_chain(
self, chain: List[Tuple[Callable[..., Any], List[Any], Dict[str, Any]]]
) -> "ChainTracer":
"""
Processes each item in the operation chain by executing the specified external function
with its args and kwargs. Logs starting, annotating, and ending the trace based on tuple position.
Args:
chain (List[Tuple[Callable[..., Any], List[Any], Dict[str, Any]]]): A list where each tuple contains:
- An external function to execute.
- A list of positional arguments for the function.
- A dictionary of keyword arguments for the function.
"""
for i, (func, args, kwargs) in enumerate(chain):
# Infer operation type and log
if i == 0:
operation = "Start"
self.start_trace(*args, **kwargs)
elif i == len(chain) - 1:
operation = "End"
self.end_trace(*args, **kwargs)
else:
operation = "Annotate"
self.annotate_trace(*args, **kwargs)
# For the actual external function call
result = func(*args, **kwargs)
print(f"Function '{func.__name__}' executed with result: {result}")
self.traces.append((operation, func, args, kwargs, result))
return self
|