Skip to content

Commit 709ef4b

Browse files
committed
comments
1 parent 838c236 commit 709ef4b

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

src/strands/multiagent/function_node.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import logging
99
import time
10-
from typing import Any, Protocol, Union
10+
from typing import Any, Callable, Union
1111

1212
from opentelemetry import trace as trace_api
1313

@@ -21,23 +21,7 @@
2121
logger = logging.getLogger(__name__)
2222

2323

24-
class FunctionNodeCallable(Protocol):
25-
"""Protocol defining the required signature for functions used in FunctionNode.
26-
27-
Functions must accept:
28-
- task: The input task (string or ContentBlock list)
29-
- invocation_state: Additional state/context from the calling environment
30-
- **kwargs: Additional keyword arguments for future extensibility
31-
32-
Functions must return:
33-
- A string result that will be converted to a Message
34-
"""
35-
36-
def __call__(
37-
self, task: Union[str, list[ContentBlock]], invocation_state: dict[str, Any] | None = None, **kwargs: Any
38-
) -> str:
39-
"""Execute the node with the given task."""
40-
...
24+
FunctionNodeCallable = Callable[[Union[str, list[ContentBlock]], dict[str, Any] | None], str]
4125

4226

4327
class FunctionNode(MultiAgentBase):
@@ -82,16 +66,19 @@ async def invoke_async(
8266
logger.debug("task=<%s> | starting function node execution", task)
8367
logger.debug("function_name=<%s> | executing function", self.name)
8468

85-
start_time = time.time()
8669
span = self.tracer.start_multiagent_span(task, "function_node")
8770
with trace_api.use_span(span, end_on_exit=True):
8871
try:
72+
start_time = time.time()
8973
# Execute the wrapped function with proper parameters
9074
function_result = self.func(task, invocation_state, **kwargs)
91-
logger.debug("function_result=<%s> | function executed successfully", function_result)
92-
9375
# Calculate execution time
9476
execution_time = int((time.time() - start_time) * 1000) # Convert to milliseconds
77+
logger.debug(
78+
"function_result=<%s>, execution_time=<%dms> | function executed successfully",
79+
function_result,
80+
execution_time,
81+
)
9582

9683
# Convert function result to Message
9784
message = Message(role="assistant", content=[ContentBlock(text=str(function_result))])

0 commit comments

Comments
 (0)