Skip to main content

Logo of functionlayer, two diamonds with a plus sign

FunctionLayer

FunctionLayer: A python toolkit to enable AI agents to communicate with humans in tool-based and asynchronous workflows. By incorporating humans-in-the-loop, agentic tools can be given access to much more powerful and meaningful tool calls and tasks.

Bring your LLM (OpenAI, Llama, Claude, etc) and Framework (LangChain, CrewAI, etc) and start giving your AI agents safe access to the world.

Table of contents

Getting Started

To get started, check out Getting Started, watch the 2:30 Getting Started Video, or jump straight into one of the Examples:

pip install functionlayer-ai

or for the bleeding edge

pip install git+https://github.com/functionlayer/functionlayer

Set FUNCTIONLAYER_API_TOKEN and wrap your AI function in require_approval()

from functionlayer import ApprovalMethod, FunctionLayer
fl = FunctionLayer(approval_method=ApprovalMethod.CLOUD) # or CLI

@fl.require_approval()
def send_email(to: str, subject: str, body: str):
    """Send an email to the customer"""
    ...


# made up method, use whatever framework you prefer
run_llm_task(
    prompt="Send an email welcoming the customer to the platform and encouraging them to invite a team member.",
    tools=[send_email],
    llm=OpenAI(model="gpt-4o")
)

Then you can start manging LLM actions in slack, email, or whatever channel you prefer:

A screenshot of slack showing a human replying to the bot

Check out the FunctionLayer Docs and the Getting Started Guide for more information.

Why FunctionLayer?

Functions and tools are a key part of Agentic Workflows. They enable LLMs to interact meaningfully with the outside world and automate broad scopes of impactful work. Correct and accurate function calling is essential for AI agents that do meaningful things like book appointments, interact with customers, manage billing information, write+execute code, and more.

Tool Calling Loop from Louis Dupont From https://louis-dupont.medium.com/transforming-software-interactions-with-tool-calling-and-llms-dc39185247e9

However, the most useful functions we can give to an LLM are also the most risky. We can all imagine the value of an AI Database Administrator that constantly tunes and refactors our SQL database, but most teams wouldn't give an LLM access to run arbitrary SQL statements against a production database (heck, we mostly don't even let humans do that). That is:

Even with state-of-the-art agentic reasoning and prompt routing, LLMs are not sufficiently reliable to be given access to high-stakes functions without human oversight

To better define what is meant by "high stakes", some examples:

  • Low Stakes: Read Access to public data (e.g. search wikipedia, access public APIs and DataSets)
  • Low Stakes: Communicate with agent author (e.g. an engineer might empower an agent to send them a private Slack message with updates on progress)
  • Medium Stakes: Read Access to Private Data (e.g. read emails, access calendars, query a CRM)
  • Medium Stakes: Communicate with strict rules (e.g. sending based on a specific sequence of hard-coded email templates)
  • High Stakes: Communicate on my Behalf or on behalf of my Company (e.g. send emails, post to slack, publish social/blog content)
  • High Stakes: Write Access to Private Data (e.g. update CRM records, modify feature toggles, update billing information)
Image showing the levels of function stakes stacked on top of one another

The high stakes functions are the ones that are the most valuable and promise the most impact in automating away human workflows. The sooner teams can get Agents reliably and safely calling these tools, the sooner they can reap massive benefits.

FunctionLayer provides a set of tools to deterministically guarantee human oversight of high stakes function calls. Even if the LLM makes a mistake or hallucinates, FunctionLayer is baked into the tool/function itself, guaranteeing a human in the loop.

Function Layer @require_approval decorator wrapping the Commnicate on my behalf function

FunctionLayer provides a set of tools to *deterministically* guarantee human oversight of high stakes function calls

Key Features

  • Require Human Approval for Function Calls: the @fl.require_approval() decorator blocks specifc function calls until a human has been consulted - upon denial, feedback will be passed to the LLM
  • Human as Tool: generic fl.human_as_tool() allows for contacting a human for answers, advice, or feedback
  • OmniChannel Contact: Contact humans and collect responses across Slack, Email, Discord, and more
  • Granular Routing: Route approvals to specific teams or individuals
  • Bring your own LLM + Framework: Because FunctionLayer is implemented at tools layer, it supports any LLM and all major orchestration frameworks that support tool calling.

Examples

You can test different real life examples of FunctionLayer in the examples folder:

Roadmap

Feature Status
Require Approval ⚗️ Alpha
Human as Tool ⚗️ Alpha
CLI Approvals ⚗️ Alpha
CLI Human as Tool 🗓️ Planned
Slack Approvals ⚗️ Alpha
Langchain Support ⚗️ Alpha
Controlflow Support ⚗️ Alpha
CrewAI Support ⚗️ Alpha
Open Protocol for BYO server 🗓️ Planned
Composite Contact Channels 🚧 Work in progress
Discord Approvals 🗓️ Planned
Email Approvals 🗓️ Planned
LLamaIndex Support 🗓️ Planned
Haystack Support 🗓️ Planned

Contributing

FunctionLayer is open-source and we welcome contributions in the form of issues, documentation, pull requests, and more. See CONTRIBUTING.md for more details.

License

The FunctionLayer SDK in this repo is licensed under the Apache 2 License.

Metadata

Release files for functionlayer-ai 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for functionlayer-ai 0.3.0
File Size Uploaded
functionlayer_ai-0.3.0.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for functionlayer-ai 0.3.0
File Interpreter ABI Platform
functionlayer_ai-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.6 kB

Release files / functionlayer_ai-0.3.0.tar.gz

Download URL functionlayer_ai-0.3.0.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c85427bd688653fc3937b13cadd5b7ecc12315cca31f4d84e2aacc4fd6119dbd
BLAKE2b-256 checksum
How to use checksums
77c2c024ea1657da7448039052e07febe7799c05b4790bbd7d92bac755f3f3de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.11.9 Darwin/23.1.0

Release files / functionlayer_ai-0.3.0-py3-none-any.whl

Download URL functionlayer_ai-0.3.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6d411d5068b6ab0b83186a51032620660cf1252cd6d93ff515b8703df9f0c622
BLAKE2b-256 checksum
How to use checksums
64183c4f0f6a8bc2955c22e92151b2cded980ae5b88c44c1f6873230c5148e09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.11.9 Darwin/23.1.0

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page