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 <joao@crewai.com>

* fix: resolve mypy type-checker errors for async awaitable handling

* fix: remove unused type: ignore comment

---------

Co-authored-by: Joe Moura <joao@crewai.com>
This commit is contained in:
iris-clawd
2026-07-21 15:21:41 -03:00
committed by GitHub
parent 40279e3152
commit 6d496f799b

View File

@@ -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."