Back
Imp brings a full port of DSPy to the BEAM in Elixir
SiTech AI Team3 წთ. საკითხავი

Imp brings a full port of DSPy to the BEAM in Elixir

Imp is an Elixir library that ports DSPy to the BEAM: a developer declares what each model step takes and returns, and an optimizer improves the program against labeled examples. Signatures and agent loops run under OTP.

A new Elixir library called Imp presents itself as a full port of DSPy to the BEAM. A developer describes a language-model step as a typed function, measures the result and hands it to an optimizer, while the reliability and concurrency of OTP stay in place.

Imp project illustration: an imp studying a hand of cards through a lens

A signature instead of a prompt

The basic unit is a signature: you write only what goes in and what comes out, for example "issue -> kind: enum[bug,feature,question], summary", plus a short description. Imp.predict/2 builds the prompt from it, checks the reply against it and returns typed fields: kind is always one of the three allowed values, or the call fails.

The same signature works in other modes: Imp.chain_of_thought/2 makes the model reason first, and Imp.react/3 gives it tools. The developer writes neither a prompt template nor a reply parser.

Measure it, then improve it

With labeled examples and a metric, Imp scores a program and improves it. Three lists are needed: a trainset the optimizer learns from, a valset used to compare candidates, and a testset scored before and after. Imp.evaluate/3 computes the metric, for instance Imp.exact_match(:kind).

Then an optimizer takes over: Imp.Optimizer.GEPA.new/2 uses a stronger reflection model to read failures and rewrite instructions. The library also ships LabeledFewShot and BootstrapFewShot for selecting examples, MIPROv2 for searching combinations, SIMBA for rules drawn from the program's own attempts, and weight training. The result is a new program whose instructions and examples are saved as JSON and reviewed as a diff.

Agents and the rules of OTP

A tool is an ordinary Elixir function: Imp.tool/3 takes a name, a description, a function and a JSON schema, and Imp.react/3 builds an agent that calls those tools until it can answer. In the README example the agent fetches a web page with Req and returns the version number.

Imp.call/2 runs a program in the calling process, while Imp.start_run/3 starts it as a separate supervised process that can be watched, stopped and limited; an authorize callback decides which tool calls are allowed. Imp.Run.events/1 returns the event log, model requests are cut to a deadline, and a tool call that may already have taken effect is reported as unknown rather than silently retried.

Imp can import the tools of an approved MCP server, and through ACP any program can be served to Zed and other clients as an agent. The library is on Hex, requires Elixir 1.19 and a C++ compiler, and reaches models through ReqLLM. Version 0.5 is experimental, and Imp is MIT licensed.

SSiTech

SiTech — AI-powered web development

We build fast, modern websites and bring AI into real business workflows. Have a project or a question? We'd love to help.