mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -65,7 +65,14 @@ class BaseMicroagent(BaseModel):
|
||||
try:
|
||||
metadata = MicroagentMetadata(**metadata_dict)
|
||||
except Exception as e:
|
||||
raise MicroagentValidationError(f'Error loading metadata: {e}') from e
|
||||
# Provide more detailed error message for validation errors
|
||||
error_msg = f'Error validating microagent metadata in {path.name}: {str(e)}'
|
||||
if 'type' in metadata_dict and metadata_dict['type'] not in [
|
||||
t.value for t in MicroagentType
|
||||
]:
|
||||
valid_types = ', '.join([f'"{t.value}"' for t in MicroagentType])
|
||||
error_msg += f'. Invalid "type" value: "{metadata_dict["type"]}". Valid types are: {valid_types}'
|
||||
raise MicroagentValidationError(error_msg) from e
|
||||
|
||||
# Create appropriate subclass based on type
|
||||
subclass_map = {
|
||||
@@ -184,7 +191,13 @@ def load_microagents_from_dir(
|
||||
elif isinstance(agent, KnowledgeMicroagent):
|
||||
knowledge_agents[agent.name] = agent
|
||||
logger.debug(f'Loaded agent {agent.name} from {file}')
|
||||
except MicroagentValidationError as e:
|
||||
# For validation errors, include the original exception
|
||||
error_msg = f'Error loading microagent from {file}: {str(e)}'
|
||||
raise MicroagentValidationError(error_msg) from e
|
||||
except Exception as e:
|
||||
raise ValueError(f'Error loading agent from {file}: {e}')
|
||||
# For other errors, wrap in a ValueError with detailed message
|
||||
error_msg = f'Error loading microagent from {file}: {str(e)}'
|
||||
raise ValueError(error_msg) from e
|
||||
|
||||
return repo_agents, knowledge_agents
|
||||
|
||||
Reference in New Issue
Block a user