Skip to content

Event Listener

Overview

Event Listener Drivers are used to send Griptape Events to external services.

You can instantiate Drivers and pass them to Event Listeners in your Structure:

import os

from griptape.drivers.event_listener.amazon_sqs import AmazonSqsEventListenerDriver
from griptape.events import EventBus, EventListener
from griptape.rules import Rule
from griptape.structures import Agent

EventBus.add_event_listeners(
    [
        EventListener(
            event_listener_driver=AmazonSqsEventListenerDriver(
                queue_url=os.environ["AMAZON_SQS_QUEUE_URL"],
            ),
        ),
    ]
)


agent = Agent(
    rules=[
        Rule(value="You will be provided with a block of text, and your task is to extract a list of keywords from it.")
    ],
)

agent.run(
    """Black-on-black ware is a 20th- and 21st-century pottery tradition developed by the Puebloan Native American ceramic artists in Northern New Mexico.
    Traditional reduction-fired blackware has been made for centuries by pueblo artists.
    Black-on-black ware of the past century is produced with a smooth surface, with the designs applied through selective burnishing or the application of refractory slip.
    Another style involves carving or incising designs and selectively polishing the raised areas.
    For generations several families from Kha'po Owingeh and P'ohwhóge Owingeh pueblos have been making black-on-black ware with the techniques passed down from matriarch potters. Artists from other pueblos have also produced black-on-black ware.
    Several contemporary artists have created works honoring the pottery of their ancestors."""
)
[02/27/25 20:23:24] INFO     PromptTask 97df8b6f1cb445b9b8f846095e3e7c60        
                             Input: Black-on-black ware is a 20th- and          
                             21st-century pottery tradition developed by the    
                             Puebloan Native American ceramic artists in        
                             Northern New Mexico.                               
                                 Traditional reduction-fired blackware has been 
                             made for centuries by pueblo artists.              
                                 Black-on-black ware of the past century is     
                             produced with a smooth surface, with the designs   
                             applied through selective burnishing or the        
                             application of refractory slip.                    
                                 Another style involves carving or incising     
                             designs and selectively polishing the raised areas.
                                 For generations several families from Kha'po   
                             Owingeh and P'ohwhóge Owingeh pueblos have been    
                             making black-on-black ware with the techniques     
                             passed down from matriarch potters. Artists from   
                             other pueblos have also produced black-on-black    
                             ware.                                              
                                 Several contemporary artists have created works
                             honoring the pottery of their ancestors.           
[02/27/25 20:23:25] INFO     PromptTask 97df8b6f1cb445b9b8f846095e3e7c60        
                             Output: - Black-on-black ware                      
                             - 20th- and 21st-century                           
                             - Pottery tradition                                
                             - Puebloan Native American                         
                             - Northern New Mexico                              
                             - Reduction-fired blackware                        
                             - Pueblo artists                                   
                             - Smooth surface                                   
                             - Selective burnishing                             
                             - Refractory slip                                  
                             - Carving                                          
                             - Incising designs                                 
                             - Polishing                                        
                             - Kha'po Owingeh                                   
                             - P'ohwhóge Owingeh                                
                             - Matriarch potters                                
                             - Contemporary artists                             
                             - Ancestral pottery                                

Or use them independently:

from griptape.artifacts import TextArtifact
from griptape.drivers.event_listener.griptape_cloud import GriptapeCloudEventListenerDriver
from griptape.events import FinishStructureRunEvent

# By default, GriptapeCloudEventListenerDriver uses the api key provided
# in the GT_CLOUD_API_KEY environment variable.
event_driver = GriptapeCloudEventListenerDriver()

done_event = FinishStructureRunEvent(
    output_task_input=TextArtifact("Just started!"),
    output_task_output=TextArtifact("All done!"),
)

event_driver.publish_event(done_event)

Event Listener Drivers

Griptape offers the following Event Listener Drivers for forwarding Griptape Events.

Amazon SQS

Info

This driver requires the drivers-event-listener-amazon-sqs extra.

The AmazonSqsEventListenerDriver sends Events to an Amazon SQS queue.

import os

from griptape.drivers.event_listener.amazon_sqs import AmazonSqsEventListenerDriver
from griptape.events import EventBus, EventListener
from griptape.rules import Rule
from griptape.structures import Agent

EventBus.add_event_listeners(
    [
        EventListener(
            event_listener_driver=AmazonSqsEventListenerDriver(
                queue_url=os.environ["AMAZON_SQS_QUEUE_URL"],
            ),
        ),
    ]
)

