Skip to content

Digine-Labs/concerto-lang

Repository files navigation

Concerto Language

A programming language for orchestrating AI agents.

Concerto provides a Rust-like syntax purpose-built for designing complex AI harnesses. Define models, tools, memory databases, and multi-step pipelines as code -- then let the Concerto runtime handle LLM connections, structured output validation, and external integration.

Why Concerto?

Prompt engineering is time-consuming. LangChain-style libraries are task-specific. Concerto gives you a full programming language to orchestrate agents -- with type safety, error handling, and composable pipelines.

Concerto.toml

[project]
name = "classifier"
version = "0.1.0"
entry = "src/main.conc"

[connections.openai]
provider = "openai"
api_key_env = "OPENAI_API_KEY"
default_model = "gpt-4o"

src/main.conc

schema Classification {
    label: String,
    confidence: Float,
    reasoning: String,
}

model Classifier {
    provider: openai,
    base: "gpt-4o",
    temperature: 0.2,
    system_prompt: "You are a document classifier.",
}

fn main() {
    let document = "The quarterly earnings report shows a 15% increase...";
    let prompt = "Classify this document: ${document}";

    let result = Classifier.execute_with_schema<Classification>(prompt);

    match result {
        Ok(classification) => emit("result", classification),
        Err(e) => emit("error", e),
    }
}

Key Features

  • Models as first-class constructs -- Define LLM-powered models with base model, provider, temperature, system prompt, tools, and memory
  • Model memory -- memory declarations plus with_memory(...) for multi-turn context injection and auto-append chat history
  • Dynamic tool binding -- with_tools([...]) adds tools per-execution, without_tools() strips default tools for focused runs
  • Schema validation -- Define expected output structures; runtime validates and auto-retries on mismatch
  • First-class pipelines -- pipeline/stage keywords for declarative multi-model workflows
  • Bidirectional emit system -- Runtime outputs that enable programmatic integration with host applications
  • In-memory databases -- Map-like storage for model query design and harness state (ledger)
  • Tools -- Define tools as classes that models can invoke, with auto-generated parameter schemas
  • Strong type system -- Static typing with inference, including AI-specific types (Prompt, Response, Schema<T>)
  • Dual error handling -- Result<T,E> with ? propagation and try/catch for flexibility
  • Async-native -- All model execution is async; parallel execution with await (a, b, c)
  • Pipe operator -- prompt |> model.execute() |> parse_schema(Output) |> emit("result")
  • LLM provider agnostic -- use manifest-based [connections.*] entries for OpenAI, Anthropic, Google, Ollama, or custom providers

Architecture

 .conc Source Code
       |
       v
 +-----------+
 | COMPILER  |  Lexer -> Parser -> AST -> Semantic Analysis -> IR Generation
 +-----------+
       |
       v
  .conc-ir (JSON-based Intermediate Representation)
       |
       v
 +-----------+
 |  RUNTIME  |  Stack-based VM with model, tool, memory, and emit systems
 +-----------+
       |
       v
 Emits (programmatic output to host application)

Example: Multi-Model Pipeline

schema Classification {
    label: String,
    confidence: Float,
}

pipeline DocumentProcessor {
    stage extract(doc: String) {
        let text = Extractor.execute(doc)?;
        text
    }

    stage classify(text: String) {
        let result = Classifier.execute_with_schema<Classification>(text)?;
        result
    }

    stage route(classification: Classification) {
        match classification.label {
            "legal" => LegalModel.execute(classification)?,
            "technical" => TechModel.execute(classification)?,
            _ => DefaultModel.execute(classification)?,
        }
    }
}

fn main() {
    let result = DocumentProcessor.run(input_document);
    match result {
        Ok(output) => emit("processed", output),
        Err(e) => emit("error", e),
    }
}

Installation

git clone https://github.com/Digine-Labs/concerto-lang.git
cd concerto-lang
cargo build --release

Binaries will be in target/release/:

  • concertoc -- Compiler (.conc -> .conc-ir)
  • concerto -- Runtime (executes .conc directly or precompiled .conc-ir)

Getting Started

  1. Write a Concerto program:
// hello.conc
fn main() {
    emit("greeting", "Hello from Concerto!");
}
  1. Compile it:
concertoc hello.conc
  1. Run it:
concerto run hello.conc

Optional: run the compiled IR artifact:

concerto run hello.conc-ir

Example Projects

  • examples/hello_agent -- minimal single-model flow
  • examples/tool_usage -- local tools + MCP tool interfaces
  • examples/multi_agent_pipeline -- multi-stage orchestration
  • examples/agent_memory_conversation -- spec 24 memory patterns (with_memory, manual mode, message queries)
  • examples/dynamic_tool_binding -- spec 25 dynamic tool composition (with_tools, without_tools)
  • examples/host_streaming -- spec 27 listen syntax with external agent streaming
  • examples/bidirectional_host_middleware -- self-contained bidirectional agent middleware test (includes local agent process)
  • examples/core_language_tour -- broad core syntax/semantics coverage (types, control flow, loops, traits/impls, hashmap, Result)
  • examples/modules_and_visibility -- module/import/visibility syntax coverage (use, mod, pub)
  • examples/error_handling_matrix -- Option/Result + ? + try/catch/throw runtime behavior matrix
  • examples/async_concurrency_patterns -- async/await syntax coverage (prefix+postfix await, tuple await, await emit, pipeline interplay)
  • examples/agent_chat_stream -- memory-backed multi-turn chat + chunk streaming surrogate with emit channels
  • examples/schema_validation_modes -- strict schema + fallback/optional schema + manual coercion strategy patterns
  • examples/testing -- @test/@expect_fail decorator examples with mock agents, assertions, and emit capture

Agent adapter reference projects:

  • agents/claude_code -- reference middleware that bridges Concerto agent protocol to Claude Code CLI (oneshot + listen/stream modes)

Standard Library

Module Functions Description
std::math abs, min, max, clamp, round, floor, ceil, pow, sqrt, random, random_int Numeric operations
std::string split, join, trim, replace, to_upper, to_lower, contains, substring, len, repeat, reverse, parse_int, parse_float String manipulation
std::env get, require, all, has Environment variables
std::time now, now_ms, sleep Time and ISO 8601
std::json parse, stringify, stringify_pretty, is_valid JSON serialization
std::fmt format, pad_left, pad_right, truncate, indent Text formatting
std::log info, warn, error, debug Structured logging
std::fs read_file, write_file, append_file, exists, list_dir, remove_file, file_size File system
std::collections Set, Queue, Stack (+ 20 methods) Data structures
std::http get, post, put, delete, request HTTP client
std::crypto sha256, md5, uuid, random_bytes Cryptography
std::prompt template, from_file, count_tokens Prompt utilities

Documentation

Language specifications are in the spec/ directory:

Project Status

See STATUS.md for detailed project tracking.

Current: Phase 1-8 + Specs 29-30 complete (latest: agent initialization params with init/init_ack protocol, pipeline stage type contracts with adjacency checking and signature syntax).

License

MIT

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors