AI Agent With Workflows Template
import os
from flask import render_template, request, jsonify
from gunicorn.app.base import BaseApplication
from abilities import llm
from app_init import app, db
from models import ConversationMessage
@app.route("/")
def home_route():
return render_template("home.html")
@app.route("/chat", methods=["POST"])
def chat_route():
from agent import AIAgent
user_input = request.json.get("message", "")
# Create an AI agent to handle the request
agent = AIAgent()
# Process the user input through the agent
agent_response = agent.handle_request(user_input)
Frequently Asked Questions
Enables 24/7 operation without additional staffing costs Companies implementing this template typically see a 30-50% reduction in customer service operational costs within the first year. Q3: What sets this template apart from standard chatbot solutions in terms of business value?
The AI Agent With Workflows Template distinguishes itself through: - Intelligent workflow routing based on conversation context - Persistent memory management for coherent long-term interactions - Dynamic adaptation to different business processes - Integration capabilities with existing business systems - Scalable architecture that grows with business needs - Detailed analytics and conversation tracking
Q4: How can I extend the template to add custom API integrations? Can you provide a code example?
A: The AI Agent With Workflows Template can be extended by creating a new workflow class that implements API integrations. Here's an example:
```python from workflows.base_workflow import BaseWorkflow import requests
class APIIntegrationWorkflow(BaseWorkflow): description = "Workflow for handling external API integrations"
def __init__(self):
super().__init__()
self.api_key = os.getenv('API_KEY')
self.base_url = 'https://api.example.com'
def next_step(self, user_input, think_output=None):
try:
# Make API call
response = requests.get(
f"{self.base_url}/endpoint",
headers={'Authorization': f'Bearer {self.api_key}'},
params={'query': user_input}
)
return {
"response": self._format_api_response(response.json()),
"workflow_step": "api_integration",
"workflow_objective": "External API Integration"
}
except Exception as e:
self.logger.error(f"API Integration error: {e}")
return {"response": "Error processing API request"}
```
Q5: How can I implement custom memory management in the template? Please provide an example.
A: The template's memory management can be customized by extending the ConversationMessage model and implementing custom retrieval methods. Here's an example:
```python from models import db, ConversationMessage
class EnhancedConversationMessage(ConversationMessage): def init(self): super().init() self.metadata = Column(JSON)
@classmethod
def get_contextual_memory(cls, context_type, limit=5):
return cls.query.filter(
cls.metadata['context_type'].astext == context_type
).order_by(
cls.timestamp.desc()
).limit(limit).all()
Usage in workflow
def retrieve_context(self, context_type): relevant_messages = EnhancedConversationMessage.get_contextual_memory( context_type='customer_support' ) return self._process_memory(relevant_messages) ```
This implementation allows for more sophisticated memory management with metadata tagging and contextual retrieval.
Created: | Last Updated:
AI Agent With Workflows Template Guide
This template provides a sophisticated AI agent system with modular workflows, a web-based chat interface, and conversation memory management. The agent can analyze user input, select appropriate workflows, and generate contextual responses.
Getting Started
- Click "Start with this Template" in the Lazy Builder interface to begin working with this template
Testing the Application
- Click the "Test" button in the Lazy Builder interface
- Lazy will deploy the application and provide you with a server link to access the chat interface
Using the Chat Interface
The web interface provides several key features:
- A clean, modern chat interface for interacting with the AI agent
- Real-time message updates
- Thought process visibility for understanding the agent's decision-making
- Chat history management with a clear chat option
To use the interface:
- Navigate to the provided server link
- Type your message in the input field
- Press "Send" or hit Enter to submit
- View the AI's response, including its thought process
- Use the "Clear Chat History" button to reset the conversation
Customizing Workflows
The template supports custom workflow creation for specific use cases. To create a new workflow:
- Create a new file in the workflows directory
- Inherit from BaseWorkflow
- Implement the required methods
Example workflow structure:
```python from workflows.base_workflow import BaseWorkflow
class CustomWorkflow(BaseWorkflow): description = "Description of what this workflow handles"
def __init__(self):
super().__init__()
self.steps = ["step1", "step2", "step3"]
self.current_step = 0
def next_step(self, user_input):
# Implement your workflow logic here
pass
```
The agent will automatically discover and incorporate new workflows into its decision-making process.
Key Features
- Modular workflow system for handling different types of interactions
- Conversation memory with SQLite database storage
- Dynamic workflow selection based on user input analysis
- Thought process transparency
- Clear chat history functionality
- Responsive web interface
The template provides a foundation for building sophisticated conversational AI applications with structured workflow management and a polished user interface.
Template Benefits
- Intelligent Customer Service Automation
- Provides a ready-to-deploy AI customer service solution
- Maintains conversation context and history for personalized responses
- Reduces customer service costs while providing 24/7 availability
-
Handles multiple conversation types through dynamic workflow selection
-
Enterprise Process Automation
- Modular workflow system enables automation of complex business processes
- Easily extendable for specific business use cases and requirements
- Maintains audit trails and conversation logs for compliance
-
Integrates with existing business systems through API capabilities
-
Knowledge Management & Support
- Creates an intelligent knowledge base interface for employees
- Provides consistent and accurate information across the organization
- Reduces training time and support ticket volume
-
Enables self-service support with contextual understanding
-
Sales & Lead Qualification
- Engages potential customers through intelligent conversation flows
- Qualifies leads based on customizable criteria
- Maintains detailed interaction history for sales follow-up
-
Scales sales operations without proportional staff increases
-
Data-Driven Decision Support
- Provides intelligent analysis of user queries and requests
- Maintains conversation history for pattern analysis
- Enables data-backed decision making through structured workflows
- Offers insights into user needs and common request patterns
Technologies