agent = Agent(
    rules=[
        Rule(value="You will be provided with a block of text, and your task is to extract a list of keywords from it.")
    ],
)

agent.run(
    """Black-on-black ware is a 20th- and 21st-century pottery tradition developed by the Puebloan Native American ceramic artists in Northern New Mexico.
    Traditional reduction-fired blackware has been made for centuries by pueblo artists.
    Black-on-black ware of the past century is produced with a smooth surface, with the designs applied through selective burnishing or the application of refractory slip.
    Another style involves carving or incising designs and selectively polishing the raised areas.
    For generations several families from Kha'po Owingeh and P'ohwhóge Owingeh pueblos have been making black-on-black ware with the techniques passed down from matriarch potters. Artists from other pueblos have also produced black-on-black ware.
    Several contemporary artists have created works honoring the pottery of their ancestors."""
)
[02/27/25 20:22:19] INFO     PromptTask bb4287f85a264ce8afd0977d2fedd31f        
                             Input: Black-on-black ware is a 20th- and          
                             21st-century pottery tradition developed by the    
                             Puebloan Native American ceramic artists in        
                             Northern New Mexico.                               
                                 Traditional reduction-fired blackware has been 
                             made for centuries by pueblo artists.              
                                 Black-on-black ware of the past century is     
                             produced with a smooth surface, with the designs   
                             applied through selective burnishing or the        
                             application of refractory slip.                    
                                 Another style involves carving or incising     
                             designs and selectively polishing the raised areas.
                                 For generations several families from Kha'po   
                             Owingeh and P'ohwhóge Owingeh pueblos have been    
                             making black-on-black ware with the techniques     
                             passed down from matriarch potters. Artists from   
                             other pueblos have also produced black-on-black    
                             ware.                                              
                                 Several contemporary artists have created works
                             honoring the pottery of their ancestors.           
[02/27/25 20:22:20] INFO     PromptTask bb4287f85a264ce8afd0977d2fedd31f        
                             Output: - Black-on-black ware                      
                             - 20th- and 21st-century                           
                             - Pottery tradition                                
                             - Puebloan Native American                         
                             - Northern New Mexico                              
                             - Reduction-fired blackware                        
                             - Pueblo artists                                   
                             - Smooth surface                                   
                             - Selective burnishing                             
                             - Refractory slip                                  
                             - Carving                                          
                             - Incising designs                                 
                             - Polishing                                        
                             - Kha'po Owingeh                                   
                             - P'ohwhóge Owingeh                                
                             - Matriarch potters                                
                             - Contemporary artists                             
                             - Ancestral pottery                                

AWS IoT

Info

This driver requires the drivers-event-listener-amazon-iot extra.

The AwsIotCoreEventListenerDriver sends Events to the AWS IoT Message Broker.

import os

from griptape.configs import Defaults
from griptape.configs.drivers import DriversConfig
from griptape.drivers.event_listener.aws_iot_core import AwsIotCoreEventListenerDriver
from griptape.drivers.prompt.openai import OpenAiChatPromptDriver
from griptape.events import EventBus, EventListener, FinishStructureRunEvent
from griptape.rules import Rule
from griptape.structures import Agent

Defaults.drivers_config = DriversConfig(prompt_driver=OpenAiChatPromptDriver(model="gpt-3.5-turbo", temperature=0.7))
EventBus.add_event_listeners(
    [
        EventListener(
            event_types=[FinishStructureRunEvent],
            event_listener_driver=AwsIotCoreEventListenerDriver(
                topic=os.environ["AWS_IOT_CORE_TOPIC"],
                iot_endpoint=os.environ["AWS_IOT_CORE_ENDPOINT"],
            ),
        ),
    ]
)

agent = Agent(
    rules=[Rule(value="You will be provided with a text, and your task is to extract the airport codes from it.")],
)

agent.run("I want to fly from Orlando to Boston")
[02/27/25 20:24:18] INFO     PromptTask e1f83989cf764ee5bb8bc096fed3cb17        
                             Input: I want to fly from Orlando to Boston        
[02/27/25 20:24:19] INFO     PromptTask e1f83989cf764ee5bb8bc096fed3cb17        
                             Output: The airport codes for Orlando and Boston   
                             are MCO and BOS, respectively.                     

Griptape Cloud

