Skip to content

Conversation

@Aaryan-549
Copy link

Implements support for the AGENTS.md standard, enabling deepagents to automatically load standardized AI agent configuration files from projects.

🎯 Fixes

Closes #449

📝 Summary

This PR adds hierarchical AGENTS.md file discovery and loading to deepagents-cli, following the official agents.md specification. AGENTS.md files provide standardized project context, build steps, tests, and coding conventions that work across multiple AI coding agents (Cursor, Aider, GitHub Copilot, etc.).

🔧 Implementation Details

Core Changes

Configuration Discovery (config.py)

  • Added _find_agents_md() function for hierarchical file discovery
  • Searches from current directory up to (but not including) project root
  • Added Settings.get_agents_md_files() for easy access

Memory Integration (agent_memory.py)

  • Extended AgentMemoryMiddleware to load AGENTS.md files
  • Added agents_md_memory to state schema
  • Combines AGENTS.md content with existing user/project agent.md files
  • Multiple files are merged with clear separation markers

Key Features

Hierarchical Loading: Files loaded from most specific (current dir) to least specific
Monorepo Support: Nested AGENTS.md files provide subproject-specific context
Zero Configuration: Automatic detection and loading
Spec Compliant: Follows https://agents.md/ specification

Example Usage

my-project/
├── AGENTS.md                  # Not loaded (at project root)
├── packages/
│   ├── AGENTS.md             # ✓ Loaded: General package guidelines
│   └── package-a/
│       ├── AGENTS.md         # ✓ Loaded: Package A specific
│       └── src/              # ← You are here

When working in packages/package-a/src/, both AGENTS.md files are automatically loaded and combined.

🧪 Testing

Comprehensive Test Suite

Unit Tests (test_config.py)

  • Single file discovery
  • Hierarchical discovery
  • Project root boundary behavior
  • Monorepo scenarios
  • Edge cases (no files found, no project root)

Integration Tests (test_project_memory.py)

  • Single AGENTS.md file loading
  • Multiple hierarchical AGENTS.md files
  • Combined loading with user and project agent.md
  • Memory state management

All tests passing ✓

Windows Compatibility Fix

⚠️ Note to Reviewers: This PR includes a Windows compatibility fix for the execution.py module. The original code imported termios and tty unconditionally (Unix-only modules), causing import errors on Windows.

Changes:

  • Made termios/tty imports conditional with try-except
  • Added HAS_TERMIOS flag for runtime checks
  • Wrapped Unix-specific terminal code in conditional blocks
  • Provided Windows fallback using standard input() for approvals

Testing Request: If you're on Windows, please verify that:

  1. The CLI imports successfully
  2. Tests run without import errors
  3. Approval prompts work (with text-based fallback instead of arrow keys)

📚 Documentation

  • Added detailed AGENTS.md support section to README.md
  • Includes specification overview, usage examples, and sample file content
  • Clear documentation of hierarchical loading behavior

🔄 Backward Compatibility

✅ Fully backward compatible - existing functionality unchanged
✅ AGENTS.md loading is optional and automatic
✅ Works alongside existing agent.md files

This commit implements support for the AGENTS.md standard (https://agents.md/),
allowing deepagents to automatically load project-specific configuration files
that provide context and instructions to AI coding agents.

## Changes

### Core Implementation
- **config.py**: Added _find_agents_md() function to discover AGENTS.md files
  hierarchically from current directory up to project root
- **config.py**: Added Settings.get_agents_md_files() method for retrieving
  AGENTS.md file paths
- **agent_memory.py**: Extended AgentMemoryMiddleware to load AGENTS.md files
  alongside existing user and project agent.md files
- **agent_memory.py**: Added agents_md_memory to state schema and updated
  system prompt templates to include AGENTS.md content

### Features
- Hierarchical file discovery: searches from current directory up to (but not
  including) project root
- Monorepo support: nested AGENTS.md files provide subproject-specific context
- Multiple file combination: all discovered AGENTS.md files are combined with
  clear separation markers
- Automatic integration: no configuration needed, files are automatically loaded
  if present

### Testing
- **test_config.py**: Added comprehensive tests for _find_agents_md() function
  - Single file discovery
  - Hierarchical discovery
  - Project root boundary behavior
  - Monorepo scenarios
- **test_project_memory.py**: Added middleware integration tests
  - Single AGENTS.md file loading
  - Multiple hierarchical AGENTS.md files
  - Combined loading with user and project agent.md

### Documentation
- **README.md**: Added detailed AGENTS.md support section explaining:
  - What AGENTS.md is and its benefits
  - How it works in deepagents
  - Example directory structure for monorepos
  - Sample AGENTS.md file content

## Compliance with AGENTS.md Specification
- Follows hierarchical loading pattern (most specific to least specific)
- Stops before project root as per spec
- Supports monorepos with nested configuration files
- Compatible with other AI coding agents using the same standard
The deepagents-cli was importing termios and tty modules unconditionally,
which are Unix-only and not available on Windows. This caused import errors
when trying to use the CLI or run tests on Windows platforms.

## Changes

- Made termios and tty imports conditional with try-except
- Added HAS_TERMIOS flag to check for module availability
- Wrapped Unix-specific terminal control code in conditional blocks
- Provided Windows fallback using standard input() for approval prompts
- Existing fallback code now works correctly on Windows

## Testing

- Verified imports work correctly on Windows
- Confirmed AGENTS.md tests pass successfully on Windows platform
- Terminal control features degrade gracefully on Windows

This fix enables development and testing on Windows while maintaining
full functionality on Unix platforms.
@eyurtsev eyurtsev self-assigned this Nov 24, 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.

Support AGENTS.md

2 participants