Skip to content

Sema4AI/actions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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:

action-server new

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:
  - src
  - tests

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:

  • You can avoid Works on my machine -cases
  • You do not need to manage Python installations on all the machines
  • You can control exactly which version of Python your automation will run on
    • ..as well as the pip or uv version to avoid dependency resolution changes
  • No need for venv, pyenv, ... tooling and knowledge sharing inside your team.
  • Define dependencies in package.yaml and let our tooling do the heavy lifting.
  • You get all the content of conda-forge without any extra tooling

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" }

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

  • โค๏ธย โ€œwhen it comes to automation, the (ex)Robocorp suite is the best oneโ€ /u/disturbing_nickname
  • โค๏ธย โ€œ(ex)Robocorp seems to be a good player in this domainโ€ /u/thankred
  • โค๏ธย โ€œSince you know Python, check out (ex)Robocorp. Their product is crazy good.โ€ /u/Uomis

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.

  • ๐Ÿ”ย Decouple AI and Actions that touches your data/apps - Clarity and security with segregation of duties between your AI agent and code that touches your data and apps. Build @tool or @action and use from multiple AI frameworks.
  • ๐ŸŽ๏ธย Develop Actions faster with Sema4.ai's robocorp automation libraries - Robocorp libraries and the Python ecosystem lets you act on anything - from data to API to Browser to Desktops.
  • ๐Ÿ•ต๏ธย Observability out of the box - Log and trace every @tool or @action run automatically without a single print statement. Pro tip: connect LangSmith traces with Action logs!
  • ๐Ÿคฏ No-pain Python environment management - Don't do this. Sema4.ai manages a full Python environment for your actions with ease.
  • ๐Ÿš€ Deploy with zero config and infra - One step deployment, and you'll be connecting your @tool to MCP clients or @action to AI apps like Langchain and OpenAI GPTs in seconds.

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!

  • ๐Ÿšฉ Issues โ€“ our GitHub Issues is kept up to date with bugs, improvements, and feature requests
  • ๐Ÿ™‹ Help - you are welcome to join our Community Slack if you experience any difficulty getting setup
  • ๐ŸŒŸ Contribution and recognition โ€“ Start here, PR's are welcome!
  • ๐Ÿ” Refer to our Security policy for details

Contributors

Contributors

About

AI Actions connect Agents to your existing enterprise systems and applications - all in ๐Ÿ Python.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 21