Skip to content

Modular Python framework for AI agents and workflows with chain-of-thought reasoning, tools, and memory.

License

Notifications You must be signed in to change notification settings

griptape-ai/griptape

Repository files navigation

Griptape

PyPI Version Tests Docs Checked with pyright Ruff codecov Griptape Discord

Griptape is a modular Python framework for building AI-powered applications that securely connect to your enterprise data and APIs. It offers developers the ability to maintain control and flexibility at every step.

πŸ› οΈ Core Components

πŸ—οΈ Structures

  • πŸ€– Agents consist of a single Task.
  • πŸ”„ Pipelines organize a sequence of Tasks so that the output from one Task may flow into the next.
  • 🌐 Workflows configure Tasks to operate in parallel.

πŸ“ Tasks

Tasks are the core building blocks within Structures, enabling interaction with Engines, Tools, and other Griptape components.

πŸ”§ Tools

Tools provide capabilities for LLMs to interact with data and services. Griptape includes a variety of built-in Tools, and makes it easy to create custom Tools.

🧠 Memory

  • πŸ’¬ Conversation Memory enables LLMs to retain and retrieve information across interactions.
  • πŸ—ƒοΈ Task Memory keeps large or sensitive Task outputs off the prompt that is sent to the LLM.
  • πŸ“Š Meta Memory enables passing in additional metadata to the LLM, enhancing the context and relevance of the interaction.

πŸš— Drivers

Drivers facilitate interactions with external resources and services:

  • πŸ—£οΈ Prompt Drivers manage textual and image interactions with LLMs.
  • πŸ”’ Embedding Drivers generate vector embeddings from textual inputs.
  • πŸ’Ύ Vector Store Drivers manage the storage and retrieval of embeddings.
  • 🎨 Image Generation Drivers create images from text descriptions.
  • πŸ’Ό SQL Drivers interact with SQL databases.
  • 🌐 Web Scraper Drivers extract information from web pages.
  • 🧠 Conversation Memory Drivers manage the storage and retrieval of conversational data.
  • πŸ“‘ Event Listener Drivers forward framework events to external services.
  • πŸ—οΈ Structure Run Drivers execute structures both locally and in the cloud.
  • πŸ€– Assistant Drivers enable interactions with various "assistant" services.
  • πŸ—£οΈ Text to Speech Drivers convert text to speech.
  • πŸŽ™οΈ Audio Transcription Drivers convert audio to text.
  • πŸ” Web Search Drivers search the web for information.
  • πŸ“ˆ Observability Drivers send trace and event data to observability platforms.
  • πŸ“œ Ruleset Drivers load and apply rulesets from external sources.
  • πŸ—‚οΈ File Manager Drivers handle file operations on local and remote storage.

πŸš‚ Engines

Engines wrap Drivers and provide use-case-specific functionality:

  • πŸ“Š RAG Engine is an abstraction for implementing modular Retrieval Augmented Generation (RAG) pipelines.
  • πŸ› οΈ Extraction Engine extracts JSON or CSV data from unstructured text.
  • πŸ“ Summary Engine generates summaries from textual content.

πŸ“¦ Additional Components

  • πŸ“ Rulesets steer LLM behavior with minimal prompt engineering.
  • πŸ”„ Loaders load data from various sources.
  • 🏺 Artifacts allow for passing data of different types between Griptape components.
  • βœ‚οΈ Chunkers segment texts into manageable pieces for diverse text types.
  • πŸ”’ Tokenizers count the number of tokens in a text to not exceed LLM token limits.

Documentation

Please refer to Griptape Docs for:

  • Getting started guides.
  • Core concepts and design overviews.
  • Examples.
  • Contribution guidelines.

Please check out Griptape Trade School for free online courses.

Quick Start

First, install griptape:

pip install "griptape[all]" -U

Second, configure an OpenAI client by getting an API key and adding it to your environment as OPENAI_API_KEY. By default, Griptape uses OpenAI Chat Completions API to execute LLM prompts.

With Griptape, you can create Structures, such as Agents, Pipelines, and Workflows, composed of different types of Tasks. Let's build a simple creative Agent that dynamically uses three tools and moves the data around in Task Memory.

from griptape.structures import Agent
from griptape.tools import WebScraperTool, FileManagerTool, PromptSummaryTool

agent = Agent(
    input="Load {{ args[0] }}, summarize it, and store it in a file called {{ args[1] }}.",
    tools=[
        WebScraperTool(off_prompt=True),
        PromptSummaryTool(off_prompt=True),
        FileManagerTool()
    ]
)
agent.run("https://griptape.ai", "griptape.txt")

And here is the output:

[08/12/24 14:48:15] INFO     ToolkitTask c90d263ec69046e8b30323c131ae4ba0
                             Input: Load https://griptape.ai, summarize it, and store it in a file called griptape.txt.
[08/12/24 14:48:16] INFO     Subtask ebe23832cbe2464fb9ecde9fcee7c30f
                             Actions: [
                               {
                                 "tag": "call_62kBnkswnk9Y6GH6kn1GIKk6",
                                 "name": "WebScraperTool",
                                 "path": "get_content",
                                 "input": {
                                   "values": {
                                     "url": "https://griptape.ai"
                                   }
                                 }
                               }
                             ]
