Skip to content

Configs

Overview

Griptape exposes a global singleton, Defaults, which can be used to access and modify the default configurations of the framework.

To update the default configurations, simply update the fields on the Defaults object. Framework objects will be created with the currently set default configurations, but you can always override at the individual class level.

from griptape.configs import Defaults
from griptape.configs.drivers import AnthropicDriversConfig, OpenAiDriversConfig
from griptape.drivers.prompt.anthropic_prompt_driver import AnthropicPromptDriver
from griptape.structures import Agent

Defaults.drivers_config = OpenAiDriversConfig()  # Default
openai_agent = Agent()

Defaults.drivers_config = AnthropicDriversConfig()
anthropic_agent = Agent(
    prompt_driver=AnthropicPromptDriver(model="claude-3-5-sonnet-20240620"),  # Override the default prompt driver
)

Drivers Configs

The DriversConfig class allows for the customization of Structures within Griptape, enabling specific settings such as Drivers to be defined for Tasks.

Griptape provides predefined DriversConfig's for widely used services that provide APIs for most Driver types Griptape offers.

DriversConfigs can be used as a Python Context Manager using the with statement to temporarily change the default configurations for a block of code.

import schema

from griptape.configs.drivers import AnthropicDriversConfig, OpenAiDriversConfig
from griptape.drivers import AnthropicPromptDriver, OpenAiChatPromptDriver
from griptape.engines import JsonExtractionEngine
from griptape.structures import Agent
from griptape.tasks import ToolTask
from griptape.tools import ExtractionTool

with OpenAiDriversConfig():  # Agent will be created with OpenAi Drivers
    openai_agent = Agent()

with AnthropicDriversConfig():  # Agent will be created with Anthropic Drivers
    anthropic_agent = Agent(
        tasks=[
            ToolTask(
                "Extract sentiment from this text: {{ args[0] }}",
                prompt_driver=OpenAiChatPromptDriver(model="gpt-4o"),  # Override this particular Task's prompt driver
                tool=ExtractionTool(
                    extraction_engine=JsonExtractionEngine(
                        prompt_driver=AnthropicPromptDriver(  # Override this particular Engine's prompt driver
                            model="claude-3-opus-20240229"
                        ),
                        template_schema=schema.Schema({"sentiment": str}).json_schema("Output"),
                    ),
                ),
            )
        ]
    )

anthropic_agent.run("Hello, I am happy!")

OpenAI

The OpenAI Driver config provides default Drivers for OpenAI's APIs. This is the default config for all Structures.

from griptape.configs import Defaults
from griptape.configs.drivers import OpenAiDriversConfig
from griptape.structures import Agent

Defaults.drivers_config = OpenAiDriversConfig()

agent = Agent()

Azure OpenAI

The Azure OpenAI Driver config provides default Drivers for Azure's OpenAI APIs.

import os

from griptape.configs import Defaults
from griptape.configs.drivers import AzureOpenAiDriversConfig
from griptape.structures import Agent

Defaults.drivers_config = AzureOpenAiDriversConfig(
    azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT_3"], api_key=os.environ["AZURE_OPENAI_API_KEY_3"]
)

agent = Agent()

Amazon Bedrock

The Amazon Bedrock Driver config provides default Drivers for Amazon Bedrock's APIs.

import os

import boto3

from griptape.configs import Defaults
from griptape.configs.drivers import AmazonBedrockDriversConfig
from griptape.structures import Agent

Defaults.drivers_config = AmazonBedrockDriversConfig(
    session=boto3.Session(
        region_name=os.environ["AWS_DEFAULT_REGION"],
        aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"],
        aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"],
    )
)

agent = Agent()

Google

The Google Driver config provides default Drivers for Google's Gemini APIs.

from griptape.configs import Defaults
from griptape.configs.drivers import GoogleDriversConfig
from griptape.structures import Agent

Defaults.drivers_config = GoogleDriversConfig()

agent = Agent()

Anthropic

The Anthropic Driver config provides default Drivers for Anthropic's APIs.

Info

Anthropic does not provide an embeddings API which means you will need to use another service for embeddings. The AnthropicDriversConfig defaults to using VoyageAiEmbeddingDriver which integrates with VoyageAI, the service used in Anthropic's embeddings documentation. To override the default embedding driver, see: Override Default Structure Embedding Driver.

from griptape.configs import Defaults
from griptape.configs.drivers import AnthropicDriversConfig
from griptape.structures import Agent

Defaults.drivers_config = AnthropicDriversConfig()

agent = Agent()

Cohere

The Cohere Driver config provides default Drivers for Cohere's APIs.

import os

from griptape.configs import Defaults
from griptape.configs.drivers import CohereDriversConfig
from griptape.structures import Agent

Defaults.drivers_config = CohereDriversConfig(api_key=os.environ["COHERE_API_KEY"])

agent = Agent()

Custom

You can create your own DriversConfig by overriding relevant Drivers. The DriversConfig class includes "Dummy" Drivers for all types, which throw a DummyError if invoked without being overridden. This approach ensures that you are informed through clear error messages if you attempt to use Structures without proper Driver configurations.

import os

from griptape.configs import Defaults
from griptape.configs.drivers import DriversConfig
from griptape.drivers import AnthropicPromptDriver, OpenAiEmbeddingDriver
from griptape.structures import Agent

Defaults.drivers_config = DriversConfig(
    prompt_driver=AnthropicPromptDriver(
        model="claude-3-sonnet-20240229",
        api_key=os.environ["ANTHROPIC_API_KEY"],
    ),
    embedding_driver=OpenAiEmbeddingDriver(),
)


agent = Agent()

Logging Config

Griptape provides a predefined LoggingConfig's for easily customizing the logging events that the framework emits. In order to customize the logger, the logger can be fetched by using the Defaults.logging.logger_name.

import logging

from griptape.configs import Defaults
from griptape.configs.drivers import OpenAiDriversConfig
from griptape.configs.logging import TruncateLoggingFilter
from griptape.structures import Agent

Defaults.drivers_config = OpenAiDriversConfig()

logger = logging.getLogger(Defaults.logging_config.logger_name)
logger.setLevel(logging.ERROR)
logger.addFilter(TruncateLoggingFilter(max_log_length=100))

agent = Agent()

Loading/Saving Configs

from griptape.configs import Defaults
from griptape.configs.drivers import AmazonBedrockDriversConfig
from griptape.structures import Agent

custom_config = AmazonBedrockDriversConfig()
dict_config = custom_config.to_dict()
# Use OpenAi for embeddings
dict_config["embedding_driver"] = {
    "base_url": None,
    "model": "text-embedding-3-small",
    "organization": None,
    "type": "OpenAiEmbeddingDriver",
}
custom_config = AmazonBedrockDriversConfig.from_dict(dict_config)

Defaults.drivers_config = custom_config

agent = Agent()