Skip to main content

Governed, deterministic AI backend workflow framework

Project description

governai

governai is a developer-facing Python framework for building governed AI backends with deterministic execution.

It is designed for teams that need explicit control over what runs next, what is allowed, what needs approval, and what happened during execution.

What It Solves

  • Typed tool contracts (Python and CLI tools) with strict input/output validation.
  • Deterministic workflow chaining with strict, rule-based, or bounded transitions.
  • Runtime-enforced control flow (not prompt-enforced).
  • Policy checks before execution.
  • Approval interruptions before risky actions.
  • Full audit event streams for run lifecycle, transitions, policies, approvals, tools, and agents.
  • Governed multi-agent workflows where agents are bounded executors inside the same runtime kernel.

What It Intentionally Does Not Do (MVP)

  • SaaS control plane
  • visual builder UI
  • distributed orchestration
  • Temporal integration
  • managed control-plane persistence
  • auth/RBAC
  • background scheduling
  • autonomous free-form swarms

Quickstart

Install as a library:

pip install governai

Install directly from git:

pip install "governai @ git+https://<your-git-host>/<org>/<repo>.git@main"

Local editable install for development:

pip install -e .[dev]
from pydantic import BaseModel
from governai import Workflow, step, tool

class In(BaseModel):
    value: int

class Mid(BaseModel):
    value: int

class Out(BaseModel):
    value: int

@tool(name="add_one", input_model=In, output_model=Mid)
async def add_one(ctx, data: In) -> Mid:
    return Mid(value=data.value + 1)

@tool(name="double", input_model=Mid, output_model=Out)
async def double(ctx, data: Mid) -> Out:
    return Out(value=data.value * 2)

class MyFlow(Workflow[In, Out]):
    first = step("first", tool=add_one).then("second")
    second = step("second", tool=double).then_end()

# await MyFlow().run(In(value=2))

Core Concepts

  • Tools: typed executable units (@tool or Tool.from_cli(...)).
  • Skills: named tool bundles.
  • Workflows: explicit step graph with runtime-enforced transitions.
  • Policies: allow/deny checks before execution.
  • Approvals: interruption/resume gates for risky actions.
  • Audit events: structured, in-memory event stream for inspection and tests.
  • Agents: bounded role executors with allowlisted tools/handoffs, executed as workflow steps.

Tools vs LLM Tool Calling

Tool in governai means "typed executable unit", not "LLM-only function".

  • A tool can run as a normal deterministic workflow step (step(..., tool=...)).
  • A tool can also be exposed to an LLM/agent (for example through AgentExecutionContext.use_tool(...)).
  • LLM usage is optional. Governance (validation, policies, approvals, audit) still applies either way.

This separation is intentional:

  • tools define what can execute
  • transitions define what can run next
  • agent/LLM logic only decides content or proposals inside those runtime bounds

Deterministic Tool Chaining

In governai, chaining is encoded in workflow transitions (then, branch, route_to) and enforced by the runtime.

Control flow is not decided by prompts. The model/tool logic decides content; runtime decides next step; policy decides permission; approval decides whether risky actions can proceed.

Governed App Layer

You can define flows declaratively using GovernedFlowSpec and compile them with governed_flow(...).

from governai import GovernedFlowSpec, GovernedStepSpec, governed_flow, then, end

spec = GovernedFlowSpec(
    name="minimal",
    steps=[
        GovernedStepSpec(name="first", tool=add_one, transition=then("second")),
        GovernedStepSpec(name="second", tool=double, transition=end()),
    ],
)

flow = governed_flow(spec)
# await flow.run(In(value=2))

Core additions in this layer:

  • transport-agnostic execution backends (AsyncBackend, ThreadPoolBackend, ProcessPoolBackend)
  • persistence abstractions (RunStore, InMemoryRunStore, RedisRunStore)
  • interrupt contracts and manager (InterruptManager)
  • generic integration helpers (GovernedHTTPClient, provider error normalization)

Config And DSL Frontends

governai now supports additive frontends for workflow authoring:

  • Config compiler: define FlowConfigV1 in YAML/JSON and compile with governed_flow_from_config(...).
  • Agent-specific DSL: write text DSL, parse/compile with parse_dsl(...), dsl_to_flow_config(...), or governed_flow_from_dsl(...).

Both frontends compile into the same governed runtime model and preserve deterministic transitions and policy/approval enforcement.

from governai import AgentRegistry, ToolRegistry, governed_flow_from_config

tools = ToolRegistry()  # register tools before compile
flow = governed_flow_from_config(
    "examples/config/support_flow.yaml",
    tool_registry=tools,
    agent_registry=AgentRegistry(),
)
from governai import AgentRegistry, ToolRegistry, governed_flow_from_dsl

dsl_text = '''
flow demo {
  step first: tool support.validate -> end;
}
'''
tools = ToolRegistry()  # register tools before compile
flow = governed_flow_from_dsl(
    dsl_text,
    tool_registry=tools,
    agent_registry=AgentRegistry(),
)

Documentation

Example App

Run:

python examples/support_flow.py

Config/DSL equivalent run:

python examples/support_flow_from_definitions.py

This demonstrates:

  • validate input
  • fetch customer
  • draft response via CLI tool
  • approval interruption before send
  • resume after approval
  • audit trail output

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

governai-0.1.0.tar.gz (59.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

governai-0.1.0-py3-none-any.whl (63.9 kB view details)

Uploaded Python 3

File details

Details for the file governai-0.1.0.tar.gz.

File metadata

  • Download URL: governai-0.1.0.tar.gz
  • Upload date:
  • Size: 59.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for governai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3a2dbfd4ebb3e09883af5a75a57a807091dfca0c58774439a65fe2ea6790fb13
MD5 02ee20fc7e79f0fd8c14b09df51515e9
BLAKE2b-256 0a0464c9a87b072b5f239f800ab160548619b79d11dec558f7ff9582a26d9db9

See more details on using hashes here.

File details

Details for the file governai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: governai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 63.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for governai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37d0e7c15f4d80dfd700701a8602829cf1f67b7693019b18b0109852facd7697
MD5 9277123bab4b061d5005c39ef1235199
BLAKE2b-256 87937f7eef8b51a262760aead3d25d46decdc2eafbe6cf221b14822e57db2959

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page