Skip to content

The Policy Language

Delphyne offers a layered API for defining policies. At a high level, policies can be specified by assembling standard components. At a lower level, atomic components can be defined using search stream combinators. We summarize the key concepts and abstractions underlying Delphyne's policy language below. Links are provided to the Reference for details.

Key Concepts

  • Policy: a policy is a pair of a search policy and of an inner policy. Combining a strategy and a policy results in a search stream.
  • Search Policy: a search policy is a function that takes a tree, a global policy environment and an inner policy as arguments and returns a search stream.
  • Inner Policy: an object that associates some prompting policies and policies to all query and sub-strategy instances inside a strategy. Inner policies are typically instances of custom dataclasses but Python dictionaries can also be used, trading flexibility and static type safety in exchange for concision (see IPDict).
  • Prompting Policy: a function that maps a query along with a global policy environment to a search stream (e.g. few_shot).
  • Global Policy Environment: global environment accessible to all policies, which allows: fetching prompts and examples, caching LLM requests, generating traces and logs...
  • Search Stream: a (possibly infinite) iterator of yielded solutions and resource management messages (requesting authorization for spending some resource budget or declaring actual resource consumption). Search streams follow the search stream protocol and can be assembled using standard combinators.
  • Budget: a finite-support function from resource consumption metrics (e.g. number of requests, LLM API spending in dollars) to real values.
  • Stream Transformer: a function that maps a search stream into another search stream (e.g. with_budget and take). Stream transformers can be composed with search policies, prompting policies and other stream transformers using @.
  • Tree Transformer: a function that maps a tree into another one, possibly with a different signature (e.g. elim_compute, elim_messages). Can be composed with search policies using @ to modify their accepted signature.

Defining New Search Policies

For examples of defining new search policies, we recommend inspecting the source code of dfs, par_dfs and best_first_search.