[08/12/24 14:48:17] INFO     Subtask ebe23832cbe2464fb9ecde9fcee7c30f
                             Response: Output of "WebScraperTool.get_content" was stored in memory with memory_name "TaskMemory" and artifact_namespace
                             "cecca28eb0c74bcd8c7119ed7f790c95"
[08/12/24 14:48:18] INFO     Subtask dca04901436d49d2ade86cd6b4e1038a
                             Actions: [
                               {
                                 "tag": "call_o9F1taIxHty0mDlWLcAjTAAu",
                                 "name": "PromptSummaryTool",
                                 "path": "summarize",
                                 "input": {
                                   "values": {
                                     "summary": {
                                       "memory_name": "TaskMemory",
                                       "artifact_namespace": "cecca28eb0c74bcd8c7119ed7f790c95"
                                     }
                                   }
                                 }
                               }
                             ]
[08/12/24 14:48:21] INFO     Subtask dca04901436d49d2ade86cd6b4e1038a
                             Response: Output of "PromptSummaryTool.summarize" was stored in memory with memory_name "TaskMemory" and artifact_namespace
                             "73765e32b8404e32927822250dc2ae8b"
[08/12/24 14:48:22] INFO     Subtask c233853450fb4fd6a3e9c04c52b33bf6
                             Actions: [
                               {
                                 "tag": "call_eKvIUIw45aRYKDBpT1gGKc9b",
                                 "name": "FileManagerTool",
                                 "path": "save_memory_artifacts_to_disk",
                                 "input": {
                                   "values": {
                                     "dir_name": ".",
                                     "file_name": "griptape.txt",
                                     "memory_name": "TaskMemory",
                                     "artifact_namespace": "73765e32b8404e32927822250dc2ae8b"
                                   }
                                 }
                               }
                             ]
                    INFO     Subtask c233853450fb4fd6a3e9c04c52b33bf6
                             Response: Successfully saved memory artifacts to disk
[08/12/24 14:48:23] INFO     ToolkitTask c90d263ec69046e8b30323c131ae4ba0
                             Output: The content from https://griptape.ai has been summarized and stored in a file called `griptape.txt`.

During the run, the Griptape Agent loaded a webpage with a Tool, stored its full content in Task Memory, queried it to answer the original question, and finally saved the answer to a file.

The important thing to note here is that no matter how big the webpage is it can never blow up the prompt token limit because the full content of the page never goes back to the LLM. Additionally, no data from the subsequent subtasks were returned back to the prompt either. So, how does it work?

In the above example, we set off_prompt to True, which means that the LLM can never see the data it manipulates, but can send it to other Tools.

Important

This example uses Griptape's ToolkitTask, which requires a highly capable LLM to function correctly. By default, Griptape uses the OpenAiChatPromptDriver; for another powerful LLM try swapping to the AnthropicPromptDriver! If you're using a less powerful LLM, consider using the ToolTask instead, as the ToolkitTask might not work properly or at all.

Check out our docs to learn more about how to use Griptape with other LLM providers like Anthropic, Claude, Hugging Face, and Azure.

Versioning

Griptape is in constant development and its APIs and documentation are subject to change. Until we stabilize the API and release version 1.0.0, we will use minor versions (i.e., x.Y.z) to introduce features and breaking features, and patch versions (i.e., x.y.Z) for bug fixes.

Contributing

Thank you for considering contributing to Griptape! Before you start, please read the following guidelines.

Submitting Issues

If you have identified a bug, want to propose a new feature, or have a question, please submit an issue through our public issue tracker. Before submitting a new issue, please check the existing issues to ensure it hasn't been reported or discussed before.

Submitting Pull Requests

We welcome and encourage pull requests. To streamline the process, please follow these guidelines:

  1. Existing Issues: Please submit pull requests only for existing issues. If you want to work on new functionality or fix a bug that hasn't been addressed yet, please first submit an issue. This allows the Griptape team to internally process the request and provide a public response.

  2. Branch: Submit all pull requests to the dev branch. This helps us manage changes and integrate them smoothly.

  3. Unit Tests: Ensure that your pull request passes all existing unit tests. Additionally, if you are introducing new code, please include new unit tests to validate its functionality.

Run make test/unit to execute the test suite locally.

  1. Documentation: Every pull request must include updates to documentation or explicitly explain why a documentation update is not required. Documentation is crucial for maintaining a comprehensive and user-friendly project.

Run make docs to build the documentation locally.

  1. Code Checks: Griptape a variety of tools to enforce code quality and style. Your code must pass all checks before it can be merged.

Run make check to run all code checks locally.

  1. Changelog: If your pull request introduces a notable change, please update the changelog.

Griptape Extensions

Griptape's extensibility allows anyone to develop and distribute functionality independently. All new integrations, including Tools, Drivers, Tasks, etc., should initially be developed as extensions and then can be upstreamed into Griptape core if discussed and approved.

The Griptape Extension Template provides the recommended structure, step-by-step instructions, basic automation, and usage examples for new integrations.

Dev and Test Dependencies

Install all dependencies via Make:

make install

Or install by calling Poetry directly:

poetry install --all-extras --with dev --with test --with docs

Configure pre-commit to ensure that your code is formatted correctly and passes all checks:

poetry run pre-commit install

License

Griptape is available under the Apache 2.0 License.