From 6d496f799b4bda411cab23ef04377c14a90f98f8 Mon Sep 17 00:00:00 2001 From: iris-clawd Date: Tue, 21 Jul 2026 15:21:41 -0300 Subject: [PATCH] fix: handle async get_agent in load_agent_from_repository (#6608) * fix: handle async get_agent in load_agent_from_repository The enterprise PlusClient.get_agent() is async, but load_agent_from_repository() calls it synchronously. When the enterprise client is hooked in, client.get_agent() returns a coroutine instead of a response, causing "'coroutine' object has no attribute 'status_code'". This adds an inspect.isawaitable() check after the call: if the response is a coroutine, it is properly awaited via asyncio.run() (or via a thread-pool executor if an event loop is already running). Co-authored-by: Joe Moura * fix: resolve mypy type-checker errors for async awaitable handling * fix: remove unused type: ignore comment --------- Co-authored-by: Joe Moura --- lib/crewai/src/crewai/utilities/agent_utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/crewai/src/crewai/utilities/agent_utils.py b/lib/crewai/src/crewai/utilities/agent_utils.py index 96bcbf6d8..e72281e51 100644 --- a/lib/crewai/src/crewai/utilities/agent_utils.py +++ b/lib/crewai/src/crewai/utilities/agent_utils.py @@ -1136,6 +1136,18 @@ def load_agent_from_repository(from_repository: str) -> dict[str, Any]: client = PlusAPI(api_key=get_auth_token()) _print_current_organization() response = client.get_agent(from_repository) + if inspect.isawaitable(response): + coro = response + try: + loop = asyncio.get_running_loop() + except RuntimeError: + loop = None + + if loop and loop.is_running(): + with concurrent.futures.ThreadPoolExecutor() as pool: + response = pool.submit(asyncio.run, coro).result() # type: ignore[arg-type] + else: + response = asyncio.run(coro) # type: ignore[arg-type] if response.status_code == 404: raise AgentRepositoryError( f"Agent {from_repository} does not exist, make sure the name is correct or the agent is available on your organization."