A general-purpose programming language designed for AI agents
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file alloy_lang-0.1.0.tar.gz.
File metadata
- Download URL: alloy_lang-0.1.0.tar.gz
- Upload date:
- Size: 135.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4c64e3d9f0b017645bef7c272dc28c5926883e7097fbba6e9a0a8dbd7c87216
|
|
| MD5 |
ece2edc4a81f5d5b70e23baab5b352e2
|
|
| BLAKE2b-256 |
0b2b153b87637f0708fe93eabb546c742aeeb1afa734df321593be5003cf1bb6
|
File details
Details for the file alloy_lang-0.1.0-py3-none-any.whl.
File metadata
- Download URL: alloy_lang-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39bc652a0ff3229f833ac7ea286b313f297604d6221423fdd0ee1b04effd1ead
|
|
| MD5 |
be363a5f684e7c6f6c6631da62f9093e
|
|
| BLAKE2b-256 |
533a0623458ffb4487d53fcd33c90fdd0b10b8dc6946b03bb4374b98283c03d4
|