| Crates.io | apex_spec |
| lib.rs | apex_spec |
| version | 1.1.0 |
| created_at | 2025-11-22 22:01:37.668855+00 |
| updated_at | 2025-11-22 22:01:37.668855+00 |
| description | APEX Spec v1.1 — Deterministic DSL for agent planning, validation, and tool execution. Parser, validator, interpreter, prompts included. |
| homepage | https://github.com/oldnordic/apex |
| repository | https://github.com/oldnordic/apex |
| max_upload_size | |
| id | 1945799 |
| size | 147,134 |
APEX (Agent Planning & Execution Specification) is a deterministic, human-readable DSL for controlling LLM reasoning, tool orchestration, validation steps, and reproducible execution workflows.
This crate provides the reference Rust implementation of APEX v1.1:
APEX is designed for reliability:
cargo add apex_spec
use apex_spec::{parse_full, ExecutionPlan};
let input = r#"
TASK
fix search param
GOALS
improve recall
PLAN
scan code
fix param
run tests
CONSTRAINTS
no_mocks
real_dbs
VALIDATION
cargo test
TOOLS
code_search "hnsw"
META
version=1.1
"#;
let plan: ExecutionPlan = parse_full(input).unwrap();
println!("{:#?}", plan);
use apex_spec::{
parse_full,
prompts::{APEX_GENERATOR_V1_1, APEX_EXECUTOR_V1_1},
};
// Step 1: Ask an LLM to produce APEX
let user_query = "Fix the param mismatch in HNSW search and validate recall.";
let generator_prompt = format!("{}\n\n{}", APEX_GENERATOR_V1_1, user_query);
// send `generator_prompt` to your LLM of choice
let apex_document = call_llm(&generator_prompt)?;
// Step 2: Validate & interpret the APEX document
let plan = parse_full(&apex_document)?;
// Step 3: Execute step-by-step with an LLM or agent loop
let executor_prompt = format!(
"{}\n\n{}",
APEX_EXECUTOR_V1_1,
apex_document
);
// send `executor_prompt` + tool results to your agent loop
// interpret tool calls from the model and feed results back
println!("APEX execution initialized: {:?}", plan.task);
This pattern works with:
APEX is a simple, human-readable format for expressing:
TASK
Implement user authentication
GOALS
Users can log in securely
Session tokens expire properly
PLAN
1. Design auth schema
2. Implement login endpoint
3. Add session management
4. Write tests
CONSTRAINTS
No plaintext passwords
Use bcrypt or argon2
No breaking API changes
VALIDATION
All tests pass
No security warnings from cargo audit
When you give an LLM a task like "implement authentication", it has no guardrails:
Current solutions are either:
APEX provides explicit, parseable constraints that:
| Block | Required | Description |
|---|---|---|
| TASK | Yes | Single-line task description |
| GOALS | No | Success criteria |
| PLAN | No | Ordered execution steps |
| CONSTRAINTS | No | Hard rules that cannot be violated |
| VALIDATION | No | Post-execution checks |
| TOOLS | No | Available tool declarations |
| DIFF | No | Expected file changes |
| CONTEXT | No | Pre-loaded context |
| META | No | Metadata key-value pairs |
CONSTRAINTS > TASK > GOALS > PLAN > CONTEXT
If there's a conflict, higher precedence wins. Constraints are absolute.
version=1.1 in META blockunified or raw markers for machine validationuse apex_spec::{parse_full, Semantics, ParseMode, parse_str_with_mode};
let apex = r#"
TASK
Refactor database module
CONSTRAINTS
No mocks
Real databases only
< 300 LOC per function
PLAN
Analyze current structure
Extract common patterns
Write integration tests
META
version=1.1
"#;
let plan = parse_full(apex)?;
// Check constraints programmatically
let validated = apex_spec::parse_and_validate(apex)?;
let sem = Semantics::from_validated(&validated);
if sem.forbids_mocks() {
println!("This plan requires real implementations");
}
if let Some(limit) = sem.loc_limit() {
println!("LOC limit: {}", limit);
}
// Tolerant parsing (v1.1) - recovers from malformed input
let result = parse_str_with_mode(apex, ParseMode::Tolerant)?;
if !result.fixes.is_empty() {
println!("Recovered {} issues", result.fixes.len());
}
cargo build --release
cargo test
APEX defines a deterministic document structure:
TASK — primary objective
GOALS — desired outcomes
PLAN — sequential steps
CONSTRAINTS — rules that override PLAN
VALIDATION — success checks
TOOLS — allowed tool calls
META — version and metadata
TASK
fix index mismatch
GOALS
improve recall
PLAN
scan
patch
validate
CONSTRAINTS
no_mocks
VALIDATION
cargo test
TOOLS
code_search "index"
META
version=1.1
CONSTRAINTS > TASK > GOALS > PLAN
First line of DIFF block may specify:
unified — produce unified patchraw — free-formInvalid or hallucinated tools cause validation failure in strict mode.
Use embedded prompts:
APEX_GENERATOR_V1_1 — to create APEX documentsAPEX_EXECUTOR_V1_1 — to execute APEX documentsUse ExecutionState + StepStatus to implement checkpointing in your agent.
GPL-3.0
Open issues for:
PRs welcome for bug fixes and tests. Feature PRs should have an issue first.