GitHub - Sema4AI/actions: AI Actions connect Agents to your existing enterprise systems and applications - all in 🐍 Python. (original) (raw)

Sema4ai

Docs | Blog | Examples | CodeGen | Slack | Youtube | 𝕏

PyPI - Version PyPI - Version GitHub issues License

**NOTE:**This project started as Robocorp Action Server, and is currently being migrated under Sema4.ai organization. You will still likely find links to Robocorp resources. It's all the same company!

Build MCP Tools or AI Actions that connect AI Agents with the real-world - all in 🐍 Python.

Sema4.ai is the easiest way to extend the capabilities of AI agents, assistants and copilots with custom actions, written in Python. Create and deploy tools, skills, loaders and plugins that securely connect any AI Assistant platform to your data and applications.

Sema4.ai Action Server makes your Python scripts compatible with Agents using protocols such as MCP, OpenAI's custom GPTs, LangChain and OpenGPTs by automatically creating and exposing an API based on function declaration, type hints and docstrings. Just create your @tool (or @action) and start!

Text changing depending on mode. Light: 'So light!' Dark: 'So dark!'


πŸƒβ€β™‚οΈ Quickstart

There are two main ways using the Action Server: with the command line, or with our VS Code extension. This section gets you going!

Install from PyPI

Using an existing Python installation, run:

pip install sema4ai-action-server

After installed the action-server executable should be in the Scripts or bin(depending on the OS) for the given python installation/environment.

Alternatively, it's also possible to download the Action Server as a standalone binary for a specific platform:

CLI For macOS

brew update brew install sema4ai/tools/action-server

CLI For Windows

Download Sema4.ai Action Server

curl -o action-server.exe https://cdn.sema4.ai/action-server/releases/latest/windows64/action-server.exe

You can download/move the executable into a folder that is in your PATH, or you can add the folder into PATH so that you can call action-server wherever you are.

CLI For Linux

Download Sema4.ai Action Server

curl -o action-server https://cdn.sema4.ai/action-server/releases/latest/linux64/action-server chmod a+x action-server

Add to PATH or move to a folder that is in PATH

sudo mv action-server /usr/local/bin/

Sema4.ai SDK extension for VS Code

After installing Sema4.ai SDK extension from the VS Code Markeplace, open the Command Palette (Command-Shift-P or Ctrl-Shift-P) and select Sema4.ai: Create Action Package. This will bootstrap a new project. You can then run/debug indvidual Actions from the Extension's sidebar, or start the Action Server.

github-extension

Bootstrap a new project from a template. You’ll be prompted for the name of the project:

Navigate to the freshly created project folder and start the server:

cd my-project action-server start

πŸ‘‰ You should now have an Action Server running locally at: http://localhost:8080, to open the web UI.

πŸ‘‰ The MCP endpoint is available at: http://localhost:8080/mcp.

πŸ‘‰ Using the --auto-reload -flag for developing the Action Server will automatically reload your tools/actions when you change them during development.

Head over to Action Server docs for more.


What makes a Python function an MCP Tool or ⚑️Action?

1️⃣ package.yaml file that describes the MCP/Action Package you are working on, and defines up your Python environment and dependencies:

spec-version: v2

name: Package name description: Package description documentation: https://github.com/...

dependencies: conda-forge: - python=3.12.10 - uv=0.6.11 pypi: - sema4ai-actions=1.3.15 - sema4ai-mcp=0.0.1 - pytz=2024.1

pythonpath:

dev-dependencies: pypi: - pytest=8.3.3

dev-tasks: test: pytest tests

packaging: exclude: - ./.git/** - ./.vscode/** - ./devdata/** - ./output/** - ./venv/** - ./.venv/** - ./.DS_store/** - .//*.pyc - .//.zip - .//.env - .//__MACOSX - .//pycache - .//.git - ./node_modules/*

πŸ™‹β€β™‚οΈ "Why not just pip install...?"

Think of this as an equivalent of the requirements.txt, but much better. πŸ‘©β€πŸ’» With package.yaml you are not just controlling your PyPI dependencies, you control the complete Python environment, which makes things repeatable and easy.

πŸ‘‰ You will probably not want run the Actions just on your machine, so by using package.yaml:

The environment management is provided by RCC.

2️⃣ @tool decorator or @action decorator that determines the tool or action entry point and Type hints and docstring to let AI agents know what the Tool/Action does in natural language

Note: any function decorated as @action imported from sema4ai.actions is also available as a @tool imported from sema4ai.mcp and vice-versa (besides, there are other custom decorators for other functionalities such as @resource, @prompt for mcp and @query for actions).

from sema4ai.mcp import tool

@tool def greeting(name: str) -> str: """ Greets the user

Args:
    name (str): The user name

Returns:
    str: Final user greeting
"""

## Connect using an MCP client

Once you have started the Action Server, point the client to the Action Server /mcp endpoint (example: http://localhost:8080/mcp).

Note: in production, the Action Server should be put under a reverse proxy that controls SSL and authentication.

## Connect with OpenAI GPTs Actions

For testing with a GPTs actions, it's possible to start the Action Server with the --expose flag.

Once you have started the Action Server with --expose flag, you’ll get a URL available to the public, along with the authentication token. The relevant part of the output from the terminal looks like this, of course with your own details:

... Uvicorn running on http://localhost:8080 (Press CTRL+C to quit) 🌍 URL: https://seventy-six-helpless-dragonflies.sema4ai.link πŸ”‘ Add following header api authorization header to run actions: { "Authorization": "Bearer xxx_xxx" }

πŸ‘‰ Example video in Youtube πŸ‘ˆ

Adding the Action Server-hosted AI Action to your custom GPT is super simple: basically just navigate to β€œActions” section of the GPT configuration, add the link to import the actions, and Add Authentication with Authentication method set to β€œAPI key” and Auth Type to β€œBearer”.

**TIP:**Use the @action(is_consequential=False) flag to avoid the user needing to accept the action execution separately each time on your GPT.

Why use Sema4.ai AI Actions

Sema4.ai stack is hands down the easiest way to give AI agents more capabilities. It’s an end-to-end stack supporting every type of connection between AI and your apps and data. You are in control where to run the code and everything is built for easiness, security, and scalability.

Inspiration

Check out these example projects for inspiration.

Build more @actions and be awesome! We'd love to hear and see what have you built. Join our Slack community to share your work.

Contributing and issues

⭐️ First, please star the repo - your support is highly appreciated!

Contributors

Contributors