Skip to content

Conversation

@Gops123
Copy link
Collaborator

@Gops123 Gops123 commented Dec 28, 2025

Summary

Fixes #89

When loading agents from a directory, the daemon now checks the kind field before attempting to parse files as Agent configs. This prevents confusing errors when the directory contains non-Agent YAML files (Trigger, Fleet, Flow, etc.).

Problem

Previously, when the agents directory contained a Trigger file (or any non-Agent YAML), the daemon would try to parse it as an Agent and fail with:

Error: Failed to parse agent config: pr_review.yaml

  Field: spec
  Error: missing field `model`

This was confusing because:

  1. The file is a valid Trigger, not an invalid Agent
  2. The error message didn't clarify that the file should be in a different directory

Solution

Added a yaml_file_has_kind helper function that checks the kind field before attempting full deserialization:

fn yaml_file_has_kind(path: &Path, expected_kind: &str) -> bool {
    #[derive(Deserialize)]
    struct KindCheck {
        kind: Option<String>,
    }
    // ... parse and check kind
}

Changes

  • crates/aof-core/src/registry.rs:

    • Added yaml_file_has_kind helper function
    • Updated AgentRegistry.load_directory to skip non-Agent files
  • crates/aof-triggers/src/handler/mod.rs:

    • Added TriggerHandler::yaml_file_has_kind method
    • Updated load_agents_from_directory to check kind before parsing

Testing

# Create a directory with mixed YAML files
mkdir /tmp/mixed-agents
cp examples/agents/devops.yaml /tmp/mixed-agents/
cp examples/triggers/slack-starter.yaml /tmp/mixed-agents/pr_review.yaml

# Run daemon - now works without error
aofctl serve --agents-dir /tmp/mixed-agents
# Logs: "Skipping non-Agent file: /tmp/mixed-agents/pr_review.yaml"
# Logs: "Loaded agent 'devops' from /tmp/mixed-agents/devops.yaml"

Checklist

  • Code follows project style
  • Tests pass
  • Documentation N/A (internal behavior change)

🤖 Generated with Claude Code

When loading agents from a directory or running an agent file, we now
check the `kind` field before attempting to parse as Agent configs.
This prevents confusing errors when the file is a different resource type.

Changes:
- Added yaml_file_has_kind helper to check kind before parsing
- Updated AgentRegistry.load_directory to skip non-Agent files
- Updated TriggerHandler.load_agents_from_directory to check kind
- Updated aofctl run agent to give clear error for wrong kind

Before: Parsing a Trigger file as Agent would fail with:
  "Error: Failed to parse agent config: pr_review.yaml
   Field: spec
   Error: missing field `model`"

After: Clear error message with hint:
  "Error: Wrong resource type: pr_review.yaml
   Expected: kind: Agent
   Found: kind: Trigger
   Hint: Use 'aofctl run trigger' instead of 'aofctl run agent'"

Fixes #89

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Gops123 Gops123 force-pushed the fix/issue-89-agent-loading-kind-check branch from f1692f8 to f0508bb Compare December 28, 2025 04:59
- Triggers: Explain they're for 'aofctl serve', not 'run'
- Fleet/Flow/Workflow: Suggest correct 'aofctl run <type>' command
- Unknown types: Generic helpful message

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Collaborator Author

@Gops123 Gops123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/review

@gouravjshah gouravjshah merged commit eb0cb8f into main Dec 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Daemon agent loading fails on non-Agent YAML files (Trigger, Fleet)

3 participants