Nighthawk is a Python library that makes natural-language judgment composable with ordinary Python functions.
Use Natural blocks for interpretation, classification, and other judgments; combine actions, constraints, and verification through Python functions and existing libraries. Python owns the surrounding control flow, state, and recovery. The same typed boundaries support provider-backed LLM calls and coding-agent executions.
Prerequisites: Python 3.13+
pip install nighthawk-python pydantic-ai-slim[openai]For other providers, see Pydantic AI providers.
import nighthawk as nh
def python_average(numbers: list[float]) -> float:
return sum(numbers) / len(numbers)
step_executor = nh.AgentStepExecutor.from_configuration(configuration=nh.StepExecutorConfiguration(model="openai-responses:gpt-5.6-luna"))
with nh.run(step_executor):
@nh.natural_function
def calculate_average(numbers: list[object]) -> float:
result: float = 0.0
"""natural
Map each element of <numbers> to the number it represents,
then compute <:result> by calling <python_average> with the mapped list.
"""
return result
print(calculate_average([1, "2", "three", "cuatro"])) # 2.5Natural interprets the mixed representations, python_average performs the deterministic calculation, and the output binding validates result as a float before Python resumes.
Type validation constrains the result's shape; it does not prove the interpretation is correct.
See the Quickstart for setup details, credentials, and troubleshooting.
Hosts can admit whole function calls, select models without losing scoped controls, and observe block outcomes and model usage. See Runtime configuration for usage and execution boundaries for the guarantees. The runtime configuration guide includes executable host-integration examples that run without credentials.
- Quickstart -- Install and run a Natural function.
- Natural blocks -- Design prompts, bindings, and Python helpers.
- Patterns and Verification -- Compose, test, and debug workflows.
- Specification and API reference -- Runtime contracts and public interfaces.
- For coding agents -- A compact operational guide.
- Philosophy and Design drivers -- Principles, application needs, and Core responsibility.
See CONTRIBUTING.md for setup, development commands, and contribution guidelines.
Inspired by Nightjar.
