agentpool icon indicating copy to clipboard operation
agentpool copied to clipboard

Feat/issue 12 manifest metadata

Open Leoyzen opened this issue 10 months ago • 2 comments

Summary

Resolves #12 - Enables support for YAML anchors and metadata fields in AgentsManifest configuration files.

Changes

New Features

  • Metadata Fields: Allows top-level fields with prefixes ., _, and x- for YAML anchors and custom metadata
  • Warning System: Unknown fields now trigger warnings instead of raising validation errors, improving user experience
  • YAML Anchors: Users can now define anchors (e.g., &default_settings) and reference them (e.g., *default_settings) to reduce configuration duplication

Implementation

  • Modified src/agentpool/models/manifest.py:
    • Changed extra="allow" in model_config to accept extra top-level fields
    • Added @model_validator(mode="after") to validate and warn about unknown fields
    • Preserved strict validation for nested models (agents, teams, etc.)
  • Added comprehensive test suite in tests/manifest/test_metadata_fields.py:
    • Tests for allowed metadata fields (.anchor, _meta, x-custom)
    • Tests for warning generation on unknown fields
    • Tests for mixed scenarios

Test Coverage

All tests passing (27/27):

  • ✅ New metadata field tests (3 tests)
  • ✅ Existing manifest tests (24 tests)
  • ✅ Regression test fixed for missing response references

Example Usage

# Define anchors for reuse
.shared_config: &default_settings
  type: native
  model: "openai:gpt-4o"
  system_prompt: "You are a helpful assistant"
# Custom metadata
x-version: "1.0.0"
_internal: "for internal use only"
responses:
  MyResponse:
    type: object
    fields:
      message: str
agents:
  coder: *default_settings
    name: coder
    tools:
      - read
      - write

Technical Details

  • Validation Logic: validate_extra_fields() method checks all extra top-level keys
  • Allowed Prefixes:
    • . (dot) - for YAML anchors and hidden fields
    • _ (underscore) - for internal/metadata fields
    • x- - for custom extensions (following OpenAPI convention)
  • Warning Behavior: Unknown fields log a WARNING with message: "Unknown field '{key}' in manifest. This field will be IGNORED."

Related Issue

Fixes #12

Leoyzen avatar Jan 28 '26 03:01 Leoyzen

Are these special field names part of the YAML spec? Would an alternative be to have a SubModel which has extra="allow"?

phil65 avatar Feb 20 '26 13:02 phil65

Are these special field names part of the YAML spec? Would an alternative be to have a SubModel which has extra="allow"?

@phil65 Thanks for the review and these thoughtful questions! Let me address them:

About the special field names

These prefixes (., _, x-) are not part of the YAML spec itself. They are naming conventions we chose to support the following use cases:

  1. YAML Anchors (primary use case): Users want to define reusable configuration fragments in YAML, e.g.:

    .shared_model: &default_model
      type: native
      model: "openai:gpt-4o"
    
    agents:
      coder: *default_model
        name: coder
    

    The .anchor definitions are essentially placeholders. After the YAML loader resolves the anchors, these fields effectively disappear (anchors are expanded at reference points), so they won't appear in the final validated object.

  2. Metadata fields: _meta for internal metadata, x-* following the OpenAPI extension convention

About the SubModel alternative

This is a great suggestion! We did consider a similar design:

_anchors:
  shared_model: &default_model
    type: native
    model: "openai:gpt-4o"

However, this approach has trade-offs:

  • Pros: More structured, with explicit schema support via a nested SubModel
  • Cons: When referencing YAML anchors, users would need to use *_anchors.shared_model (non-standard YAML anchor syntax), which breaks the intuitive expectation of how YAML anchors typically work

The current approach preserves idiomatic YAML usage while declaring these fields via patternProperties in the JSON Schema, so YAML LSPs won't flag them as errors.

I'm happy to adjust the implementation if you prefer the SubModel approach, or we can iterate on other ideas. What do you think?

Leoyzen avatar Mar 01 '26 14:03 Leoyzen