The GriptapeCloudEventListenerDriver sends Events to Griptape Cloud.

Note

This Driver is required when using the Griptape Cloud Managed Structures feature. For local development, you can use the Skatepark Emulator.

from griptape.drivers.event_listener.griptape_cloud import GriptapeCloudEventListenerDriver
from griptape.events import EventBus, EventListener, FinishStructureRunEvent
from griptape.structures import Agent

EventBus.add_event_listeners(
    [
        EventListener(
            event_types=[FinishStructureRunEvent],
            # By default, GriptapeCloudEventListenerDriver uses the api key provided
            # in the GT_CLOUD_API_KEY environment variable.
            event_listener_driver=GriptapeCloudEventListenerDriver(),
        ),
    ]
)

agent = Agent()
agent.run("Create a list of 8 questions for an interview with a science fiction author.")
[02/27/25 20:22:58] INFO     PromptTask f6bb87969b6b4b20be9686fd7e36224d        
                             Input: Create a list of 8 questions for an         
                             interview with a science fiction author.           
[02/27/25 20:23:03] INFO     PromptTask f6bb87969b6b4b20be9686fd7e36224d        
                             Output: Certainly! Here are eight questions you    
                             might consider asking a science fiction author     
                             during an interview:                               

                             1. **Inspiration and Beginnings**: What initially  
                             drew you to the science fiction genre, and how did 
                             you begin your journey as a science fiction writer?

                             2. **World-Building**: How do you approach the     
                             process of world-building in your novels, and what 
                             are some key elements you focus on to make your    
                             worlds believable and engaging?                    

                             3. **Character Development**: Science fiction often
                             involves complex characters in extraordinary       
                             situations. How do you balance character           
                             development with the speculative elements of your  
                             stories?                                           

                             4. **Themes and Messages**: Are there particular   
                             themes or messages you aim to convey through your  
                             work, and how do you integrate them into your      
                             narratives without overshadowing the story?        

                             5. **Research and Technology**: How much research  
                             goes into the scientific and technological aspects 
                             of your books, and how do you ensure accuracy while
                             maintaining creative freedom?                      

                             6. **Influences and Favorites**: Which authors or  
                             works have most influenced your writing, and are   
                             there any science fiction books or films that you  
                             consider personal favorites?                       

                             7. **Challenges and Rewards**: What are some of the
                             biggest challenges you face when writing science   
                             fiction, and what do you find most rewarding about 
                             working in this genre?                             

                             8. **Future of Science Fiction**: How do you see   
                             the science fiction genre evolving in the coming   
                             years, and what role do you think it plays in      
                             shaping our understanding of the future?           

                             These questions are designed to explore the        
                             author's creative process, influences, and         
                             perspectives on the genre.                         

Webhook Event Listener Driver

The WebhookEventListenerDriver sends Events to any Webhook URL.

import os

from griptape.drivers.event_listener.webhook import WebhookEventListenerDriver
from griptape.events import EventBus, EventListener, FinishStructureRunEvent
from griptape.structures import Agent

EventBus.add_event_listeners(
    [
        EventListener(
            event_types=[FinishStructureRunEvent],
            event_listener_driver=WebhookEventListenerDriver(
                webhook_url=os.environ["WEBHOOK_URL"],
            ),
        ),
    ]
)

agent = Agent()

agent.run("Analyze the pros and cons of remote work vs. office work")
[02/27/25 20:24:40] INFO     PromptTask 06d0102f2238475fa4cd2b1e1340896c        
                             Input: Analyze the pros and cons of remote work vs.
                             office work                                        
