Skip to main content

Crate prompty

Crate prompty 

Source
Expand description

§Prompty — Rust Runtime

Prompty is a markdown file format (.prompty) for LLM prompts. YAML frontmatter defines model, connection, tools, and schema. The markdown body becomes instructions with template variables.

§Core Pipeline

The runtime provides 5 public functions (matching TypeScript, Python, C#):

  • load() — Parse a .prompty file → typed Prompty agent
  • prepare() — Render template + parse role markers → Vec<Message>
  • run() — Execute LLM call + process response (takes messages)
  • invoke_agent() — One-shot: load → prepare → execute → process
  • turn() — Conversation round with optional tool-calling agent loop

§Providers

LLM providers are separate crates:

  • prompty-openai — OpenAI API
  • prompty-foundry — Azure OpenAI / Foundry
  • prompty-anthropic — Anthropic Claude

Register providers before calling pipeline functions:

use prompty::registry;

// Register OpenAI (done by prompty_openai::register())
// registry::register_executor("openai", prompty_openai::OpenAIExecutor);
// registry::register_processor("openai", prompty_openai::OpenAIProcessor);

§Features

  • otel — Enables OpenTelemetry tracing backend

Re-exports§

pub use connections::clear_connections;
pub use connections::has_connection;
pub use connections::register_connection;
pub use connections::with_connection;
pub use context::estimate_chars;
pub use context::format_dropped_messages;
pub use context::summarize_dropped;
pub use context::trim_to_context_window;
pub use guardrails::GuardrailError;
pub use guardrails::GuardrailPhase;
pub use guardrails::GuardrailResult;
pub use guardrails::Guardrails;
pub use guardrails::InputGuardrail;
pub use guardrails::OutputGuardrail;
pub use guardrails::ToolGuardrail;
pub use interfaces::ExecuteError;
pub use interfaces::Executor;
pub use interfaces::InvokerError;
pub use interfaces::Parser;
pub use interfaces::Processor;
pub use interfaces::Renderer;
pub use loader::LoadError;
pub use loader::load;
pub use loader::load_async;
pub use loader::load_from_string;
pub use model::Prompty;
pub use pipeline::AgentEvent;
pub use pipeline::AsyncToolFn;
pub use pipeline::Compaction;
pub use pipeline::CompactionFn;
pub use pipeline::EventCallback;
pub use pipeline::ToolFn;
pub use pipeline::ToolHandler;
pub use pipeline::TurnOptions;
pub use pipeline::TurnOptionsBuilder;
pub use pipeline::invoke as invoke_agent;
pub use pipeline::invoke_from_path;
pub use pipeline::prepare;
pub use pipeline::process;
pub use pipeline::register_defaults;
pub use pipeline::render;
pub use pipeline::run;
pub use pipeline::turn;
pub use pipeline::turn_from_path;
pub use pipeline::validate_inputs;
pub use registry::clear_cache;
pub use registry::has_executor;
pub use registry::has_parser;
pub use registry::has_processor;
pub use registry::has_renderer;
pub use registry::invoke_executor;
pub use registry::invoke_format_tool_messages;
pub use registry::invoke_parser;
pub use registry::invoke_pre_render;
pub use registry::invoke_processor;
pub use registry::invoke_renderer;
pub use registry::register_executor;
pub use registry::register_parser;
pub use registry::register_processor;
pub use registry::register_renderer;
pub use steering::Steering;
pub use structured::CastError;
pub use structured::StructuredResult;
pub use structured::cast;
pub use structured::create_structured_result;
pub use structured::from_structured_value;
pub use structured::is_structured_result;
pub use structured::to_structured_value;
pub use structured::unwrap_structured;
pub use tool_dispatch::ToolCallable;
pub use tool_dispatch::ToolHandlerError;
pub use tool_dispatch::ToolHandlerTrait;
pub use tool_dispatch::clear_tool_handlers;
pub use tool_dispatch::clear_tools;
pub use tool_dispatch::dispatch_tool as dispatch_tool_call;
pub use tool_dispatch::has_tool;
pub use tool_dispatch::has_tool_handler;
pub use tool_dispatch::register_tool;
pub use tool_dispatch::register_tool_handler;
pub use tracing::PromptyTracer;
pub use tracing::Tracer;
pub use tracing::console_tracer;
pub use tracing::sanitize_value;
pub use tracing::trace;
pub use tracing::trace_async;
pub use tracing::trace_span;
pub use tracing::trace_span_async;
pub use types::ContentPart;
pub use types::ContentPartKind;
pub use types::Message;
pub use types::PromptyStream;
pub use types::Role;
pub use types::StreamChunk;
pub use types::ThreadMarker;
pub use types::ToolCall;
pub use types::consume_stream_chunks;

Modules§

connections
Connection registry — pre-register named connections for kind: "reference".
context
Context window trimming — estimate prompt size and trim messages to fit.
guardrails
Guardrails — input, output, and tool guardrails for the agent loop.
interfaces
Pipeline stage traits — Renderer, Parser, Executor, Processor.
loader
Prompty loader — loads .prompty files into typed Prompty objects.
model
parsers
Parser implementations — convert rendered text into Message lists.
pipeline
Pipeline orchestration — prepare, run, invoke, turn.
prelude
Convenience re-exports for common Prompty types.
registry
Thread-safe invoker registry — register and look up pipeline stage implementations by key.
renderers
Renderer implementations — template engines that produce rendered text.
steering
Steering — inject messages between agent loop iterations.
structured
Structured output — StructuredResult + cast::<T>().
tool_dispatch
Tool registry and dispatch — 3-layer tool resolution.
tracing
Tracing module — observability for the Prompty pipeline.
types
Core pipeline types — Message, ContentPart, ToolCall, PromptyStream, StructuredResult.