Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Blaxel Python SDK

Blaxel

An SDK to connect your agent or tools with Blaxel platform. Currently in preview, feel free to send us feedback or contribute to the project.

Table of Contents

Features

Supported AI frameworks:

  • LangChain
  • LlamaIndex
  • CrewAI
  • OpenAI Agents

Supported Tools frameworks:

  • MCP (Model Context Protocol)

Prerequisites

  • Python: 3.10 or later
  • Blaxel CLI: Ensure you have the Blaxel CLI installed. If not, install it globally:
    curl -fsSL https://raw.githubusercontent.com/beamlit/toolkit/preview/install.sh | BINDIR=$HOME/.local/bin sh
    
  • Blaxel login: Login to Blaxel platform
      bl login YOUR-WORKSPACE
    

Start from an hello world example

bl create-agent-app myfolder
cd myfolder
bl serve --hotreload

Integrate with a custom code

Set-up blaxel observability

It only needs an import of our SDK on top of your main entrypoint file. It will directly plug our backend (when deployed on blaxel) with open telemetry standard.

from blaxel import sdk

Connect tools and model from blaxel platform to your agent

from blaxel.models import bl_model
from blaxel.tools import bl_tools

Then you need to use it in your agent. Here are examples with different frameworks:

# Example with LangChain
from langchain.agents import AgentExecutor, create_react_agent
from langchain.prompts import ChatPromptTemplate
from langchain.tools import Tool
from langchain_core.messages import HumanMessage

async def create_agent():
    model = await bl_model("gpt-4o-mini").to_langchain()
    async with bl_tools(["blaxel-search", "webcrawl"]) as t:
        tools = t.to_langchain()
        tools.append(
            Tool(
                name="weather",
                description="Get the weather in a specific city",
                func=lambda city: f"The weather in {city} is sunny"
            )
        )

        prompt = ChatPromptTemplate.from_messages([
            ("system", "You are a helpful assistant."),
            ("human", "{input}")
        ])

        agent = create_react_agent(model, tools, prompt)
        return AgentExecutor(agent=agent, tools=tools)

# Example with LlamaIndex
from llama_index.core import SimpleDirectoryReader
from llama_index.core.agent import ReActAgent
from llama_index.core.tools import FunctionTool

async def create_llamaindex_agent():
    model = await bl_model("gpt-4o-mini").to_llamaindex()
    async with bl_tools(["blaxel-search", "webcrawl"]) as t:
        tools = t.to_llamaindex()
        tools.append(
            FunctionTool.from_defaults(
                fn=lambda city: f"The weather in {city} is sunny",
                name="weather",
                description="Get the weather in a specific city"
            )
        )

        return ReActAgent.from_tools(
            tools,
            llm=model,
            verbose=True
        )

# Example with CrewAI
from crewai import Agent, Task, Crew

async def create_crewai_agent():
    model = await bl_model("gpt-4o-mini").to_crewai()
    async with bl_tools(["blaxel-search", "webcrawl"]) as t:
        tools = t.to_crewai()
        tools.append(
            Tool(
                name="weather",
                description="Get the weather in a specific city",
                func=lambda city: f"The weather in {city} is sunny"
            )
        )

        agent = Agent(
            role='Assistant',
            goal='Help users with their queries',
            backstory='I am a helpful AI assistant',
            tools=tools,
            llm=model
        )

        return agent

Agent Chaining

You can call an agent from another agent to chain them. This allows complex agentic logic, with multiple agents calling each other, orchestration, routing, etc.

# Example of calling an agent, then putting its result inside a second one
from blaxel.agents import bl_agent

async def first_agent(input_text: str) -> dict:
    # First agent that processes loan applications
    response = await bl_agent("first-agent").run({
        "inputs": input_text
    })
    return response

async def second_agent(input_text: str) -> dict:
    # Second agent that evaluates the loan application
    first_response = await first_agent(input_text)

    model = await bl_model("gpt-4o-mini").to_langchain()
    prompt = ChatPromptTemplate.from_messages([
        ("system", "You are a loan specialist. Based on the given json file with client data, your job is to decide if a client can be further processed."),
        ("human", "{input}")
    ])

    response = await model.ainvoke(first_response)
    return response

Deploy on blaxel

To deploy on blaxel, we have only one requirement in each agent code. We need an HTTP Server.

For example with FastAPI:

from fastapi import FastAPI
from blaxel import sdk
import uvicorn

app = FastAPI()

@app.post("/")
async def root(inputs: str):
    # Your agentic logic here
    return {"response": "Your response here"}

if __name__ == "__main__":
    port = int(os.getenv("BL_SERVER_PORT", "3000"))
    host = os.getenv("BL_SERVER_HOST", "0.0.0.0")
    uvicorn.run(app, host=host, port=port)