[02/27/25 20:24:53] INFO     PromptTask 06d0102f2238475fa4cd2b1e1340896c        
                             Output: The debate between remote work and office  
                             work has gained significant attention, especially  
                             in recent years. Each mode of work has its own set 
                             of advantages and disadvantages, which can vary    
                             depending on the industry, company culture, and    
                             individual preferences. Here's a detailed analysis:

                             ### Remote Work                                    

                             #### Pros:                                         
                             1. **Flexibility**: Remote work offers greater     
                             flexibility in terms of work hours and location,   
                             allowing employees to balance personal and         
                             professional responsibilities more effectively.    

                             2. **Reduced Commute**: Eliminating the daily      
                             commute saves time and money, reducing stress and  
                             increasing productivity for many employees.        

                             3. **Broader Talent Pool**: Companies can hire     
                             talent from anywhere in the world, not being       
                             limited to a specific geographic location.         

                             4. **Cost Savings**: Both employees and employers  
                             can save on costs. Employees save on commuting and 
                             work attire, while employers can reduce overhead   
                             costs related to office space and utilities.       

                             5. **Increased Productivity**: Some studies suggest
                             that remote workers can be more productive due to  
                             fewer office distractions and the ability to create
                             a personalized work environment.                   

                             6. **Environmental Impact**: Reduced commuting     
                             leads to lower carbon emissions, contributing      
                             positively to environmental sustainability.        

                             #### Cons:                                         
                             1. **Isolation**: Remote work can lead to feelings 
                             of isolation and loneliness, as employees miss out 
                             on social interactions with colleagues.            

                             2. **Communication Challenges**: Remote work can   
                             hinder communication and collaboration, especially 
                             if not supported by effective digital tools and    
                             practices.                                         

                             3. **Work-Life Balance**: The line between work and
                             personal life can blur, leading to overwork and    
                             burnout if boundaries are not set.                 

                             4. **Distractions at Home**: Home environments can 
                             present their own set of distractions, which can   
                             impact productivity.                               

                             5. **Limited Career Advancement**: Remote workers  
                             may miss out on networking opportunities and face  
                             challenges in career advancement compared to their 
                             in-office counterparts.                            

                             6. **Technology Dependence**: Remote work relies   
                             heavily on technology, which can be a barrier if   
                             there are connectivity issues or if employees lack 
                             the necessary tech skills.                         

                             ### Office Work                                    

                             #### Pros:                                         
                             1. **Collaboration and Communication**: Being      
                             physically present in an office facilitates        
                             spontaneous communication and collaboration, which 
                             can enhance creativity and problem-solving.        

                             2. **Structured Environment**: The office provides 
                             a structured environment that can help some        
                             employees focus and maintain a clear separation    
                             between work and home life.                        

                             3. **Networking Opportunities**: Working in an     
                             office allows for more networking opportunities and
                             relationship-building, which can be beneficial for 
                             career growth.                                     

                             4. **Access to Resources**: Employees have         
                             immediate access to office resources and support,  
                             such as IT assistance and office equipment.        

                             5. **Team Cohesion**: Regular face-to-face         
                             interactions can strengthen team cohesion and      
                             company culture.                                   

                             #### Cons:                                         
                             1. **Commute Stress**: Commuting can be            
                             time-consuming, costly, and stressful, impacting   
                             overall job satisfaction and work-life balance.    

                             2. **Less Flexibility**: Office work typically     
                             offers less flexibility in terms of work hours and 
                             location, which can be challenging for employees   
                             with personal commitments.                         

                             3. **Higher Costs**: Employees incur additional    
                             costs related to commuting, meals, and professional
                             attire.                                            

                             4. **Potential for Distractions**: The office      
                             environment can have its own set of distractions,  
                             such as noise and interruptions from colleagues.   

                             5. **Limited Talent Pool**: Companies are          
                             restricted to hiring talent within a certain       
                             geographic area, potentially missing out on skilled
                             candidates from other regions.                     

                             ### Conclusion                                     

                             The choice between remote work and office work     
                             depends on various factors, including the nature of
                             the job, company policies, and individual          
                             preferences. A hybrid model, combining elements of 
                             both remote and office work, is becoming           
                             increasingly popular as it seeks to balance the    
                             benefits and drawbacks of each approach.           
                             Ultimately, the best work arrangement is one that  
                             aligns with the goals and needs of both the        
                             employer and the employee.                         

Pusher

Info

This driver requires the drivers-event-listener-pusher extra.

The PusherEventListenerDriver sends Events to Pusher.

import os

from griptape.drivers.event_listener.pusher import PusherEventListenerDriver
from griptape.events import EventBus, EventListener, FinishStructureRunEvent
from griptape.structures import Agent

EventBus.add_event_listeners(
    [
        EventListener(
            event_types=[FinishStructureRunEvent],
            event_listener_driver=PusherEventListenerDriver(
                batched=False,
                app_id=os.environ["PUSHER_APP_ID"],
                key=os.environ["PUSHER_KEY"],
                secret=os.environ["PUSHER_SECRET"],
                cluster=os.environ["PUSHER_CLUSTER"],
                channel="my-channel",
                event_name="my-event",
            ),
        ),
    ],
)

agent = Agent()

