From ad66667bdb9dbb6c30b5c7f925303f4e94a7969c Mon Sep 17 00:00:00 2001 From: Eric Gustin <34000337+EricGustin@users.noreply.github.com> Date: Fri, 21 Feb 2025 16:25:43 -0800 Subject: [PATCH] Update CrewAI example: Custom Auth Flow (#260) --- examples/crewai/crewai_with_arcade_tool.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/crewai/crewai_with_arcade_tool.py b/examples/crewai/crewai_with_arcade_tool.py index 19bba268..131153c4 100644 --- a/examples/crewai/crewai_with_arcade_tool.py +++ b/examples/crewai/crewai_with_arcade_tool.py @@ -30,16 +30,15 @@ def custom_auth_flow( Authorization is handled before executing the tool. This function overrides the ArcadeToolManager's default auth flow performed by ArcadeToolManager.authorize_tool """ - print(f"Authorization required for tool: '{tool_name}' with inputs:") - for input_name, input_value in tool_input.items(): - print(f" {input_name}: {input_value}") - # Get authorization status auth_response = manager.authorize(tool_name, USER_ID) # If the user is not authorized for the tool, # then we need to handle the authorization before executing the tool if not manager.is_authorized(auth_response.id): + print(f"Authorization required for tool: '{tool_name}' with inputs:") + for input_name, input_value in tool_input.items(): + print(f" {input_name}: {input_value}") # Handle authorization print(f"\nTo authorize, visit: {auth_response.url}") # Block until the user has completed the authorization @@ -48,6 +47,10 @@ def custom_auth_flow( # Ensure authorization completed successfully if not manager.is_authorized(auth_response.id): raise ValueError(f"Authorization failed for {tool_name}. URL: {auth_response.url}") + else: + print(f"Authorization already granted for tool: '{tool_name}' with inputs:") + for input_name, input_value in tool_input.items(): + print(f" {input_name}: {input_value}") def custom_execute_flow(