Core library for AgentSpec - define and enforce agent capabilities and boundaries.
AgentSpec is a formal specification language for defining what agents can and cannot do. It supports:
- Capability definitions (what actions are allowed)
- Boundary declarations (hard limits on behavior)
- Obligation rules (what must happen)
- Hierarchical composition (specs can inherit from others)
- Conflict resolution (deterministic handling of competing rules)
- Formal verification (prove specs are consistent)
npm install @goalos/agentspec-core
import { AgentSpec } from "@goalos/agentspec-core";
const spec = AgentSpec.parse(` agent: claude-research version: 1.0
capabilities: read: - documents - web_search - academic_databases write: - draft_documents - save_research_notes
boundaries: must_not: - contact_external_apis - modify_existing_documents - access_user_personal_data max_token_spend: 100000 max_retries: 3 max_request_size: 8KB
obligations: must: - cite_all_sources - flag_uncertain_claims - report_search_queries `);
const canRead = spec.canCapability("read", "documents"); // true const canModify = spec.canCapability("write", "documents"); // false
await spec.toFile("claude-research.agent");
agent: version:
capabilities: read: [list of readable resources] write: [list of writable resources] execute: [list of executable actions]
boundaries: must_not: [forbidden actions] max_token_spend: max_retries: max_request_size: time_limit:
obligations: must: [required actions] must_verify: [verification requirements]
inherits:
- parent_spec.agent
class AgentSpec:
- name: string
- version: string
- capabilities: Capabilities
- boundaries: Boundaries
- obligations: Obligations
- parent?: AgentSpec
Methods:
- parse(yaml) - Parse YAML specification
- canCapability(action, resource) - Check if allowed
- isWithinBoundary(action) - Check boundary compliance
- canExecute(action) - Full permission check
- getConflicts() - Find conflicting rules
- verify() - Prove spec is consistent
- inherit(parent) - Inherit from parent spec
- toYAML() - Serialize to YAML
- toJSON() - Serialize to JSON
- toFile(path) - Save to file
- fromFile(path) - Load from file
agent: claude-coding version: 1.0
capabilities: read: - source_code - file_system - git_history write: - source_code - comments - test_files execute: - run_tests - linter - formatter
boundaries: must_not: - push_to_main - delete_files - access_secrets max_file_size: 1MB
obligations: must: - include_tests - follow_style_guide - write_comments
agent: advanced-research version: 1.0
inherits:
- base-research.agent
capabilities: read: - paywalled_academic_databases
boundaries: max_token_spend: 200000
const spec = AgentSpec.parse(specYaml);
if (!spec.isWithinBoundary({ type: "token_spend", value: 5000 })) { throw new Error("Would exceed token limit"); }
When specs inherit, conflicts are resolved using:
- Most specific rule wins
- Explicit deny overrides allow
- Child overrides parent
- Documented in conflict report
Example:
capabilities: write: [all_documents]
boundaries: must_not: [sensitive_documents]
Result: Can write documents except sensitive ones (child boundary applies)
Specs can be formally verified:
const conflicts = spec.getConflicts(); if (conflicts.length > 0) { console.error("Spec has conflicts:", conflicts); }
const verified = spec.verify(); if (!verified.valid) { console.error("Spec is inconsistent:", verified.errors); }
npm test
Includes:
- Spec parsing
- Permission checking
- Conflict detection
- Inheritance resolution
- Verification
- Main README: ../../README.md
- AgentSpec Language: ../../spec/agentspec-lang-v0.1.md
- CLI Reference: ../../spec/agentspec-cli-reference.md
- Quickstart: ../../spec/agentspec-quickstart.md
MIT - See LICENSE