agent.run("Analyze the pros and cons of remote work vs. office work")
[02/27/25 20:22:31] INFO     PromptTask 29e77fa1332a40b7acda91ca58ba0170        
                             Input: Analyze the pros and cons of remote work vs.
                             office work                                        
[02/27/25 20:22:50] INFO     PromptTask 29e77fa1332a40b7acda91ca58ba0170        
                             Output: The debate between remote work and office  
                             work has gained significant attention, especially  
                             in the wake of the COVID-19 pandemic. Both work    
                             arrangements have their own set of advantages and  
                             disadvantages, which can vary depending on the     
                             industry, company culture, and individual          
                             preferences. Here’s a detailed analysis of the pros
                             and cons of each:                                  

                             ### Remote Work                                    

                             #### Pros:                                         
                             1. **Flexibility**: Remote work offers employees   
                             the flexibility to set their own schedules, which  
                             can lead to a better work-life balance. This is    
                             particularly beneficial for those with family      
                             commitments or personal obligations.               

                             2. **Reduced Commute**: Eliminating the daily      
                             commute saves time and money, reducing stress and  
                             allowing for more personal or productive time.     

                             3. **Increased Productivity**: Many employees      
                             report higher productivity levels when working     
                             remotely due to fewer office distractions and the  
                             ability to create a personalized work environment. 

                             4. **Access to a Wider Talent Pool**: Employers can
                             hire talent from anywhere in the world, not being  
                             limited by geographical location.                  

                             5. **Cost Savings**: Both employees and employers  
                             can save money. Employees save on commuting costs, 
                             while employers can reduce overhead costs related  
                             to office space and utilities.                     

                             #### Cons:                                         
                             1. **Isolation**: Remote work can lead to feelings 
                             of isolation and loneliness, as employees miss out 
                             on social interactions with colleagues.            

                             2. **Communication Challenges**: Virtual           
                             communication can sometimes lead to                
                             misunderstandings or a lack of clarity, and it may 
                             require more effort to maintain team cohesion.     

                             3. **Work-Life Balance Blurring**: Without clear   
                             boundaries, some remote workers may find it        
                             difficult to separate work from personal life,     
                             leading to burnout.                                

                             4. **Technology Dependence**: Remote work relies   
                             heavily on technology, and technical issues can    
                             disrupt productivity.                              

                             5. **Limited Career Advancement**: Some remote     
                             workers may feel they have fewer opportunities for 
                             career advancement due to less visibility and      
                             networking opportunities.                          

                             ### Office Work                                    

                             #### Pros:                                         
                             1. **Collaboration and Teamwork**: Being physically
                             present in an office facilitates spontaneous       
                             collaboration and brainstorming, which can enhance 
                             creativity and problem-solving.                    

                             2. **Structured Environment**: The office provides 
                             a structured environment that can help some        
                             employees focus and maintain a routine.            

                             3. **Networking Opportunities**: Working in an     
                             office allows for more face-to-face interactions,  
                             which can be beneficial for networking and career  
                             advancement.                                       

                             4. **Access to Resources**: Employees have direct  
                             access to office resources and support, such as IT 
                             assistance, office supplies, and meeting spaces.   

                             5. **Clear Work-Life Separation**: The physical    
                             separation between home and work can help employees
                             maintain a clearer distinction between their       
                             professional and personal lives.                   

                             #### Cons:                                         
                             1. **Commute Stress**: Commuting can be            
                             time-consuming, costly, and stressful, impacting   
                             overall job satisfaction and work-life balance.    

                             2. **Less Flexibility**: Office work typically     
                             requires adherence to a fixed schedule, which can  
                             be challenging for those with personal commitments 
                             or preferences for non-traditional work hours.     

                             3. **Higher Costs**: Employees may incur additional
                             costs related to commuting, work attire, and meals.

                             4. **Potential for Distractions**: Office          
                             environments can be noisy and distracting, which   
                             may hinder productivity for some individuals.      

                             5. **Limited Talent Pool**: Employers are          
                             restricted to hiring talent within a certain       
                             geographical area, potentially missing out on      
                             skilled candidates from other regions.             

                             ### Conclusion                                     

                             The choice between remote work and office work     
                             depends on various factors, including the nature of
                             the job, company policies, and individual          
                             preferences. Some organizations are adopting hybrid
                             models to combine the benefits of both             
                             arrangements. Ultimately, the best approach is one 
                             that aligns with the goals and needs of both the   
                             employer and the employees.