Config
Overview
The StructureConfig class allows for the customization of Structures within Griptape, enabling specific settings such as Drivers to be defined for Tasks.
Premade Configs
Griptape provides predefined StructureConfig's for widely used services that provide APIs for most Driver types Griptape offers.
OpenAI
The OpenAI Structure Config provides default Drivers for OpenAI's APIs. This is the default config for all Structures.
from griptape.structures import Agent
from griptape.config import OpenAiStructureConfig
agent = Agent(
config=OpenAiStructureConfig()
)
agent = Agent() # This is equivalent to the above
Amazon Bedrock
The Amazon Bedrock Structure Config provides default Drivers for Amazon Bedrock's APIs.
from griptape.structures import Agent
from griptape.config import AmazonBedrockStructureConfig
agent = Agent(
config=AmazonBedrockStructureConfig()
)
The Google Structure Config provides default Drivers for Google's Gemini APIs.
from griptape.structures import Agent
from griptape.config import GoogleStructureConfig
agent = Agent(
config=GoogleStructureConfig()
)
Anthropic
The Anthropic Structure 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 AnthropicStructureConfig
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.structures import Agent
from griptape.config import AnthropicStructureConfig
agent = Agent(
config=AnthropicStructureConfig()
)
Custom Configs
You can create your own StructureConfig by overriding the Drivers in default_config. The StructureConfig class includes "Dummy" Drivers for all types, which throw a DummyException 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.structures import Agent
from griptape.config import StructureConfig, StructureGlobalDriversConfig
from griptape.drivers import AnthropicPromptDriver
agent = Agent(
config=StructureConfig(
global_drivers=StructureGlobalDriversConfig(
prompt_driver=AnthropicPromptDriver(
model="claude-3-sonnet-20240229",
api_key=os.environ["ANTHROPIC_API_KEY"],
)
)
),
)
Task Memory
Griptape allows for detailed control over Task Memory settings, permitting overrides on a per Engine basis, beyond the global Drivers configuration.
from griptape.structures import Agent
from griptape.config import StructureConfig, StructureTaskMemoryConfig, StructureTaskMemoryQueryEngineConfig
from griptape.drivers import LocalVectorStoreDriver, OpenAiEmbeddingDriver
agent = Agent(
config=StructureConfig(
task_memory=StructureTaskMemoryConfig(
query_engine=StructureTaskMemoryQueryEngineConfig(
vector_store_driver=LocalVectorStoreDriver(
embedding_driver=OpenAiEmbeddingDriver(),
)
)
)
)
)
Loading/Saving Configs
Configuration classes in Griptape offer utility methods for loading, saving, and merging configurations, streamlining the management of complex setups.
from griptape.structures import Agent
from griptape.config import AmazonBedrockStructureConfig
from griptape.drivers import AmazonBedrockCohereEmbeddingDriver
custom_config = AmazonBedrockStructureConfig()
custom_config.global_drivers.embedding_driver = AmazonBedrockCohereEmbeddingDriver()
custom_config.merge_config(
{
"task_memory": {
"summary_engine": {
"prompt_driver": {
"model": "amazon.titan-text-express-v1",
"prompt_model_driver": {
"type": "BedrockTitanPromptModelDriver",
},
}
}
}
}
)
serialized_config = custom_config.to_json()
deserialized_config = AmazonBedrockStructureConfig.from_json(serialized_config)
agent = Agent(
config=deserialized_config,
)