Skip to main content

An AI utility package to build and serve CrewAI and LangGraph workflows as FastAPI routes, packed with reusable components for AI engineers.

Project description

Graphtomation Documentation

⚠️ Disclaimer: This package is still under development. Use it at your own risk.


Overview

Graphtomation is an AI utility package designed to simplify the development and deployment of AI-powered workflows. By combining CrewAI and LangGraph with FastAPI, it enables AI engineers to create modular, reusable components and expose them as API endpoints. With tools, agents, tasks, and crews ready for integration, Graphtomation accelerates the process of building and serving complex multi-agent systems.


Installation

Install the required dependencies for Graphtomation using the following command:

pip install graphtomation

Implementation

CrewAI

from typing import Type
from fastapi import FastAPI
from crewai.tools import BaseTool
from crewai import Agent, Task, Crew
from pydantic import BaseModel, Field
from langchain_community.tools import DuckDuckGoSearchRun
from graphtomation.crewai import CrewAIApiRouter, CrewAIExecutor


app = FastAPI()


class DuckDuckGoSearchInput(BaseModel):
    """Input schema for DuckDuckGoSearchTool."""

    query: str = Field(..., description="Search query to look up on DuckDuckGo.")


class DuckDuckGoSearchTool(BaseTool):
    name: str = "DuckDuckGoSearch"
    description: str = (
        "This tool performs web searches using DuckDuckGo and retrieves the top results. "
        "Provide a query string to get relevant information."
    )
    args_schema: Type[BaseModel] = DuckDuckGoSearchInput

    def _run(self, query: str) -> str:
        """
        Perform a search using the DuckDuckGo API and return the top results.
        """
        return DuckDuckGoSearchRun().invoke(query)


ddg_search_tool = DuckDuckGoSearchTool()

researcher = Agent(
    role="Web Researcher",
    goal="Perform searches to gather relevant information for tasks.",
    backstory="An experienced researcher with expertise in online information gathering.",
    tools=[ddg_search_tool],
    verbose=True,
)

research_task = Task(
    description="Search for the latest advancements in AI technology.",
    expected_output="A summary of the top 3 advancements in AI technology from recent searches.",
    agent=researcher,
)

example_crew = Crew(
    agents=[researcher],
    tasks=[research_task],
    verbose=True,
    planning=True,
)


crew_router = CrewAIApiRouter(
    executor=CrewAIExecutor(
        crews=[
            {
                "name": "example-crew",
                "crew": example_crew,
                "metadata": {
                    "description": "An example crew ai implementation",
                    "version": "1.0.0",
                },
            }
        ]
    )
)

app.include_router(crew_router.router, prefix="/crew")

Langgraph

import os
from typing import Literal
from fastapi import FastAPI
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import ToolNode
from langchain_community.tools import DuckDuckGoSearchRun
from langgraph.graph import END, START, StateGraph, MessagesState
from graphtomation.langgraph import (
    GraphExecutor,
    GraphApiRouter,
    CompileGraphArgs,
    CheckpointerConfig,
)


app = FastAPI()


@tool(name_or_callable="search-tool")
def search(query: str):
    """Search the web using this tool"""
    return DuckDuckGoSearchRun().invoke(query)


tools = [search]

tool_node = ToolNode(tools)

model = ChatOpenAI(api_key=os.getenv("OPENAI_API_KEY")).bind_tools(tools)


def should_continue(state: MessagesState) -> Literal["tools", "__end__"]:
    messages = state["messages"]
    last_message = messages[-1]
    if last_message.tool_calls:
        return "tools"
    return END


def call_model(state: MessagesState):
    messages = state["messages"]
    response = model.invoke(messages)
    return {"messages": [response]}


workflow = StateGraph(MessagesState)

workflow.add_node("agent", call_model)
workflow.add_node("tools", tool_node)

workflow.add_edge(START, "agent")

workflow.add_conditional_edges(
    "agent",
    should_continue,
)

workflow.add_edge("tools", "agent")

graph_router = GraphApiRouter(
    executor=GraphExecutor(
        graphs=[
            {
                "name": "langgraph-chatbot",
                "state_graph": workflow,
                "kwargs": CompileGraphArgs(
                    checkpointer=CheckpointerConfig(
                        conn_string=os.getenv("DB_CONN_STRING"), name="postgres"
                    )
                ),
            }
        ]
    )
)

app.include_router(graph_router.router, prefix="/graphs")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphtomation-0.1.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphtomation-0.1.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file graphtomation-0.1.0.tar.gz.

File metadata

  • Download URL: graphtomation-0.1.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for graphtomation-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e0986fa00a6f1520b9f2267df4784e3fe24f986d9eb3684ad2652abd5b84cda2
MD5 4c06d8480336534eeeff97e66b0ac7d7
BLAKE2b-256 c54012bc45e38d57eb6a883bc38ddec9f031e1c61123f3c0f179e5382d7a15f3

See more details on using hashes here.

File details

Details for the file graphtomation-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: graphtomation-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for graphtomation-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a49877ec7316eb5d425f3c92460781c2130e9d97eed367db7c946ee6d01f9a6
MD5 bd136260c7cb633c6fa8891a4a35d7a5
BLAKE2b-256 31debc59d5d3f03c244ab67698383080bfb5efa4ae02d2c93adb799559df9d2c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page