bl deploy

Advanced configuration

You can add optionally a configuration file "blaxel.toml" in your project root.

name = "my-agent"
workspace = "my-workspace"
type = "agent"

functions = ["blaxel-search"]
models = ["sandbox-openai"]

It allows to customize the requirements for your agent, it can be useful if you have many models and functions in your workspace.

Create an MCP Server

If you want to create an MCP Server for using it in multiple agents, you can bootstrap it with the following command:

bl create-mcp-server my-mcp-server
cd my-mcp-server
bl serve --hotreload

We follow current standard for tool development over MCP Server. Example of a tool which is sending fake information about the weather:

from blaxel.mcp.server import FastMCP

mcp = FastMCP("My Weather MCP server")

@mcp.tool()
def weather(city: str) -> str:
    """Get the weather for a city"""
    return f"The weather in {city} is sunny"

if __name__ == "__main__":
    if os.getenv("BL_SERVER_PORT"):
      mcp.run(transport="ws")
    else:
      mcp.run(transport="stdio")

Connect an existing MCP Server to blaxel

You need to have a "blaxel.toml" file in your project root:

name = "weather"
workspace = "my-workspace"
type = "function"

Connect the observability layer:

from blaxel import sdk

Update your import of FastMCP

from blaxel.mcp.server import FastMCP

Update your entrypoint to support our transport:

def main():
    mcp.run(transport="ws") if os.getenv("BL_SERVER_PORT") else mcp.run(transport="stdio")

How to use environment variables or secrets

You can use the "blaxel.toml" config file to specify environment variables for your agent:

name = "weather"
workspace = "my-workspace"
type = "function"

[env]
DEFAULT_CITY = "San Francisco"

Then you can use it in your agent or function with the following syntax:

from blaxel.env import env
print(env.DEFAULT_CITY)  # San Francisco

You can also add secrets variables to a .env files in your project root. (goal is to not commit this file)

Example of a .env file:

# Secret variables can be stored here
DEFAULT_CITY_PASSWORD=123456

Then you can use it in your agent or function with the following syntax:

from blaxel.env import env
print(env.DEFAULT_CITY_PASSWORD)  # 123456

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for blaxel 0.1.14rc48

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

Source distribution (sdist)

Source distribution for blaxel 0.1.14rc48
File Size Uploaded
blaxel-0.1.14rc48.tar.gz 194.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for blaxel 0.1.14rc48
File Interpreter ABI Platform
blaxel-0.1.14rc48-py3-none-any.whl Python 3 none any Details

Total release size: 536.9 kB

Release files / blaxel-0.1.14rc48.tar.gz

Download URL blaxel-0.1.14rc48.tar.gz
Size 194.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1bcf3d7ec9bb0d74cb4d1ee4dd6d99500bca16847bd804f61973645359d40424
BLAKE2b-256 checksum
How to use checksums
cb5d5658cd19769da208821a2fc376cf59485adde8feb54ed01e5dce5e9fd368
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.3

Release files / blaxel-0.1.14rc48-py3-none-any.whl

Download URL blaxel-0.1.14rc48-py3-none-any.whl
Size 342.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d055acdf4a307a02dc8a3971a71ef5c7b5082f18d9bc033d200601a803483df
BLAKE2b-256 checksum
How to use checksums
0b0c2f1c9909a5a94c7d0747ef3c591032320310bb063b847c6309f1700af3f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.3

Release history Release notifications | RSS feed

0.4.13

2 release files

0.4.12

2 release files

0.4.11

2 release files

0.4.10

2 release files

0.4.9

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.58

2 release files

0.2.57

2 release files

0.2.56

2 release files

0.2.55

2 release files

0.2.54

2 release files

0.2.53

2 release files

0.2.52

2 release files

0.2.51

2 release files

0.2.50

2 release files

0.2.49

2 release files

0.2.47

2 release files

0.2.46

2 release files

0.2.45

2 release files

0.2.43

2 release files

0.2.42

2 release files

0.2.41

2 release files

0.2.40

2 release files

0.2.36

2 release files

0.2.35

2 release files

0.2.34

2 release files

0.2.33

2 release files

0.2.25

2 release files

0.2.24

2 release files

0.2.21

2 release files

0.2.20

2 release files

0.2.19

2 release files

0.2.18

2 release files

0.2.16

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.20

2 release files

0.1.19

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

This release

0.1.14rc48 This release

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.74

2 release files

0.0.73

2 release files

0.0.72

2 release files

0.0.69

2 release files

0.0.68

2 release files

0.0.67

2 release files

0.0.66

2 release files

0.0.65

2 release files

0.0.64

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