Enhance Agent repository feedback & fix Tool auto-import (#2829)
Some checks failed
Notify Downstream / notify-downstream (push) Has been cancelled

* fix: fix tool auto-import from agent repository

* feat: enhance error message when agent is not found
This commit is contained in:
Lucas Gomide
2025-05-14 11:37:48 -03:00
committed by GitHub
parent c403497cf4
commit 7c4889f5c9
2 changed files with 26 additions and 8 deletions

View File

@@ -441,6 +441,11 @@ def load_agent_from_repository(from_repository: str) -> Dict[str, Any]:
client = PlusAPI(api_key=get_auth_token())
response = client.get_agent(from_repository)
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"
)
if response.status_code != 200:
raise AgentRepositoryError(
f"Agent {from_repository} could not be loaded: {response.text}"
@@ -450,14 +455,14 @@ def load_agent_from_repository(from_repository: str) -> Dict[str, Any]:
for key, value in agent.items():
if key == "tools":
attributes[key] = []
for tool_name in value:
for tool in value:
try:
module = importlib.import_module("crewai_tools")
tool_class = getattr(module, tool_name)
tool_class = getattr(module, tool["name"])
attributes[key].append(tool_class())
except Exception as e:
raise AgentRepositoryError(
f"Tool {tool_name} could not be loaded: {e}"
f"Tool {tool['name']} could not be loaded: {e}"
) from e
else:
attributes[key] = value