Alloy Programming Language
A general-purpose programming language designed specifically for AI agents, with first-class support for agent interactions, tool definitions, and hybrid human-AI development workflows.
Overview
Alloy is a complete programming language that treats artificial intelligence as a first-class citizen alongside traditional deterministic computation. The language provides all the capabilities of modern programming languages - variables, functions (tools), control flow, data structures, and error handling - with AI integration seamlessly woven into the fabric of the language.
Key Features
- Agent-First Design: Optimized for AI agents to read, write, and maintain code
- Natural Language Patterns: Syntax follows natural language conventions
- Complete Programming Language: Full support for variables, tools, control flow, and data structures
- AI as Infrastructure: AI models treated as computational primitives
- Tool Definition: Define reusable functions with clear parameter and return specifications
- Multi-Agent Collaboration: Built-in support for multiple AI agents working together
- Robust Error Handling: Comprehensive error handling patterns built into the language
Quick Start
Installation
# Clone the repository
git clone https://github.com/alloy-lang/alloy.git
cd alloy
# Install dependencies
pip install -r requirements.txt
# Or install in development mode
pip install -e .[dev]
Basic Usage
from alloy import Interpreter, Parser
# Create interpreter
interpreter = Interpreter()
parser = Parser()
# Example Alloy code
code = '''
# Define a tool (function)
tool add_numbers takes a, b returns sum {
sum = a + b
return sum
}
# Use the tool
result = add_numbers(5, 3)
# Define an AI agent
claude = agent "gpt-4o-mini"
# Use the agent
analysis, error = claude "Analyze this data: [1, 2, 3, 4, 5]"
'''
# Parse and execute
ast = parser.parse(code)
interpreter.interpret(ast)
Environment Setup
Create a .env file in your project root:
OPENAI_API_KEY=your_openai_api_key_here
Language Examples
Tool Definition and Usage
tool calculate_average takes numbers returns average {
sum = 0
count = 0
for num in numbers do {
sum = sum + num
count = count + 1
}
average = sum / count
return average
}
data = [10, 20, 30, 40, 50]
avg = calculate_average(data)
Agent Interactions
# Define agents with specific capabilities
analyst = agent "gpt-4o-mini" with tools data_analysis, chart_creation
writer = agent "gpt-4o-mini" with tools document_writing
# Use agents for specific tasks
insights, error = analyst Analyze sales_data
report, error = writer "Write a summary report" insights
Control Flow
# Conditional logic
when score > 90 then {
grade = "A"
} otherwise {
grade = "B"
}
# Loops
for item in shopping_list do {
total_cost = total_cost + item.price
}
# While loops
while queue_not_empty do {
process_next_item()
}
Project Structure
alloy/
├── README.md # This file
├── pyproject.toml # Python packaging configuration
├── requirements.txt # Runtime dependencies
├── .gitignore # Git ignore patterns
├── src/
│ └── alloy/
│ ├── __init__.py # Package initialization
│ ├── lexer.py # Tokenization and lexical analysis
│ ├── parser.py # Grammar parsing and AST generation
│ ├── interpreter.py # AST execution engine
│ ├── ast_nodes.py # AST node type definitions
│ └── environment.py # Variable and scope management
├── tests/
│ ├── __init__.py
│ ├── test_lexer.py # Lexer tests
│ ├── test_parser.py # Parser tests
│ ├── test_interpreter.py # Interpreter tests
│ ├── test_language_features.py # End-to-end language tests
│ └── test_examples.py # Example program tests
├── docs/
│ ├── language-specification.md # Complete language specification
│ ├── alloy-mvp-spec.md # MVP specification
│ └── development.md # Development guide
└── examples/
├── basic.alloy # Basic language examples
├── agent_examples.alloy # Agent usage examples
└── tools_examples.alloy # Tool definition examples
Development
Setting up for Development
# Install development dependencies
pip install -e .[dev]
# Run tests
pytest
# Run tests with coverage
pytest --cov=src/alloy --cov-report=html
# Format code
black src/ tests/
# Sort imports
isort src/ tests/
# Type checking
mypy src/
# Linting
flake8 src/ tests/
Test-Driven Development (TDD)
This project follows TDD practices:
- Write tests first for new language features
- Run tests to ensure they fail initially
- Implement the minimal code to make tests pass
- Refactor while keeping tests green
- Repeat for each new feature
Adding New Language Features
- Create tests in the appropriate
tests/test_*.pyfile - Update the lexer in
src/alloy/lexer.pyif new tokens are needed - Update the parser in
src/alloy/parser.pyfor new grammar rules - Update the interpreter in
src/alloy/interpreter.pyfor execution logic - Add AST nodes in
src/alloy/ast_nodes.pyif needed - Update documentation
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes following TDD practices
- Ensure all tests pass (
pytest) - Ensure code formatting is correct (
black . && isort .) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Documentation
- Language Specification - Complete language reference
- MVP Specification - Minimum viable product specification
- Development Guide - Detailed development instructions
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with PLY (Python Lex-Yacc) for lexing and parsing
- Inspired by modern programming languages and AI-first development practices
- Designed for the age of AI agents and human-AI collaboration
Metadata
Release files for alloy-lang 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| alloy_lang-0.1.0.tar.gz | 135.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| alloy_lang-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 172.1 kB
Release files / alloy_lang-0.1.0.tar.gz
| Download URL | alloy_lang-0.1.0.tar.gz |
|---|---|
| Size | 135.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4c64e3d9f0b017645bef7c272dc28c5926883e7097fbba6e9a0a8dbd7c87216
|
|
BLAKE2b-256 checksum How to use checksums |
0b2b153b87637f0708fe93eabb546c742aeeb1afa734df321593be5003cf1bb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / alloy_lang-0.1.0-py3-none-any.whl
| Download URL | alloy_lang-0.1.0-py3-none-any.whl |
|---|---|
| Size | 36.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
39bc652a0ff3229f833ac7ea286b313f297604d6221423fdd0ee1b04effd1ead
|
|
BLAKE2b-256 checksum How to use checksums |
533a0623458ffb4487d53fcd33c90fdd0b10b8dc6946b03bb4374b98283c03d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for alloy-lang 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.