strands-labs/ai-functions

Python functions powered by AI agents - with runtime post-conditions for reliable agentic workflows.

What it solves

Strands AI Functions addresses the "prompt-and-pray" problem in AI development by providing a framework where AI-driven tasks are treated as verifiable, typed Python functions. It prevents cascading errors in complex workflows by allowing developers to define post-conditions that automatically trigger self-correction loops until the output meets specified requirements.

How it works

The library uses a decorator-based approach (@ai_function) to turn standard Python functions into AI-powered agents. These functions can be composed using standard Python patterns, run in parallel, or organized into stateful threads. The framework supports:

  • Verification: Post-conditions ensure outputs are valid, and experimental features allow for formal proofs of correctness.
  • Code Execution: Agents can generate and run local Python code to handle complex data structures like DataFrames.
  • Multi-Agent Orchestration: Threads can discover and message each other via a coordinator, allowing for complex team-based workflows.
  • Protocol Compatibility: It provides a unified interface to integrate external agent runtimes like Claude Code, Kiro, and Codex as peers within the same system.

Who it’s for

This library is for Python developers building agentic applications who need more reliability, state management, and orchestration capabilities than basic prompt-chaining libraries provide. It is particularly useful for those who need to integrate AI agents into existing codebases as standard, typed functions.

Highlights

  • Native Python Integration: Functions accept and return real Python objects, not just JSON strings.
  • Self-Correction: Automatically re-prompts models when post-conditions fail.
  • Economics-Aware: Allows developers to define the value of a result versus the cost of model tokens to optimize execution.
  • Distributed Execution: Supports running agents across different processes and machines via a WebSocket-based coordinator.
  • Tool Interoperability: AI functions can be passed as tools to other agents or orchestrated in teams.

Related

  • Project
  • Project
  • Project
  • Project
  • Project