AMU Pattern
Understanding the Adapter-Metadata-Usecases Pattern
The AMU (Adapter-Metadata-Usecases) is a general purpose pattern used throughout Agentic Team OS, influenced by hexagonal architecture and ports and adapters pattern. It provides a clear separation of concerns and promotes maintainable, testable code.
Pattern Overview
The pattern consists of three main components:
1. Adapters
Adapters handle external interactions and infrastructure concerns:
This is split into primary and secondary adapters.
- Primary adapters are for handling incoming requests to the unit. For example a Lambda handler or DynamoDB stream handler.
- Secondary adapters are for handling outgoing requests to external services. For example an OpenAI client or a database client.
Primary Adapter
Here is an example of a primary adapter in the Orchestrator for an Agent that handles generating a value strategy. for a saas founder.
Key Points of Primary Adapter Pattern:
- Handles all Protocol specific logic
- Integrates with SaaS Identity for auth
- Enriches the request with metadata before passing it to the usecase
- Handles response formatting and errors
- Keeps infrastructure concerns separate from business logic
Secondary Adapter
Secondary adapters handle external integrations like AI services, databases, and third-party APIs. Here’s an example of a secondary adapter for OpenAI:
Key Points of Secondary Adapter Pattern:
- Encapsulates external service integration details
- Handles service-specific configuration
- Manages connection lifecycle
- Implements retry and error handling
- Transforms data between domain and external formats
2. Metadata
Metadata is used to glue the adapters and usecases together. It defines the domain models, types, and interfaces:
Key Points of Metadata Pattern:
- Defines system prompts and instructions
- Specifies data schemas and validation rules
- Declares domain types and interfaces
- Establishes contract between adapters and usecases
- Provides type safety and runtime validation
3. Usecases
Usecases implement the business logic and orchestrate the flow between adapters. They handle:
- Business rules and domain logic
- Flow coordination between adapters
- Error handling and logging
- Data transformation and validation
Here’s an example usecase that generates a value strategy:
Key Points of Usecase Pattern:
- Pure business logic with no infrastructure concerns
- Coordinates between multiple adapters (e.g., OpenAI and database)
- Handles error cases and logging
- Transforms data between adapter formats
- Returns standardized response types
Pattern Benefits
-
Separation of Concerns
- Clear boundaries between components
- Easier to maintain and modify
- Better testability
-
Dependency Inversion
- Business logic depends on abstractions
- Infrastructure details are isolated
- Easier to swap implementations
-
Testability
- Business logic can be tested in isolation
- Easy to mock external dependencies
- Clear component boundaries
Best Practices
-
Keep Components Focused
- Adapters handle external concerns
- Metadata defines structures
- Usecases contain business logic
-
Dependency Injection
- Inject dependencies through constructors
- Use interfaces for dependencies
- Follow IoC principles
-
Error Handling
- Define domain-specific errors
- Handle errors at appropriate levels
- Maintain error boundaries
-
Testing Strategy
- Unit test usecases in isolation
- Mock adapters in tests
- Integration test full flows
Was this page helpful?